@@ -17,17 +17,11 @@ def clear_screen():
17
17
18
18
def check_ip (ip ):
19
19
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]?)$"
20
- if re .match (pattern , ip ):
21
- return True
22
- else :
23
- return False
20
+ return bool (re .match (pattern , ip ))
24
21
25
22
def check_url (url ):
26
23
pattern = r'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)'
27
- if re .match (pattern , url ):
28
- return True
29
- else :
30
- return False
24
+ return bool (re .match (pattern , url ))
31
25
32
26
def known_IP ():
33
27
urls = [
@@ -47,7 +41,7 @@ def known_IP():
47
41
for file in saved_files :
48
42
with open (file , 'r' ) as f :
49
43
lines = f .readlines ()
50
- for i in range (5 ):
44
+ for _ in range (5 ):
51
45
randomIP = random .choice (lines )
52
46
if check_ip (randomIP ):
53
47
sampleIP .append (randomIP )
@@ -62,16 +56,25 @@ def known_IP():
62
56
result = sock .connect_ex ((ip , port ))
63
57
if result == 0 :
64
58
current_time = time .strftime ("%X" )
65
- resultUP = "Timestamp:" + str (current_time )+ " IP:" + str (ip )+ " : Port:" + str (port )+ " test SUCCESSFUL\n "
59
+ resultUP = (
60
+ f"Timestamp:{ str (current_time )} IP:{ str (ip )} : Port:{ str (port )} "
61
+ + " test SUCCESSFUL\n "
62
+ )
66
63
myFile .write (resultUP )
67
64
else :
68
65
current_time = time .strftime ("%X" )
69
- resultDOWN = "Timestamp:" + str (current_time )+ " IP:" + str (ip )+ " : Port:" + str (port )+ " test FAILED\n "
66
+ resultDOWN = (
67
+ f"Timestamp:{ str (current_time )} IP:{ str (ip )} : Port:{ str (port )} "
68
+ + " test FAILED\n "
69
+ )
70
70
myFile .write (resultDOWN )
71
71
sock .close ()
72
72
except Exception as e :
73
73
current_time = time .strftime ("%X" )
74
- resultDOWN = "Timestamp:" + str (current_time ) + " IP:" + str (ip ) + " : Port:" + str (port ) + " test FAILED\n "
74
+ resultDOWN = (
75
+ f"Timestamp:{ str (current_time )} IP:{ str (ip )} : Port:{ str (port )} "
76
+ + " test FAILED\n "
77
+ )
75
78
myFile .write (resultDOWN )
76
79
continue
77
80
for file_name in saved_files :
@@ -93,7 +96,7 @@ def known_phish():
93
96
for file in saved_files :
94
97
with open (file , 'r' ) as f :
95
98
lines = f .readlines ()
96
- for i in range (15 ):
99
+ for _ in range (15 ):
97
100
randomURL = random .choice (lines )
98
101
if check_url (randomURL ):
99
102
sampleURL .append (randomURL )
@@ -104,11 +107,14 @@ def known_phish():
104
107
response = requests .get (url , timeout = 5 )
105
108
if response .status_code == 200 :
106
109
current_time = time .strftime ("%X" )
107
- resultUP = "Timestamp:" + str (current_time ) + " URL:" + str (url ) + " test SUCCESSFUL\n "
110
+ resultUP = (
111
+ f"Timestamp:{ str (current_time )} URL:{ str (url )} "
112
+ + " test SUCCESSFUL\n "
113
+ )
108
114
myFile .write (resultUP )
109
115
else :
110
116
current_time = time .strftime ("%X" )
111
- resultDOWN = "Timestamp:" + str (current_time ) + " URL:" + str (url ) + " test FAILED\n "
117
+ resultDOWN = f "Timestamp:{ str (current_time )} URL:{ str (url )} " + " test FAILED\n "
112
118
myFile .write (resultDOWN )
113
119
except Exception as e :
114
120
continue
@@ -131,7 +137,7 @@ def known_TOR():
131
137
for file in saved_files :
132
138
with open (file , 'r' ) as f :
133
139
lines = f .readlines ()
134
- for i in range (15 ):
140
+ for _ in range (15 ):
135
141
randomIP = random .choice (lines )
136
142
if check_ip (randomIP ):
137
143
sampleTOR .append (randomIP )
@@ -146,19 +152,25 @@ def known_TOR():
146
152
result = sock .connect_ex ((ip , port ))
147
153
if result == 0 :
148
154
current_time = time .strftime ("%X" )
149
- resultUP = "Timestamp:" + str (current_time ) + " IP:" + str (ip ) + " : Port:" + str (
150
- port ) + " test SUCCESSFUL\n "
155
+ resultUP = (
156
+ f"Timestamp:{ str (current_time )} IP:{ str (ip )} : Port:{ str (port )} "
157
+ + " test SUCCESSFUL\n "
158
+ )
151
159
myFile .write (resultUP )
152
160
else :
153
161
current_time = time .strftime ("%X" )
154
- resultDOWN = "Timestamp:" + str (current_time ) + " IP:" + str (ip ) + " : Port:" + str (
155
- port ) + " test FAILED\n "
162
+ resultDOWN = (
163
+ f"Timestamp:{ str (current_time )} IP:{ str (ip )} : Port:{ str (port )} "
164
+ + " test FAILED\n "
165
+ )
156
166
myFile .write (resultDOWN )
157
167
sock .close ()
158
168
except Exception as e :
159
169
current_time = time .strftime ("%X" )
160
- resultDOWN = "Timestamp:" + str (current_time ) + " IP:" + str (ip ) + " : Port:" + str (
161
- port ) + " test FAILED\n "
170
+ resultDOWN = (
171
+ f"Timestamp:{ str (current_time )} IP:{ str (ip )} : Port:{ str (port )} "
172
+ + " test FAILED\n "
173
+ )
162
174
myFile .write (resultDOWN )
163
175
continue
164
176
for file_name in saved_files :
@@ -174,13 +186,13 @@ def known_dist():
174
186
response = requests .get (baseURL )
175
187
json_response = response .json ()
176
188
counter = 0
177
- for x in tqdm (json_response ["urls" ], desc = "Getting samples list" ):
189
+ for _ in tqdm (json_response ["urls" ], desc = "Getting samples list" ):
178
190
status = json_response ["urls" ][counter ]["url_status" ]
179
191
if status == "online" :
180
192
liveURL = json_response ["urls" ][counter ]["url" ]
181
193
urlsIndex .append (liveURL )
182
194
counter = counter + 1
183
- for i in range (20 ):
195
+ for _ in range (20 ):
184
196
randomSample = random .choice (urlsIndex )
185
197
randomUrlsIndex .append (randomSample )
186
198
myFile = open ("Malware_Results.txt" , mode = "a+" )
@@ -189,15 +201,14 @@ def known_dist():
189
201
downloader = requests .get (x , timeout = 5 )
190
202
if downloader .status_code == 200 :
191
203
current_time = time .strftime ("%X" )
192
- result = "Timestamp:" + str (current_time ) + " URL:" + str (x ) + " test SUCCESFULL\n "
193
- myFile .write (result )
204
+ result = f"Timestamp:{ str (current_time )} URL:{ str (x )} " + " test SUCCESFULL\n "
194
205
else :
195
206
current_time = time .strftime ("%X" )
196
- result = "Timestamp:" + str (current_time ) + " URL:" + str (x ) + " test FAILED\n "
197
- myFile .write (result )
207
+ result = f "Timestamp:{ str (current_time )} URL:{ str (x )} " + " test FAILED\n "
208
+ myFile .write (result )
198
209
except Exception as e :
199
210
current_time = time .strftime ("%X" )
200
- result = "Timestamp:" + str (current_time ) + " URL:" + str (x ) + " test FAILED\n "
211
+ result = f "Timestamp:{ str (current_time )} URL:{ str (x )} " + " test FAILED\n "
201
212
myFile .write (result )
202
213
continue
203
214
aprint ("random" )
@@ -217,7 +228,7 @@ def known_crypto():
217
228
for file in saved_files :
218
229
with open (file , 'r' ) as f :
219
230
lines = f .readlines ()
220
- for i in range (15 ):
231
+ for _ in range (15 ):
221
232
randomIP = random .choice (lines )
222
233
sampleMining .append (randomIP )
223
234
sampleMining = [x .strip () for x in sampleMining ]
@@ -227,15 +238,14 @@ def known_crypto():
227
238
downloader = requests .get (x , timeout = 5 )
228
239
if downloader .status_code == 200 :
229
240
current_time = time .strftime ("%X" )
230
- result = "Timestamp:" + str (current_time ) + " URL:" + str (x ) + " test SUCCESFULL\n "
231
- myFile .write (result )
241
+ result = f"Timestamp:{ str (current_time )} URL:{ str (x )} " + " test SUCCESFULL\n "
232
242
else :
233
243
current_time = time .strftime ("%X" )
234
- result = "Timestamp:" + str (current_time ) + " URL:" + str (x ) + " test FAILED\n "
235
- myFile .write (result )
244
+ result = f "Timestamp:{ str (current_time )} URL:{ str (x )} " + " test FAILED\n "
245
+ myFile .write (result )
236
246
except Exception as e :
237
247
current_time = time .strftime ("%X" )
238
- result = "Timestamp:" + str (current_time ) + " URL:" + str (x ) + " test FAILED\n "
248
+ result = f "Timestamp:{ str (current_time )} URL:{ str (x )} " + " test FAILED\n "
239
249
myFile .write (result )
240
250
continue
241
251
for file_name in saved_files :
@@ -246,11 +256,11 @@ def known_crypto():
246
256
def generate_DGA ():
247
257
tld_list = ['xyz' , 'top' , 'zone' , 'info' , 'biz' , 'gq' , 'tk' , 'club' ] #https://trends.netcraft.com/cybercrime/tlds
248
258
sampleDGA = []
249
- for i in range (1 , 15 ):
259
+ for _ in range (1 , 15 ):
250
260
tld = random .choice (tld_list )
251
261
domain_length = random .randint (5 , 15 )
252
262
domain_name = '' .join (random .choices (string .ascii_lowercase , k = domain_length ))
253
- dga = domain_name + '.' + tld
263
+ dga = f' { domain_name } . { tld } '
254
264
sampleDGA .append (dga )
255
265
myFile = open ("DGA_Results.txt" , mode = "a+" )
256
266
ports = [80 , 443 ]
@@ -262,19 +272,25 @@ def generate_DGA():
262
272
result = sock .connect_ex ((ip , port ))
263
273
if result == 0 :
264
274
current_time = time .strftime ("%X" )
265
- resultUP = "Timestamp:" + str (current_time ) + " IP:" + str (ip ) + " : Port:" + str (
266
- 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 "
275
+ resultUP = (
276
+ f"Timestamp:{ str (current_time )} IP:{ str (ip )} : Port:{ str (port )} "
277
+ + " 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 "
278
+ )
267
279
myFile .write (resultUP )
268
280
else :
269
281
current_time = time .strftime ("%X" )
270
- resultDOWN = "Timestamp:" + str (current_time ) + " IP:" + str (ip ) + " : Port:" + str (
271
- 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 "
282
+ resultDOWN = (
283
+ f"Timestamp:{ str (current_time )} IP:{ str (ip )} : Port:{ str (port )} "
284
+ + " 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 "
285
+ )
272
286
myFile .write (resultDOWN )
273
287
sock .close ()
274
288
except Exception as e :
275
289
current_time = time .strftime ("%X" )
276
- resultDOWN = "Timestamp:" + str (current_time ) + " IP:" + str (ip ) + " : Port:" + str (
277
- 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 "
290
+ resultDOWN = (
291
+ f"Timestamp:{ str (current_time )} IP:{ str (ip )} : Port:{ str (port )} "
292
+ + " 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 "
293
+ )
278
294
myFile .write (resultDOWN )
279
295
continue
280
296
aprint ("random" )
@@ -300,20 +316,17 @@ def test_RAT():
300
316
'instance-ra153n-relay.screenconnect.com' ,
301
317
'gotoassist.com'
302
318
]
303
- if platform .system () == 'Windows' :
304
- ping_args = '-n'
305
- else :
306
- ping_args = '-c'
319
+ ping_args = '-n' if platform .system () == 'Windows' else '-c'
307
320
myFile = open ("RAT_Results.txt" , mode = "a+" )
308
321
for url in tqdm (urls ,desc = "Testing URLs from known Remote Desktop tools, results saved to RAT_Results.txt" ):
309
322
try :
310
323
subprocess .check_output (['ping' , ping_args , '1' , url ])
311
324
current_time = time .strftime ("%X" )
312
- result = "Timestamp:" + str (current_time ) + " URL:" + str (url ) + " test DONE\n "
325
+ result = f "Timestamp:{ str (current_time )} URL:{ str (url )} " + " test DONE\n "
313
326
myFile .write (result )
314
327
except subprocess .CalledProcessError :
315
328
current_time = time .strftime ("%X" )
316
- result = "Timestamp:" + str (current_time ) + " URL:" + str (url ) + " test DONE\n "
329
+ result = f "Timestamp:{ str (current_time )} URL:{ str (url )} " + " test DONE\n "
317
330
myFile .write (result )
318
331
aprint ("random" )
319
332
clear_screen ()
@@ -332,52 +345,85 @@ def known_badAgents():
332
345
for file in saved_files :
333
346
with open (file , 'r' ) as f :
334
347
lines = f .readlines ()
335
- for i in tqdm (range (15 ),desc = 'Downloading Samples' ):
348
+ for _ in tqdm (range (15 ),desc = 'Downloading Samples' ):
336
349
randomAgent = random .choice (lines )
337
350
sampleAgent .append (randomAgent )
338
351
sampleAgent = [x .strip () for x in sampleAgent ]
339
352
myFile = open ("Agent_Results.txt" , mode = "a+" )
353
+ url = 'https://google.com'
340
354
for agent in tqdm (sampleAgent ,desc = 'Sending HTTPS request to Google with known bad User-Agent' ):
341
- url = 'https://google.com'
342
355
headers = {'User-Agent' : agent }
343
356
response = requests .get (url , headers = headers )
344
- if response .status_code == 200 :
345
- current_time = time .strftime ("%X" )
346
- result = "Timestamp:" + str (current_time ) + " URL:" + str (agent ) + " test DONE\n "
347
- myFile .write (result )
348
- else :
349
- current_time = time .strftime ("%X" )
350
- result = "Timestamp:" + str (current_time ) + " URL:" + str (agent ) + " test DONE\n "
351
- myFile .write (result )
357
+ current_time = time .strftime ("%X" )
358
+ result = f"Timestamp:{ str (current_time )} URL:{ str (agent )} " + " test DONE\n "
359
+ myFile .write (result )
352
360
for file_name in saved_files :
353
361
os .remove (file_name )
354
362
aprint ("random" )
355
363
clear_screen ()
364
+ def dns_HTTPS ():
365
+ 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 " )
366
+
367
+ domains = ['google.com' ,'example.com' ,'bing.com' ,'cloudflare.com' ,'apple.com' ]
368
+ myFile = open ("DoH_Results.txt" , mode = "a+" )
369
+ x = 0
370
+ headers = {
371
+ 'accept' : 'application/dns-json' ,
372
+ }
373
+ for _ in tqdm (domains ,desc = "Generating requests" ):
374
+ dns_params = {
375
+ 'name' : domains [x ],
376
+ 'type' : 'A'
377
+ }
378
+ y = 0
379
+ doh_servers = [
380
+ 'https://dns.google/resolve' ,
381
+ 'https://cloudflare-dns.com/dns-query' ,
382
+ ]
383
+ for _ in doh_servers :
384
+ try :
385
+ response = requests .get (doh_servers [y ], params = dns_params ,headers = headers )
386
+ dns_response = response .content
387
+ current_time = time .strftime ("%X" )
388
+ if doh_servers [y ] == "https://dns.google/resolve" :
389
+ result = f'Timestamp:{ str (current_time )} Google response for { domains [x ]} is : { dns_response } \n '
390
+ myFile .write (result )
391
+ elif doh_servers [y ] == "https://cloudflare-dns.com/dns-query" :
392
+ result = f'Timestamp:{ str (current_time )} Cloudflare response for { domains [x ]} is : { dns_response } \n '
393
+ myFile .write (result )
394
+ y = y + 1
395
+ except Exception as e :
396
+ result = f'Timestamp:{ str (current_time )} Error response for { domains [x ]} \n '
397
+ myFile .write (result )
398
+ x = x + 1
399
+ aprint ("random" )
400
+ clear_screen ()
356
401
#Main
357
- Art = text2art ("Somnium: NetSec testing script " ,"rand" )
402
+ Art = text2art ("Somnium" ,"rand" )
358
403
print (Art )
359
404
loopEnd = False
360
- while (loopEnd == False ):
361
- 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 #0 Exit.\n Choice:" )
362
- if int (choice ) == 1 :
363
- known_IP ()
364
- elif int (choice ) == 2 :
365
- known_phish ()
366
- elif int (choice ) == 3 :
367
- known_TOR ()
368
- elif int (choice ) == 4 :
369
- known_dist ()
370
- elif int (choice ) == 5 :
371
- known_crypto ()
372
- elif int (choice ) == 6 :
373
- generate_DGA ()
374
- elif int (choice ) == 7 :
375
- test_RAT ()
376
- elif int (choice ) == 8 :
377
- known_badAgents ()
378
- else :
379
- print ("-----" )
380
- clear_screen ()
381
- exit ()
382
-
383
-
405
+ while not loopEnd :
406
+ 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.\n Choice:" )
407
+ if int (choice ) == 1 :
408
+ known_IP ()
409
+ elif int (choice ) == 2 :
410
+ known_phish ()
411
+ elif int (choice ) == 3 :
412
+ known_TOR ()
413
+ elif int (choice ) == 4 :
414
+ known_dist ()
415
+ elif int (choice ) == 5 :
416
+ known_crypto ()
417
+ elif int (choice ) == 6 :
418
+ generate_DGA ()
419
+ elif int (choice ) == 7 :
420
+ test_RAT ()
421
+ elif int (choice ) == 8 :
422
+ known_badAgents ()
423
+ elif int (choice ) == 9 :
424
+ dns_HTTPS ()
425
+ ##
426
+ else :
427
+ print ("-----" )
428
+ clear_screen ()
429
+ exit ()
0 commit comments