Skip to content

Commit 282aeb9

Browse files
author
Robert Nikolai Reith
committed
test
1 parent 3172ff4 commit 282aeb9

File tree

7 files changed

+105
-31
lines changed

7 files changed

+105
-31
lines changed

.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ __pycache__/
1111
build/
1212
develop-eggs/
1313
dist/
14-
downloads/
14+
downloads/*
1515
eggs/
1616
.eggs/
1717
lib/
@@ -127,3 +127,8 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
132+
# jsmon
133+
downloads/*
134+
targets/*

README.md

+41-18
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,51 @@
1-
# jsmon
2-
JavaScript Change Monitor for BugBounty
1+
# JSMon
2+
JSMon - JavaScript Change Monitor for BugBounty
33

4-
## Installation
4+
Using this script, you can configure a number of JavaScript files on websites that you want to monitor. Everytime you run this script, these files will be fetched and compared to the previously fetched version. If they have changed, you will be notified via Telegram with a message containing a link to the script, the changed filesizes, and a diff file to inspect the changes easily.
55

6-
`git clone https://github.com/robre/jsmon.git & cd jsmon & TODO`
6+
## Installation
77

8+
To install JSMon:
9+
```bash
10+
git clone https://github.com/robre/jsmon.git
11+
cd jsmon
12+
python setup.py install
13+
```
14+
15+
To create a cron script to run JSMon regularly:
16+
```
17+
crontab -e
18+
```
19+
20+
create an entry like this:
21+
```
22+
@daily python /path/to/jsmon.py
23+
```
24+
This will run JSMon once a day, at midnight.
25+
You can change ``@daily`` to whatever schedule suits you.
26+
27+
To configure Telegram notifications, you need to add your Telegram API key and chat_id to the code, at the start of `jsmon.py`. You can read how to get these values [here](https://blog.r0b.re/automation/bash/2020/06/30/setup-telegram-notifications-for-your-shell.html).
28+
29+
Lastly, you need to get started with some targets that you want to monitor. Lets create an example:
30+
```
31+
echo "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js" >> targets/cdnjs-example
32+
```
33+
All done ! now you can run `python jsmon.py` to download the specified files for the first time!
834

935
## Features
1036

11-
- Keep Track of endpoints - check them in a configurable interval
12-
- when endpoints change - send a notification via slack/telegram/mail?
13-
14-
15-
16-
## Structure
17-
18-
- Provide Endpoints via files in $ENDPOINTS directory (line seperated endpoints)
19-
- Per Endpoint
20-
- Download Endpoints and save whole or hash? (save as its own hash.js)
21-
- Everyday request huge number of js files..
22-
- have a file that tracks hash - endpoint relations. Simple JSON
37+
- Keep Track of endpoints - check them in a configurable interval (using cron)
38+
- when endpoints change - send a notification via telegram
2339

2440

2541
## Usage
2642

27-
jsmon is designed to keep track of javascript files on websites - but it can be used for any filetype
28-
To add endpoints
43+
- Provide Endpoints via files in `targets/` directory (line seperated endpoints)
44+
- any number of files, with one endpoint per line
45+
- e.g. one file per website, or one file per program, etc.
46+
- Every endpoint gets downloaded and stored in downloads/ with its hash as file name (first 10 chars of md5 hash)
47+
- if it already exists nothing changes
48+
- if it is changed, user gets notified
49+
- jsmon.json keeps track of which endpoints are associated with which filehashes
50+
51+
- jsmon is designed to keep track of javascript files on websites - but it can be used for any filetype to add endpoints

jsmon.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"https://www.heise.de/assets/akwa/v19/js/akwa.js?aeb8be20b00473bc2941": ["fb6fd508d8"], "https://www.heise.de/assets/heise/hohomepage/js/hohomepage.js?92b41930cad76c61c7bc": ["1baa84caf7"], "http://r0b.re/test.js": ["d8e8fca2dc", "71f74d0894", "8a4641220d", "380b224dba"]}
1+
{}

jsmon.py

100644100755
+42-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
import os
66
import hashlib
77
import json
8+
import difflib
9+
import jsbeautifier
10+
11+
TELEGRAM_TOKEN = 'CHANGEME'
12+
TELEGRAM_CHAT_ID = 'CHANGEME'
813

9-
gEndpoints = {} # global Endpoint List
1014

1115
def is_valid_endpoint(endpoint):
1216
regex = re.compile(
@@ -73,25 +77,54 @@ def get_previous_endpoint_hash(endpoint):
7377
def get_file_stats(fhash):
7478
return os.stat("downloads/{}".format(fhash))
7579

80+
def get_diff(old,new):
81+
opt = {
82+
"indent_with_tabs": 1,
83+
"keep_function_indentation": 0,
84+
}
85+
oldlines = open("downloads/{}".format(old), "r").readlines()
86+
newlines = open("downloads/{}".format(new), "r").readlines()
87+
oldbeautified = jsbeautifier.beautify("".join(oldlines), opt).splitlines()
88+
newbeautified = jsbeautifier.beautify("".join(newlines), opt).splitlines()
89+
# print(oldbeautified)
90+
# print(newbeautified)
91+
92+
differ = difflib.HtmlDiff()
93+
html = differ.make_file(oldbeautified,newbeautified)
94+
#open("test.html", "w").write(html)
95+
return html
96+
7697
def notify(endpoint,prev, new):
98+
diff = get_diff(prev,new)
7799
print("[!!!] Endpoint [ {} ] has changed from {} to {}".format(endpoint, prev, new))
78-
TELEGRAM_TOKEN = '1216105549:AAHEfqRMGjenWQsFTp5ZXaE3ap-BK8BUBBE'
79-
TELEGRAM_CHAT_ID = '115041299'
80100

81101
prevsize = get_file_stats(prev).st_size
82102
newsize = get_file_stats(new).st_size
83-
log_entry = "{} has been updated from {}({}) to {}({})".format(endpoint, prev,prevsize, new,newsize)
103+
log_entry = "{} has been updated from <code>{}</code>(<b>{}</b>Bytes) to <code>{}</code>(<b>{}</b>Bytes)".format(endpoint, prev,prevsize, new,newsize)
84104
payload = {
85105
'chat_id': TELEGRAM_CHAT_ID,
86-
'text': log_entry,
106+
'caption': log_entry,
87107
'parse_mode': 'HTML'
88108
}
89-
return requests.post("https://api.telegram.org/bot{token}/sendMessage".format(token=TELEGRAM_TOKEN),
90-
data=payload).content
109+
fpayload = {
110+
'document': ('diff.html', diff)
111+
}
112+
113+
sendfile = requests.post("https://api.telegram.org/bot{token}/sendDocument".format(token=TELEGRAM_TOKEN),
114+
files=fpayload, data=payload)
115+
#print(sendfile.content)
116+
return sendfile
117+
#test2 = requests.post("https://api.telegram.org/bot{token}/sendMessage".format(token=TELEGRAM_TOKEN),
118+
# data=payload).content
119+
91120

92121
def main():
122+
print("JSMon - Web File Monitor")
123+
if TELEGRAM_TOKEN == "CHANGEME" or TELEGRAM_CHAT_ID == "CHANGEME":
124+
print("Please Set Up your Telegram Token And Chat ID!!!")
125+
93126
allendpoints = get_endpoint_list('targets')
94-
print(allendpoints)
127+
# print(allendpoints)
95128

96129
for ep in allendpoints:
97130
prev_hash = get_previous_endpoint_hash(ep)
@@ -108,3 +141,4 @@ def main():
108141

109142

110143
main()
144+

setup.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python
2+
from setuptools import setup, find_packages
3+
4+
setup(
5+
name='JSMon',
6+
packages=find_packages(),
7+
version='1.0',
8+
description="A python script that monitors JavaScript files.",
9+
long_description=open('README.md').read(),
10+
author='r0bre',
11+
author_email='[email protected]',
12+
license='MIT',
13+
url='https://github.com/robre/jsmon',
14+
install_requires=['requests', 'jsbeautifier'],
15+
)

targets/heise

-2
This file was deleted.

targets/r0bre

-1
This file was deleted.

0 commit comments

Comments
 (0)