/
Adarma.py
576 lines (485 loc) · 17 KB
/
Adarma.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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
"""
Created by Nicholas Venis 25/06/19
Inspired by Sooty (https://github.com/TheresAFewConors/Sooty), changed for Python 2.7
"""
import re
import csv
import subprocess
import os
import urllib2
from Tkinter import *
import Tkinter, Tkconstants, tkFileDialog
import hashlib
import json
import socket
from ipwhois import IPWhois
try:
import email
from email.parser import HeaderParser
except ImportError:
print("Please install the ipwhois package via pip before running.")
print("To install 'pip install ipwhois'")
exit(0)
VT_API_KEY = ''
deleted = False
try:
if os.path.exists("vtkeys.txt"):
r = open("vtkeys.txt", "r")
VT_API_KEY = r.read()
r.close()
except Exception as e:
print(e)
def switchMenu(option):
if option == "1":
nslookup()
if option == "2":
domainExtract()
if option == "3":
sanitise()
if option == "4":
vtReport()
if option == "5":
hashMenu()
if option == "6":
hibp()
if option == "7":
dnsMenu()
if option == "8":
emailMenu()
if option == "9":
settingsMenu()
if option == "0":
exit(1)
else:
print("Please enter a valid option or 0 to exit\n")
mainMenu()
def mainMenu():
print("\n ___ ______ ___ _________ ___ ___ ")
print(" / _ \| _ \/ _ \ | ___ \ \/ | / _ \ ")
print('/ /_\ \ | | / /_\ \| |_/ / . . |/ /_\ \\')
print("| _ | | | | _ || /| |\/| || _ |")
print("| | | | |/ /| | | || |\ \| | | || | | |")
print("\_| |_/___/ \_| |_/\_| \_\_| |_/\_| |_/")
print("\n\nWhat would you like to do?")
print("\nOPTION 1: Nslookup")
print("OPTION 2: Extract domains")
print("OPTION 3: Sanitise URLs")
print("OPTION 4: Reputation check")
print("OPTION 5: Hash suite")
print("OPTION 6: Have i been pwned?")
print("OPTION 7: Ip/DNS tools")
print("OPTION 8: Email tools")
print("OPTION 9: Settings\n")
print("OPTION 0: Exit\n")
switchMenu(raw_input())
def nslookup():
print("\n--------------------------------- ")
print(" \t\tN S L O O K U P ")
print("--------------------------------- ")
try:
inp = str(raw_input("Enter an IP or hostname\n"))
out = subSystem(inp)
host = out.split()
if str(host[5]) == "answer:":
print("\nDevice not in estate")
elif str(host[5]) == "name":
print('\nAsset:')
print("ip: " + str(host[1]))
print("hostname: " + str(host[7]) + "\n")
print('\nFull output:\n')
print(str(out))
else:
print('\nAsset:')
print("ip: " + str(host[7]))
print("hostname: " + str(host[5]) + "\n")
print('\nFull output:\n')
print(str(out))
mainMenu()
except Exception as e:
print(e)
mainMenu()
def subSystem(ip):
proc = subprocess.Popen('nslookup ' + ip, shell=True, stdout=subprocess.PIPE)
tmp = proc.stdout.read()
return tmp
def domainExtract():
root = Tk()
root.filename = tkFileDialog.askopenfilename(initialdir="/", title="Select file")
fileName = root.filename
urls = []
header = False
try:
with open(fileName) as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV:
url = row[0]
urls.append(url)
for index, item in enumerate(urls):
m = re.search('h[a-z]{2}ps?://([A-Za-z_0-9.-]+).*', urls[index])
if m is None:
print("Header:" + urls[index])
header = True
continue
urls[index] = m.group(1)
fileName = fileName.replace(".csv", "")
fileName += "-DOMAINS.csv"
if header is False:
urls.insert(0, "url")
with open(fileName, "wb") as newcsv:
wr = csv.writer(newcsv, delimiter=",")
for url in urls:
wr.writerow([url])
print("Created csv: " + fileName + " successfully!")
except Exception as e:
print(e)
root.destroy()
mainMenu()
def sanitise():
print("Enter URL to sanitize: ")
url = raw_input()
x = re.sub("\.", "[.]", url)
x = re.sub("http://", "hxxp://", x)
x = re.sub("https://", "hxxps://", x)
print("\n" + x)
mainMenu()
def vtReport():
global VT_API_KEY
ip = str(raw_input("\nEnter ip or URL to check\n"))
print("VirusTotal report for: " + ip)
apiKey = "apikey=" + VT_API_KEY
res = "&ip=" + ip
site = "https://www.virustotal.com/vtapi/v2/ip-address/report?" + apiKey + res
hdr = {
"User-Agent": "'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'}
pos = 0
tot = 0
try:
req = urllib2.Request(site, headers=hdr)
response = urllib2.urlopen(req)
page = json.load(response)
if response.getcode() == 200:
try:
try:
for i in page['detected_urls']:
tot = tot + 1
pos = pos + i['positives']
if tot != 0:
print(" No of Reportings: " + str(tot))
print(" Average Score: " + str(pos / tot))
print(" VirusTotal Report Link: " + "https://www.virustotal.com/gui/ip-address/" + str(ip))
else:
print(" No of Reportings: " + str(tot))
except:
site = "https://www.virustotal.com/vtapi/v2/url/report?" + apiKey + "&resource=" + ip
req = urllib2.Request(site, headers=hdr)
response = urllib2.urlopen(req)
page = json.load(response)
print("\n VirusTotal Report:")
print(" URL Malicious Reportings: " + str(page['positives']) + "/" + str(page['total']))
print(" VirusTotal Report Link: " + str(page['permalink']))
except:
print("IP or URL not found in VT database")
else:
print(" There's been an error - check your API key, or VirusTotal is possibly down")
mainMenu()
except:
print("Unable to connect to VirusTotal, check connection and api key is present")
site = "https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=1.1.1.1"
hdr = {
"User-Agent": "'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'}
req = urllib2.Request(site, headers=hdr)
try:
page = urllib2.urlopen(req)
print("\n TOR Exit Node Report: ")
if page.status_code == 200:
tl = page.text.split('\n')
c = 0
for i in tl:
if ip == i:
print(" " + i + " is a TOR Exit Node")
c = c + 1
if c == 0:
print(" " + ip + " is NOT a TOR Exit Node")
else:
print(" TOR LIST UNREACHABLE")
except:
print('\nTor list unreachable!')
print("\nChecking BadIP's... ")
try:
site = 'https://www.badips.com/get/info/' + ip
hdr = {
"User-Agent": "'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'}
req = urllib2.Request(site, headers=hdr)
page = urllib2.urlopen(req)
if page.status_code == 200:
result = json.load(page)
sc = result['Score']['ssh']
print(" " + str(result['suc']))
print(" Score: " + str(sc))
else:
print(' Error reaching BadIPs')
except:
print(' IP not found')
mainMenu()
def hashMenu():
print("\n--------------------------------- ")
print(" \t H A S H S U I T E ")
print("--------------------------------- ")
print("\nWhat would you like to do?")
print("\nOPTION 1: Generate file hash")
print("OPTION 2: Check file hash in VT")
print("OPTION 3: Return to menu")
hashSwitch(raw_input())
def hashSwitch(option):
if option == "1":
hashGen()
if option == "2":
vtHashCheck()
if option == "3":
mainMenu()
def hashGen():
root = Tk()
root.filename = tkFileDialog.askopenfilename(initialdir="/", title="Select file")
hasher = hashlib.md5()
with open(root.filename, 'rb') as r:
buf = r.read()
hasher.update(buf)
print(" MD5 Hash: " + hasher.hexdigest())
root.destroy()
hashMenu()
def dnsMenu():
print("\n --------------------------------- ")
print(" D N S T O O L S ")
print(" --------------------------------- ")
print(" What would you like to do? ")
print(" OPTION 1: Reverse DNS Lookup")
print(" OPTION 2: DNS Lookup")
print(" OPTION 3: WHOIS Lookup")
print(" OPTION 4: Exit to Main Menu")
dnsSwitch(raw_input())
def dnsSwitch(option):
if option == "1":
revDNS()
if option == "2":
dnsLookup()
if option == "3":
whoIs()
if option == "4":
mainMenu()
def revDNS():
d = raw_input("Enter IP to check:\n")
try:
s = socket.gethostbyaddr(d)
print('\n ' + s[0])
except:
print(" Hostname not found")
dnsMenu()
def dnsLookup():
d = raw_input("Enter Domain Name to check:\n")
d = re.sub("http://", "", d)
d = re.sub("https://", "", d)
try:
s = socket.gethostbyname(d)
print('\n ' + s)
except:
print("Website not found")
dnsMenu()
def whoIs():
ip = raw_input(' Enter IP: ')
try:
w = IPWhois(ip)
w = w.lookup_whois()
addr = str(w['nets'][0]['address'])
addr = addr.replace('\n', ', ')
print("\n WHO IS REPORT:")
print(" CIDR: " + str(w['nets'][0]['cidr']))
print(" Name: " + str(w['nets'][0]['name']))
# print(" Handle: " + str(w['nets'][0]['handle']))
print(" Range: " + str(w['nets'][0]['range']))
print(" Descr: " + str(w['nets'][0]['description']))
print(" Country: " + str(w['nets'][0]['country']))
print(" State: " + str(w['nets'][0]['state']))
print(" City: " + str(w['nets'][0]['city']))
print(" Address: " + addr)
print(" Post Code: " + str(w['nets'][0]['postal_code']))
# print(" Emails: " + str(w['nets'][0]['emails']))
print(" Created: " + str(w['nets'][0]['created']))
print(" Updated: " + str(w['nets'][0]['updated']))
except:
print(" IP Not Found")
dnsMenu()
def vtHashCheck():
global VT_API_KEY
hash = raw_input("\nEnter hash of file for lookup:\n")
apiKey = "apikey=" + VT_API_KEY
res = "&resource=" + hash
site = "https://www.virustotal.com/vtapi/v2/file/report?" + apiKey + res
hdr = {
"User-Agent": "'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'}
req = urllib2.Request(site, headers=hdr)
count = 0
try:
page = json.load(urllib2.urlopen(req))
try:
if page['positives'] != 0:
print("\n Malware Detection")
for key, value in page['scans'].items():
if value['detected'] == True:
count = count + 1
print(" VirusTotal Report: " + str(count) + " detections found")
print(" Report Link: " + "https://www.virustotal.com/gui/file/" + hash + "/detection")
except:
print("No positives found for hash")
except Exception as e:
print(e)
hashMenu()
def hibp():
acc = raw_input("\nPlease enter an email address to check\n")
url = "https://haveibeenpwned.com/api/v2/breachedaccount/" + acc
hdr = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"}
try:
req = urllib2.Request(url, headers=hdr)
response = urllib2.urlopen(req)
page = json.load(response)
if response.getcode() == 200:
le = len(page)
for i in range(le):
dc = str(page[i]['DataClasses'])
dc = re.sub('\[(?:[^\]|]*\|)?([^\]|]*)\]', r'\1', dc)
dc = dc.replace("'", '')
print("\n")
print("Name: " + str(page[i]['Title']))
print("Domain: " + str(page[i]['Domain']))
print("Breached: " + str(page[i]['BreachDate']))
print("Details: " + str(dc))
print("Verified: " + str(page[i]['IsVerified']))
else:
print("Email not found in database")
mainMenu()
except Exception as e:
print(e)
mainMenu()
def emailMenu():
print("\n --------------------------------- ")
print(" E M A I L T O O L S ")
print(" --------------------------------- ")
print(" What would you like to do? ")
print(" OPTION 1: Get headers")
print(" OPTION 4: Exit to Main Menu")
emailSwitch(raw_input())
def emailSwitch(option):
if option == "1":
getHeaders()
if option == "2":
mainMenu()
def getHeaders():
root = Tk()
root.filename = tkFileDialog.askopenfilename(initialdir="/", title="Select file")
buf = open(root.filename, "rb")
msg = email.message_from_file(buf)
try:
parser = HeaderParser()
h = parser.parsestr(str(msg))
for i in h.items():
for p in i:
print (p + "\n")
except Exception as e:
print(e)
root.destroy()
emailMenu()
def settingsMenu():
global VT_API_KEY
global deleted
vtTemp = ""
found = False
if VT_API_KEY != "":
vtTemp = VT_API_KEY[-4:]
found = True
print("\n--------------------------------- ")
print(" \t\tS E T T I N G S ")
print("--------------------------------- ")
if found == True and deleted == False:
print("VT API key found, ends in: " + vtTemp)
else:
print("No VT API key found")
print("\nWhat would you like to do?")
print("\nOPTION 1: Add api key")
print("OPTION 2: Remove api key")
print("OPTION 3: Check connectivity")
print("OPTION 4: Return to menu")
settingsSwitch(raw_input())
def settingsSwitch(option):
if option == "1":
addKey()
if option == "2":
delKey()
if option == "3":
checkConnect()
if option == "4":
mainMenu()
def checkConnect():
global VT_API_KEY
try:
global VT_API_KEY
if VT_API_KEY != "":
apiKey = "apikey=" + VT_API_KEY
site = "https://www.virustotal.com/vtapi/v2/file/report?" + apiKey
hdr = {
"User-Agent": "'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'}
req = urllib2.Request(site, headers=hdr)
try:
page = urllib2.urlopen(req)
if page.getcode() == 200:
print("\nAPI Working correctly")
settingsMenu()
else:
print(page.getcode())
settingsMenu()
except Exception as e:
print(e)
else:
print("No VT api key found, please add one.")
settingsMenu()
except Exception as e:
print(e)
def addKey():
global VT_API_KEY, deleted
print("\nPlease enter a valid VirusTotal API key\n")
VT_API_KEY = raw_input()
try:
if os.path.exists("vtkeys.txt"):
w = open("vtkeys.txt", "w")
w.truncate(0)
w.write(VT_API_KEY)
w.close()
vtTemp = VT_API_KEY[-4:]
print("Successfully written key ending in: " + vtTemp)
deleted = False
settingsMenu()
else:
w = open("vtkeys.txt", "w")
w.write(VT_API_KEY)
w.close()
vtTemp = VT_API_KEY[-4:]
print("Successfully written key ending in: " + vtTemp)
deleted = False
settingsMenu()
except Exception as e:
print(e)
def delKey():
global deleted
if os.path.exists("vtkeys.txt"):
os.remove("vtkeys.txt")
print("API key removed successfully")
deleted = True
settingsMenu()
else:
settingsMenu()
if __name__ == '__main__':
mainMenu()