/
main.py
429 lines (418 loc) · 17.8 KB
/
main.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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
#pip libs
from tqdm import tqdm
import requests
from art import *
#standard libs
import string
import random
import socket
import time
import os
import re
import subprocess
import platform
#funcs
def clear_screen():
os.system(['clear','cls'][os.name == 'nt'])
def check_ip(ip):
pattern = r"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
return bool(re.match(pattern, ip))
def check_url(url):
pattern = r'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)'
return bool(re.match(pattern, url))
def known_IP():
urls = [
'http://opendbl.net/lists/etknown.list',
'http://opendbl.net/lists/talos.list',
'https://mirai.security.gives/data/ip_list.txt'
]
saved_files = []
for url in tqdm(urls, desc="Downloading Samples"):
response = requests.get(url)
if response.status_code == 200:
file_name = url.split("/")[-1]
with open(file_name, "w") as f:
f.write(response.text)
saved_files.append(file_name)
sampleIP = []
for file in saved_files:
with open(file, 'r') as f:
lines = f.readlines()
for _ in range(5):
randomIP = random.choice(lines)
if check_ip(randomIP):
sampleIP.append(randomIP)
sampleIP = [x.strip() for x in sampleIP]
ports = [80, 22, 443]
myFile = open("IP_Results.txt", mode="a+")
for ip in tqdm(sampleIP, desc="Testing 15 samples from Cisco Talos, EmergingThreats and Mirai, results saved to IP_Results.txt"):
for port in ports:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
result = sock.connect_ex((ip, port))
if result == 0:
current_time = time.strftime("%X")
resultUP = (
f"Timestamp:{str(current_time)} IP:{str(ip)} : Port:{str(port)}"
+ " test SUCCESSFUL\n"
)
myFile.write(resultUP)
else:
current_time = time.strftime("%X")
resultDOWN = (
f"Timestamp:{str(current_time)} IP:{str(ip)} : Port:{str(port)}"
+ " test FAILED\n"
)
myFile.write(resultDOWN)
sock.close()
except Exception as e:
current_time = time.strftime("%X")
resultDOWN = (
f"Timestamp:{str(current_time)} IP:{str(ip)} : Port:{str(port)}"
+ " test FAILED\n"
)
myFile.write(resultDOWN)
continue
for file_name in saved_files:
os.remove(file_name)
aprint("random")
clear_screen()
def known_phish():
urls = 'https://openphish.com/feed.txt'
saved_files = []
print("Downloading Samples")
response = requests.get(urls)
if response.status_code == 200:
file_name = urls.split("/")[-1]
with open(file_name, "w") as f:
f.write(response.text)
saved_files.append(file_name)
sampleURL = []
for file in saved_files:
with open(file, 'r') as f:
lines = f.readlines()
for _ in range(15):
randomURL = random.choice(lines)
if check_url(randomURL):
sampleURL.append(randomURL)
sampleURL = [x.strip() for x in sampleURL]
myFile = open("URL_Results.txt", mode="a+")
for url in tqdm(sampleURL, desc="Testing 15 samples from OpenPhish results saved to URL_Results.txt"):
try:
response = requests.get(url, timeout=5)
if response.status_code == 200:
current_time = time.strftime("%X")
resultUP = (
f"Timestamp:{str(current_time)} URL:{str(url)}"
+ " test SUCCESSFUL\n"
)
myFile.write(resultUP)
else:
current_time = time.strftime("%X")
resultDOWN = f"Timestamp:{str(current_time)} URL:{str(url)}" + " test FAILED\n"
myFile.write(resultDOWN)
except Exception as e:
continue
for file_name in saved_files:
os.remove(file_name)
aprint("random")
clear_screen()
def known_TOR():
urls = 'https://raw.githubusercontent.com/SecOps-Institute/Tor-IP-Addresses/master/tor-exit-nodes.lst'
saved_files = []
print("Downloading Samples")
response = requests.get(urls)
if response.status_code == 200:
file_name = urls.split("/")[-1]
with open(file_name, "w") as f:
f.write(response.text)
saved_files.append(file_name)
sampleTOR = []
for file in saved_files:
with open(file, 'r') as f:
lines = f.readlines()
for _ in range(15):
randomIP = random.choice(lines)
if check_ip(randomIP):
sampleTOR.append(randomIP)
sampleTOR = [x.strip() for x in sampleTOR]
ports = [80, 443]
myFile = open("TOR_Results.txt", mode="a+")
for ip in tqdm(sampleTOR, desc="Testing 15 TOR Exits Nodes, results saved to TOR_Results.txt"):
for port in ports:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
result = sock.connect_ex((ip, port))
if result == 0:
current_time = time.strftime("%X")
resultUP = (
f"Timestamp:{str(current_time)} IP:{str(ip)} : Port:{str(port)}"
+ " test SUCCESSFUL\n"
)
myFile.write(resultUP)
else:
current_time = time.strftime("%X")
resultDOWN = (
f"Timestamp:{str(current_time)} IP:{str(ip)} : Port:{str(port)}"
+ " test FAILED\n"
)
myFile.write(resultDOWN)
sock.close()
except Exception as e:
current_time = time.strftime("%X")
resultDOWN = (
f"Timestamp:{str(current_time)} IP:{str(ip)} : Port:{str(port)}"
+ " test FAILED\n"
)
myFile.write(resultDOWN)
continue
for file_name in saved_files:
os.remove(file_name)
aprint("random")
clear_screen()
def known_dist():
print('Testing LIVE malware distribution URL, THANKS TO ABUSE.CH!!!')
urlsIndex = []
randomUrlsIndex = []
baseURL = "https://urlhaus-api.abuse.ch/v1/urls/recent/limit/200/"
response = requests.get(baseURL)
json_response = response.json()
counter = 0
for _ in tqdm(json_response["urls"], desc="Getting samples list"):
status = json_response["urls"][counter]["url_status"]
if status == "online":
liveURL = json_response["urls"][counter]["url"]
urlsIndex.append(liveURL)
counter = counter + 1
for _ in range(20):
randomSample = random.choice(urlsIndex)
randomUrlsIndex.append(randomSample)
myFile = open("Malware_Results.txt", mode="a+")
for x in tqdm(randomUrlsIndex, desc="Testing samples, Results saved at Malware_Results.txt"):
try:
downloader = requests.get(x, timeout=5)
if downloader.status_code == 200:
current_time = time.strftime("%X")
result = f"Timestamp:{str(current_time)} URL:{str(x)}" + " test SUCCESFULL\n"
else:
current_time = time.strftime("%X")
result = f"Timestamp:{str(current_time)} URL:{str(x)}" + " test FAILED\n"
myFile.write(result)
except Exception as e:
current_time = time.strftime("%X")
result = f"Timestamp:{str(current_time)} URL:{str(x)}" + " test FAILED\n"
myFile.write(result)
continue
aprint("random")
clear_screen()
def known_crypto():
urls = 'https://gist.githubusercontent.com/asluppiter/88aa3cb285948e4f982dd94218e5baf3/raw/bffe8bb462eb8b3fb6cd647be65d67de059cb789/mining'
saved_files = []
print("Downloading Samples")
response = requests.get(urls)
if response.status_code == 200:
file_name = urls.split("/")[-1]
with open(file_name, "w") as f:
f.write(response.text)
saved_files.append(file_name)
sampleMining = []
for file in saved_files:
with open(file, 'r') as f:
lines = f.readlines()
for _ in range(15):
randomIP = random.choice(lines)
sampleMining.append(randomIP)
sampleMining = [x.strip() for x in sampleMining]
myFile = open("Mining_Results.txt", mode="a+")
for x in tqdm(sampleMining, desc="Testing samples, Results saved at Mining_Results.txt"):
try:
downloader = requests.get(x, timeout=5)
if downloader.status_code == 200:
current_time = time.strftime("%X")
result = f"Timestamp:{str(current_time)} URL:{str(x)}" + " test SUCCESFULL\n"
else:
current_time = time.strftime("%X")
result = f"Timestamp:{str(current_time)} URL:{str(x)}" + " test FAILED\n"
myFile.write(result)
except Exception as e:
current_time = time.strftime("%X")
result = f"Timestamp:{str(current_time)} URL:{str(x)}" + " test FAILED\n"
myFile.write(result)
continue
for file_name in saved_files:
os.remove(file_name)
aprint("random")
clear_screen()
def generate_DGA():
tld_list = ['xyz', 'top', 'zone', 'info', 'biz', 'gq', 'tk', 'club'] #https://trends.netcraft.com/cybercrime/tlds
sampleDGA = []
for _ in range(1, 15):
tld = random.choice(tld_list)
domain_length = random.randint(5, 15)
domain_name = ''.join(random.choices(string.ascii_lowercase, k=domain_length))
dga = f'{domain_name}.{tld}'
sampleDGA.append(dga)
myFile = open("DGA_Results.txt", mode="a+")
ports = [80, 443]
for ip in tqdm(sampleDGA, desc="Testing samples, Results saved at DGA_Results.txt"):
for port in ports:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
result = sock.connect_ex((ip, port))
if result == 0:
current_time = time.strftime("%X")
resultUP = (
f"Timestamp:{str(current_time)} IP:{str(ip)} : Port:{str(port)}"
+ " tested (Actual DGA generated by script, so the domain even may not exist BUT look if your FW or IPS detected the request and tagged it)\n"
)
myFile.write(resultUP)
else:
current_time = time.strftime("%X")
resultDOWN = (
f"Timestamp:{str(current_time)} IP:{str(ip)} : Port:{str(port)}"
+ " tested (Actual DGA generated by script, so the domain even may not exist BUT look if your FW or IPS detected the request and tagged it)\n"
)
myFile.write(resultDOWN)
sock.close()
except Exception as e:
current_time = time.strftime("%X")
resultDOWN = (
f"Timestamp:{str(current_time)} IP:{str(ip)} : Port:{str(port)}"
+ " tested (Actual DGA generated by script, so the domain even may not exist BUT look if your FW or IPS detected the request and tagged it)\n"
)
myFile.write(resultDOWN)
continue
aprint("random")
clear_screen()
def test_RAT():
print('\nUnsanctioned Remote Desktop management tools are used by threat actors for persistance and exfil read more at: https://redcanary.com/blog/misbehaving-rats/')
urls = [
'teamviewer.com', #Functional URLs thanks to https://www.netify.ai/resources/applications
'router1.teamviewer.com',
'udp.ping.teamviewer.com'
'boot.net.anydesk.com',
'rpm.anydesk.com',
'relay-a7a47b7c.net.anydesk.com',
'splashtop.com',
'sdrs.splashtop.com'
'st2-v3-dc.splashtop.com',
'update.logmein.com',
'lmi-app22-01.logmein.com',
'secure.logmeinrescue.com',
'screenconnect.com',
'server-nix4beff1f3-web.screenconnect.com',
'instance-ra153n-relay.screenconnect.com',
'gotoassist.com'
]
ping_args = '-n' if platform.system() == 'Windows' else '-c'
myFile = open("RAT_Results.txt", mode="a+")
for url in tqdm(urls,desc="Testing URLs from known Remote Desktop tools, results saved to RAT_Results.txt"):
try:
subprocess.check_output(['ping', ping_args, '1', url])
current_time = time.strftime("%X")
result = f"Timestamp:{str(current_time)} URL:{str(url)}" + " test DONE\n"
myFile.write(result)
except subprocess.CalledProcessError:
current_time = time.strftime("%X")
result = f"Timestamp:{str(current_time)} URL:{str(url)}" + " test DONE\n"
myFile.write(result)
aprint("random")
clear_screen()
def known_badAgents():
print("Simulating traffic using known bad User-Agent(SPAM,botnet,etc)")
urls = 'https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/_generator_lists/bad-user-agents.list'
saved_files = []
response = requests.get(urls)
if response.status_code == 200:
file_name = urls.split("/")[-1]
with open(file_name, "w") as f:
f.write(response.text)
saved_files.append(file_name)
sampleAgent = []
for file in saved_files:
with open(file, 'r') as f:
lines = f.readlines()
for _ in tqdm(range(15),desc='Downloading Samples'):
randomAgent = random.choice(lines)
sampleAgent.append(randomAgent)
sampleAgent = [x.strip() for x in sampleAgent]
myFile = open("Agent_Results.txt", mode="a+")
url = 'https://google.com'
for agent in tqdm(sampleAgent,desc='Sending HTTPS request to Google with known bad User-Agent'):
headers = {'User-Agent': agent}
response = requests.get(url, headers=headers)
current_time = time.strftime("%X")
result = f"Timestamp:{str(current_time)} URL:{str(agent)}" + " test DONE\n"
myFile.write(result)
for file_name in saved_files:
os.remove(file_name)
aprint("random")
clear_screen()
def dns_HTTPS():
print("Unmanaged DNS using encryption protocols like TLS/HTTPS/QUIC is a risk given the fact that you lose visibility over trafic (requests), if you use a managed DoH/DoT (EX: Umbrella, Zscaler,etc), you should allowlist only those services and block the category of DoH/DoT\n")
domains = ['google.com','example.com','bing.com','cloudflare.com','apple.com']
myFile = open("DoH_Results.txt", mode="a+")
x=0
headers = {
'accept': 'application/dns-json',
}
for _ in tqdm(domains,desc="Generating requests"):
dns_params = {
'name': domains[x],
'type': 'A'
}
y=0
doh_servers = [
'https://dns.google/resolve',
'https://cloudflare-dns.com/dns-query',
]
for _ in doh_servers:
try:
response = requests.get(doh_servers[y], params=dns_params,headers=headers)
dns_response = response.content
current_time = time.strftime("%X")
if doh_servers[y] == "https://dns.google/resolve":
result = f'Timestamp:{str(current_time)} Google response for {domains[x]} is : {dns_response}\n'
myFile.write(result)
elif doh_servers[y] == "https://cloudflare-dns.com/dns-query":
result = f'Timestamp:{str(current_time)} Cloudflare response for {domains[x]} is : {dns_response}\n'
myFile.write(result)
y=y+1
except Exception as e:
result = f'Timestamp:{str(current_time)} Error response for {domains[x]}\n'
myFile.write(result)
x=x+1
aprint("random")
clear_screen()
#Main
Art=text2art("Somnium","rand")
print(Art)
loopEnd = False
while not loopEnd:
choice = input("#1 Test connection with known bad IPs.\n#2 Test connection with known Phishing URLs.\n#3 Test connection to TOR Exits Nodes.\n#4 Test connection to live Malware distribution Urls\n#5 Test connection to known Cryptomining domains.\n#6 Test connection to Domain-Generated-Algorithm Domains.\n#7 Test connection to Remote Desktop Management.(Anydesk,etc.)\n#8 Test connection using known bad user agents.\n#9 Generate DNS queries using DoH\n#0 Exit.\nChoice:")
if int(choice) == 1:
known_IP()
elif int(choice) == 2:
known_phish()
elif int(choice) == 3:
known_TOR()
elif int(choice) == 4:
known_dist()
elif int(choice) == 5:
known_crypto()
elif int(choice) == 6:
generate_DGA()
elif int(choice) == 7:
test_RAT()
elif int(choice) == 8:
known_badAgents()
elif int(choice) == 9:
dns_HTTPS()
##
else:
print("-----")
clear_screen()
exit()