-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwatch_dog.py
399 lines (359 loc) · 19.9 KB
/
watch_dog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
import requests, pymongo, re, config
import argparse
import sys
from time import sleep
from discord_webhook import DiscordWebhook, DiscordEmbed
platforms = ['hackerone', 'bugcrowd', 'intigriti', 'yeswehack']
PATTERN = r"(?:(?:https?|ftp):\/\/)?(?:[\w-]+\.)+[a-z]{2,}(?::\d+)?(?:\/\S*)?"
PATH = "https://raw.githubusercontent.com/Osb0rn3/bugbounty-targets/main/programs/"
def get_data(url:str):
return requests.get(url).json()
def is_exist(collection: str, db) -> bool:
if collection in db.list_collection_names():
return True
return False
def insert_db(database, data:dict, collection_name:str, mongo_uri:str):
# Connect to MongoDB client
client = pymongo.MongoClient(mongo_uri)
# Select database and collection
# if platform in db.list_collection_names():
# print("Already exists!")
# return
db = client[database]
if is_exist(collection_name, db):
# print(f"{collection_name} already exists!")
return
collection = db[collection_name]
# Insert data into collection
try:
collection.insert_many(data)
print("Successfully added to DB.")
return True
except Exception as e:
print(e)
def check_changes(mongo_uri, database, platform:str, notification:str, token:str, telegram_chatid = None):
try:
# Connect to MongoDB client
client = pymongo.MongoClient(mongo_uri)
# Select database and collection
db = client[database]
if platform == 'hackerone':
collection = db["hackerone"]
# get new data
new_results = cleaner(get_data(PATH + "hackerone.json"), platform)
for program in new_results:
old_data = collection.find_one({"handle": program["handle"]})
if old_data == None:
in_scopes = "\n".join(program["in_scope"])
push(program["logo"], program["name"], program["program_url"], platform, in_scopes, program["offers_bounties"], "New Program", notification, token, telegram_chatid)
collection.insert_one(program)
continue
for in_scope in program["in_scope"]:
if in_scope not in old_data["in_scope"]:
collection.update_one({"handle": program["handle"]}, {"$push": {"in_scope": in_scope}})
push(program["logo"], program["name"], program["program_url"], platform, in_scope, program["offers_bounties"], "New Scope", notification, token, telegram_chatid)
print(f"new scope found! {in_scope}")
if not config.no_out_scope:
for out_of_scope in program["out_of_scope"]:
if out_of_scope not in old_data["out_of_scope"]:
print(f"new out of scope found! out_of_scope")
push(program["logo"], program["name"], program["program_url"], platform, out_of_scope, program["offers_bounties"], "Out of Scope", notification, token, telegram_chatid)
collection.update_one({"handle": program["handle"]}, {"$push": {"out_of_scope": out_of_scope}})
elif platform == 'bugcrowd':
collection = db["bugcrowd"]
# get new data
new_results = cleaner(get_data(PATH + "bugcrowd.json"), platform)
for program in new_results:
old_data = collection.find_one({"code": program["code"]})
if old_data == None:
in_scopes = "\n".join(program["in_scope"])
push(program["logo"], program["name"], program["program_url"], platform, in_scopes, program["offers_bounties"], "New Program", notification, token, telegram_chatid)
# New program
collection.insert_one(program)
continue
for in_scope in program["in_scope"]:
#print(in_scope)
if in_scope not in old_data["in_scope"]:
collection.update_one({"code": program["code"]}, {"$push": {"in_scope": in_scope}})
push(program["logo"], program["name"], program["program_url"], platform, in_scope, program["offers_bounties"], "New Scope", notification, token, telegram_chatid)
print(f"new scope found! {in_scope}")
if not config.no_out_scope:
for out_of_scope in program["out_of_scope"]:
if out_of_scope not in old_data["out_of_scope"]:
push(program["logo"], program["name"], program["program_url"], platform, out_of_scope, program["offers_bounties"], "Out of Scope", notification, token, telegram_chatid)
collection.update_one({"code": program["code"]}, {"$push": {"out_of_scope": out_of_scope}})
elif platform == 'intigriti':
collection = db["intigriti"]
# get new data
new_results = cleaner(get_data(PATH + "intigriti.json"), platform)
for program in new_results:
old_data = collection.find_one({"handle": program["handle"]})
if old_data == None:
in_scopes = "\n".join(program["in_scope"])
push(program["logo"], program["name"], program["program_url"], platform, in_scopes, program["offers_bounties"], "New Program", notification, token, telegram_chatid)
collection.insert_one(program)
continue
for in_scope in program["in_scope"]:
#print(in_scope)
if in_scope not in old_data["in_scope"]:
collection.update_one({"handle": program["handle"]}, {"$push": {"in_scope": in_scope}})
push(program["logo"], program["name"], program["program_url"], platform, in_scope, program["offers_bounties"], "New Scope", notification, token, telegram_chatid)
if not config.no_out_scope:
for out_of_scope in program["out_of_scope"]:
if out_of_scope not in old_data["out_of_scope"]:
push(program["logo"], program["name"], program["program_url"], platform, out_of_scope, program["offers_bounties"], "Out of Scope", notification, token, telegram_chatid)
collection.update_one({"handle": program["handle"]}, {"$push": {"out_of_scope": out_of_scope}})
elif platform == 'yeswehack':
collection = db["yeswehack"]
# get new data
new_results = cleaner(get_data(PATH + "yeswehack.json"), platform)
for program in new_results:
old_data = collection.find_one({"slug": program["slug"]})
if old_data == None:
in_scopes = "\n".join(program["in_scope"])
push(program["logo"], program["title"], program["program_url"], platform, in_scopes, program["offers_bounties"], "New Program", notification, token, telegram_chatid)
collection.insert_one(program)
continue
for in_scope in program["in_scope"]:
if in_scope not in old_data["in_scope"]:
collection.update_one({"slug": program["slug"]}, {"$push": {"in_scope": in_scope}})
push(program["logo"], program["title"], program["program_url"], platform, in_scope, program["offers_bounties"], "New Scope", notification, token, telegram_chatid)
else:
pass
except:
print("An error has occurred.")
def cleaner(data:dict, platform:str):
try:
if platform == 'hackerone':
programs = []
for program in data:
program_name = program["attributes"]["name"]
program_handle = program["attributes"]["handle"]
program_scopes = program["relationships"]["structured_scopes"]["data"]
offers_bounties = program["attributes"]["offers_bounties"]
if len(program_scopes) == 0:
continue
programs_dict = {"name":program_name,
"handle": program_handle,
"offers_bounties": offers_bounties,
"program_url": "https://hackerone.com/" + program_handle,
"logo": program["attributes"]["profile_picture"],
"in_scope": [],
"out_of_scope": []}
for x in program_scopes:
if x["attributes"]["eligible_for_submission"]:
if x["attributes"]["asset_identifier"] != None:
programs_dict["in_scope"].append(x["attributes"]["asset_identifier"])
else:
pass
else:
if not config.no_out_scope:
if x["attributes"]["asset_identifier"] != None:
programs_dict["out_of_scope"].append(x["attributes"]["asset_identifier"])
else:
pass
else:
pass
programs.append(programs_dict)
return programs
elif platform == 'bugcrowd':
programs = []
for program in data:
program_name = program["name"]
program_code = program["code"]
program_scopes = program["target_groups"]
offers_bounties = True if program["license_key"] == "bug_bounty" else False
program["license_key"]
if len(program_scopes) == 0:
continue
programs_dict = {"name":program_name,
"offers_bounties": offers_bounties,
"code": program_code,
"program_url": "https://bugcrowd.com/" + program_code,
"logo": program["logo"],
"in_scope": [],
"out_of_scope": []}
for x in program_scopes:
if x["in_scope"] == True:
for y in x["targets"]:
if y["uri"] != None:
programs_dict["in_scope"].append(y["uri"])
elif y["name"] != None:
programs_dict["in_scope"].append(y["name"])
else:
pass
else:
if not config.no_out_scope:
for y in x["targets"]:
if y["name"] != None:
programs_dict["out_of_scope"].append(y["name"])
elif y["uri"] != None:
programs_dict["out_of_scope"].append(y["uri"])
else:
pass
else:
pass
programs.append(programs_dict)
return programs
elif platform == 'intigriti':
programs = []
for program in data:
program_name = program["name"]
program_company_handle = program["companyHandle"]
program_handle = program["handle"]
program_scopes = program["domains"]
if len(program_scopes) == 0:
continue
offers_bounties = True if program["maxBounty"]["value"] > 0 else False
programs_dict = {"name":program_name,
"offers_bounties": offers_bounties,
"companyHandle": program_company_handle,
"handle": program_handle,
"program_url": "https://app.intigriti.com/programs/" + program_company_handle + "/" + program_handle,
"logo": "https://bff-public.intigriti.com/file/" + program["logoId"],
"in_scope": [],
"out_of_scope": []}
for x in program_scopes:
if x["description"] and 'Out of scope' in x["description"] and not config.no_out_scope:
# out of scope!
domains = re.findall(PATTERN, x["description"])
for domain in domains:
if domain != None:
programs_dict["out_of_scope"].append(domain)
else:
pass
else:
# in_scope!
if x["endpoint"] != None:
programs_dict["in_scope"].append(x["endpoint"])
else:
pass
programs.append(programs_dict)
return programs
elif platform == 'yeswehack':
programs = []
for program in data:
program_title = program["title"]
program_slug = program["slug"]
program_scopes = program["scopes"]
if len(program_scopes) == 0:
continue
offers_bounties = True if program["bounty"] else False
programs_dict = {"title":program_title,
"offers_bounties": offers_bounties,
"slug": program_slug,
"program_url": "https://yeswehack.com/programs/" + program_slug,
"logo": program["thumbnail"]["url"],
"in_scope": [],
"out_of_scope": []}
for x in program_scopes:
if x["scope_type"] == "web-application":
if x["scope"] != None:
programs_dict["in_scope"].append(x["scope"])
else:
pass
else:
if not config.no_out_scope:
pass
# programs_dict["out_of_scope"].append(x["targets"]["name"])
else:
pass
programs.append(programs_dict)
return programs
else:
return
except:
print("An error has occurred !!!")
def push(logo_url, program_name, program_url, platform, message:str, bounty:bool, message_type:str, notification: str, token:str, telegram_chatid = None):
if notification == "discord":
try:
webhook = DiscordWebhook(url=token)
if platform == 'hackerone':
embed = DiscordEmbed(title=message_type, description=message, color="ffffff")
embed.set_thumbnail(url=logo_url)
embed.add_embed_field(name="Platform:", value="Hackerone", inline=False)
elif platform == 'bugcrowd':
embed = DiscordEmbed(title=message_type, description=message, color="ff6900")
embed.set_thumbnail(url=logo_url)
embed.add_embed_field(name="Platform:", value="Bugcrowd", inline=False)
elif platform == 'intigriti':
embed = DiscordEmbed(title=message_type, description=message, color="4c59a8")
embed.set_thumbnail(url=logo_url)
embed.add_embed_field(name="Platform:", value="Intigriti", inline=False)
elif platform == 'yeswehack':
embed = DiscordEmbed(title=message_type, description=message, color="8f0e0e")
embed.set_thumbnail(url=logo_url)
embed.add_embed_field(name="Platform:", value="YesWeHack", inline=False)
else:
pass
embed.add_embed_field(name="Program:", value=program_name, inline=False)
embed.add_embed_field(name="Bounty:", value=bounty, inline=False)
embed.add_embed_field(name="URL:", value=program_url, inline=False)
webhook.add_embed(embed)
response = webhook.execute()
except:
print("Check your webhook")
elif notification == "telegram":
apiURL = f'https://api.telegram.org/bot{token}/sendMessage'
msg = """
{}
{}
Platform: {}
Program: {}
Bounty: {}
URL: {}
""".format(message_type, message, platform, program_name, bounty, program_url)
try:
response = requests.post(apiURL, json={'chat_id': telegram_chatid, 'text': msg})
except Exception as e:
print(e)
else:
print("[!] Unknown value for notification.")
def main():
# Command-line arguments
parser = argparse.ArgumentParser(description="A watcher script to watch for new changes in bugbounty platforms.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-p", "--platforms", type=lambda arg: arg.replace(' ', '').split(','), default="all" ,help="Platforms to watch for (comma separated), 'all' for all platforms.")
parser.add_argument("-t", "--telegram", action="store_true",help="Send notifications to Telegram.")
parser.add_argument("-cid", help="Chat id of the telegram channel to send notifications to.")
parser.add_argument("-d", "--discord", action="store_true", help="Send notifications to Discord.")
parser.add_argument("--token", help="Telegram bot token OR Discord webhook.")
parser.add_argument("--database", default=config.database,help="Database name.")
parser.add_argument("--mongo", default="mongodb://mongo:27017/", help="MongoDB URI to connect.")
args = parser.parse_args()
arg_config = vars(args)
# check if there is no command-line argument
if len(sys.argv) > 1: #there is cmdline argumetns
# Remove any databases in first run
if len(arg_config["platforms"]) == 1 and arg_config["platforms"][0] == "all":
input_platforms = platforms
else:
input_platforms = arg_config["platforms"]
for platform in input_platforms:
URL = PATH + platform + ".json"
result = get_data(URL)
clean_result = cleaner(result, platform)
insert_db(arg_config["database"], clean_result, platform, arg_config["mongo"])
for platform in input_platforms:
if arg_config["telegram"]:
check_changes(arg_config["mongo"], arg_config["database"], platform, "telegram", arg_config["token"], arg_config["cid"])
else:
check_changes(arg_config["mongo"], arg_config["database"], platform, "discord", arg_config["token"])
else: # there is no commandline arguments so we sould get our configs from config file
mongo_uri = "mongodb://"+config.mongoHost+":"+config.mongoPort+"/"
if config.program == "all":
input_platforms = platforms
else:
input_platforms = config.program.replace(' ', '').split(",")
for platform in input_platforms:
URL = PATH + platform + ".json"
result = get_data(URL)
clean_result = cleaner(result, platform)
insert_db(config.database, clean_result, platform, mongo_uri)
for platform in input_platforms:
if config.telegram:
check_changes(mongo_uri, config.database, platform, "telegram", config.telegram_token, config.telegram_chatid)
else:
check_changes(mongo_uri, config.database, platform, "discord", config.discord_webhook)
if __name__ == "__main__":
main()