forked from wirasecure/pentest-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remoterecon.py
executable file
·881 lines (753 loc) · 33.3 KB
/
remoterecon.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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
#!/usr/bin/python
###################################################
#
# RemoteRecon - written by Justin Ohneiser
# ------------------------------------------------
# Inspired by reconscan.py by Mike Czumak
#
# This program will conduct full reconnaissance
# on a target using three steps:
# 1. Light NMAP scan -> to identify services
# 2. Modular enumeration for each service
# 3. Heavy NMAP scan
#
# [Warning]:
# This script comes as-is with no promise of functionality or accuracy. I strictly wrote it for personal use
# I have no plans to maintain updates, I did not write it to be efficient and in some cases you may find the
# functions may not produce the desired results so use at your own risk/discretion. I wrote this script to
# target machines in a lab environment so please only use it against systems for which you have permission!!
#-------------------------------------------------------------------------------------------------------------
# [Modification, Distribution, and Attribution]:
# You are free to modify and/or distribute this script as you wish. I only ask that you maintain original
# author attribution and not attempt to sell it or incorporate it into any commercial offering (as if it's
# worth anything anyway :)
#
# Designed for use in Kali Linux 4.6.0-kali1-686
###################################################
import os, sys, subprocess, re, urlparse
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
# ------------------------------------
# Toolbox
# ------------------------------------
def printHeader(target):
print ""
print "###################################################"
print "## Enumerating %s" % target
print "##"
print "###################################################"
print ""
def printUsage():
print "Usage: %s <target ip>" % sys.argv[0]
def printPlus(message):
print bcolors.OKGREEN + "[+] " + message + bcolors.ENDC
def printMinus(message):
print bcolors.WARNING + "[-] " + message + bcolors.ENDC
def printStd(message):
print "[*] " + message
def printErr(message):
print bcolors.FAIL + "[!] " + message + bcolors.ENDC
def printDbg(message):
print bcolors.OKBLUE + "[?] " + message + bcolors.ENDC
def printInBox(command, result):
top = "###################################################"
bot = "==================================================="
sub = "---------------------------------------------------"
return "%s\n\n%s\n\n%s\n\n%s\n%s\n" % (top, command, sub, result, bot)
def parseNmapScan(results):
services = {}
lines = results.split("\n")
for line in lines:
ports = []
line = line.strip()
if ("tcp" in line or "udp" in line) and ("open" in line) and not ("filtered" in line) and not ("Discovered" in line):
while " " in line:
line = line.replace(" ", " ");
linesplit = line.split(" ")
service = linesplit[2]
port = linesplit[0]
if service in services:
ports = services[service]
ports.append(port)
services[service] = ports
return services
def dispatchModules(target, services):
for service in services:
ports = services[service]
if service in KNOWN_SERVICES:
try:
KNOWN_SERVICES[service](target, ports)
except AttributeError:
printDbg("No module available for %s - %s" % (service, ports))
else:
printDbg("No module available for %s - %s" % (service, ports))
def validate_ip(s):
a = s.split('.')
if len(a) != 4:
return False
for x in a:
if not x.isdigit():
return False
i = int(x)
if i < 0 or i > 255:
return False
return True
def parse_ip(s):
urls = re.findall("http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+", s)
for url in urls:
url = url.lower()
return list(set(urls))
def parse_ip_directories(s):
urls = re.findall("http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+/", s)
for url in urls:
url = url.lower()
return list(set(urls))
# ------------------------------------
# Setup
# ------------------------------------
def prepareFolder(target):
printStd("Preparing portfolio")
directory = "%s/%s" % (os.getcwd(), target)
if not os.path.exists(directory):
os.makedirs(directory)
return None
return directory
def writeToFile(target, name, content):
path = "%s/%s/%s.txt" % (os.getcwd(), target, name)
file = open(path, "a+")
file.write(content)
file.close()
return path
# ------------------------------------
# Scans
# ------------------------------------
# Light NMAP
# ========================
def conductLightNmap(target):
printStd("Conducting light nmap scan")
NAME = "nmap_light"
# Conduct Scan #
TCPSCAN = "nmap %s" % target
UDPSCAN = "nmap -sU -p 161 %s" % target
tcpResults = ""
udpResults = ""
try:
tcpResults = subprocess.check_output(TCPSCAN, shell=True)
udpResults = subprocess.check_output(UDPSCAN, shell=True)
print "%s" % tcpResults
# Write Results #
content = "%s" % printInBox(TCPSCAN, tcpResults)
path = writeToFile(target, NAME, content)
printPlus("Finished light nmap scan: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % TCPSCAN)
except Exception as e:
printErr("Unable to conduct light nmap scan:\n\t%s\n\n%s" % (TCPSCAN, e))
sys.exit(2)
# Filter Results #
services = parseNmapScan("%s\n%s" % (tcpResults, udpResults))
return services
# ========================
# Heavy NMAP
# ========================
def conductHeavyNmap(target):
printStd("Conducting heavy nmap scan")
NAME = "nmap_heavy"
# Conduct Heavy nmap Scan #
TCPSCAN = "nmap -A --top-ports 10000 %s" % target
try:
tcpResults = subprocess.check_output(TCPSCAN, shell=True)
# Write Results #
content = "%s" % printInBox(TCPSCAN, tcpResults)
path = writeToFile(target, NAME, content)
printPlus("Finished heavy nmap scan: %s/%s/nmap_heavy.txt" % (os.getcwd(), target))
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % TCPSCAN)
except Exception:
printErr("Unable to conduct heavy nmap scan:\n\t%s" % TCPSCAN)
printStd("Conducting UDP scan")
# Conduct UDP Scan #
UDPSCAN = "nmap -sU --top-ports 100 %s" % target
try:
udpResults = subprocess.check_output(UDPSCAN, shell=True)
# Write Results #
content = "%s" % printInBox(UDPSCAN, udpResults)
path = writeToFile(target, NAME, content)
printPlus("Finished UDP scan: %s/%s/nmap_heavy.txt" % (os.getcwd(), target))
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % UDPSCAN)
except Exception:
printErr("Unable to conduct UDP scan:\n\t%s" % UDPSCAN)
# ========================
# FTP
# ========================
def ftp(target, ports):
printStd("Investigating FTP")
NAME = "ftp"
# Conduct nmap Scan #
portString = ""
for port in ports:
port = port.split("/")[0]
portString += "%s," % port
SCRIPTS = "ftp-vuln-*, ftp-anon"
NMAPSCAN = "nmap -p %s -sV -sC --script=\"%s\" %s" % (portString, SCRIPTS, target)
try:
nmapResults = subprocess.check_output(NMAPSCAN, shell=True)
# Write Results #
content = "%s" % printInBox(NMAPSCAN, nmapResults)
path = writeToFile(target, NAME, content)
printPlus("Finished investigating FTP: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % NMAPSCAN)
except Exception:
printErr("Unable to conduct FTP scan:\n\t%s" % NMAPSCAN)
# ========================
# SMTP
# ========================
def smtp(target, ports):
printStd("Investigating SMTP")
NAME = "smtp"
# Conduct nmap Scan #
portString = ""
for port in ports:
port = port.split("/")[0]
portString += "%s," % port
NMAPSCAN = "nmap -p %s -sV --script=\"smtp-vuln*\" %s" % (portString, target)
try:
nmapscanResults = subprocess.check_output(NMAPSCAN, shell=True)
# Write Results #
content = "%s" % printInBox(NMAPSCAN, nmapscanResults)
path = writeToFile(target, NAME, content)
printPlus("Finished scanning SMTP: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % NMAPSCAN)
except Exception:
printErr("Unable to conduct SMTP scan:\n\t%s" % NMAPSCAN)
# Conduct Brute #
printStd("Trying to brute-force SMTP users")
SCAN1 = "smtp-user-enum -M EXPN -U /usr/share/fern-wifi-cracker/extras/wordlists/common.txt -t %s" % target
try:
scan1Results = subprocess.check_output(SCAN1, shell=True)
# Write Results #
content = "%s" % (printInBox(SCAN1, scan1Results))
path = writeToFile(target, NAME, content)
printPlus("Finished investigating SMTP: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % SCAN1)
except Exception:
printErr("Unable to conduct SMTP brute force:\n\t%s\n\t%s" % SCAN1)
# ========================
# POP3
# ========================
def pop3(target, ports):
printStd("Investigating POP3")
NAME = "pop3"
# Conduct Basic Scan"
portString = ""
for port in ports:
port = port.split("/")[0]
portString += "%s," % port
NMAPSCAN = "nmap -p %s -sV --script=\"pop3-capabilities,pop3-ntlm-info\" %s" % (portString, target)
try:
nmapscanResults = subprocess.check_output(NMAPSCAN, shell=True)
# Write Results #
content = "%s" % printInBox(NMAPSCAN, nmapscanResults)
path = writeToFile(target, NAME, content)
printPlus("Finished enumerating POP3: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % NMAPSCAN)
except Exception:
printErr("Unable to enumerate POP3:\n\t%s" % NMAPSCAN)
# Conduct Brute Force"
printStd("Trying to brute-force POP3 users")
BRUTE = "nmap -p %s --script=\"pop3-brute\" %s" % (portString, target)
try:
bruteResults = subprocess.check_output(BRUTE, shell=True)
# Write Results #
content = "%s" % printInBox(BRUTE, bruteResults)
path = writeToFile(target, NAME, content)
printPlus("Finished investigating POP3: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % BRUTE)
except Exception:
printErr("Unable to brute-force POP3 users:\n\t%s" % BRUTE)
# ========================
# IMAP
# ========================
def imap(target, ports):
printStd("Investigating IMAP")
NAME = "imap"
# Conduct Basic Scan"
portString = ""
for port in ports:
port = port.split("/")[0]
portString += "%s," % port
NMAPSCAN = "nmap -p %s -sV --script=\"imap-capabilities,imap-ntlm-info\" %s" % (portString, target)
try:
nmapscanResults = subprocess.check_output(NMAPSCAN, shell=True)
# Write Results #
content = "%s" % printInBox(NMAPSCAN, nmapscanResults)
path = writeToFile(target, NAME, content)
printPlus("Finished enumerating IMAP: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % NMAPSCAN)
except Exception:
printErr("Unable to enumerate IMAP:\n\t%s" % NMAPSCAN)
# Conduct Brute Force"
printStd("Trying to brute-force IMAP users")
BRUTE = "nmap -p %s --script=\"imap-brute\" %s" % (portString, target)
try:
bruteResults = subprocess.check_output(BRUTE, shell=True)
# Write Results #
content = "%s" % printInBox(BRUTE, bruteResults)
path = writeToFile(target, NAME, content)
printPlus("Finished investigating IMAP: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % BRUTE)
except Exception:
printErr("Unable to brute-force IMAP users:\n\t%s" % BRUTE)
# ========================
# SMB
# ========================
def smb(target, ports):
printStd("Investigating SMB")
NAME = "smb"
# Conduct Vulnerability Scans #
SCAN1 = "nmap -sV -sC --script=\"smb-vuln-*,samba-vuln-*\" -p 445,139 %s" % target
SCAN2 = "nmap -sU -sV -sC --script=\"smb-vuln-*\" -p U:137,T:139 %s" % target
try:
scan1Results = subprocess.check_output(SCAN1, shell=True)
scan2Results = subprocess.check_output(SCAN2, shell=True)
# Write Results #
content = "%s\n%s" % (printInBox(SCAN1, scan1Results), printInBox(SCAN2, scan2Results))
path = writeToFile(target, NAME, content)
printPlus("Finished investigating SMB Vulnerabilities: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s\n\t%s" % (SCAN1, SCAN2))
except Exception:
printErr("Unable to conduct SMB vulnerability scan:\n\t%s\n\t%s" % (SCAN1, SCAN2))
# Conduct Scan #
printStd("Investigating SMB Access")
LOOKUP = "nmblookup -A %s" % target
SCAN = "enum4linux %s" % target
ADVICE = "use :: smbclient //<server>/<share> -I <target ip> -N :: to mount shared drive anonymously"
try:
# Lookup #
lookupResults = subprocess.check_output(LOOKUP, shell=True)
# Write Results #
content = "%s" % printInBox(LOOKUP, lookupResults)
path = writeToFile(target, NAME, content)
# Scan #
scanResults = subprocess.check_output(SCAN, shell=True)
# Write Results #
content = "%s" % printInBox(SCAN, "%s\n\n%s" % (scanResults, ADVICE))
path = writeToFile(target, NAME, content)
printPlus("Finished investigating SMB: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % SCAN)
except Exception:
printErr("Unable to conduct SMB scan:\n\t%s" % SCAN)
# ========================
# HTTP
# ========================
def http(target, ports):
printStd("Investigating HTTP")
NAME = "http"
# Conduct nmap Scan #
SCRIPTS = "http-methods,http-robots.txt,http-vuln-*,http-userdir-enum,http-iis-webdav-vuln,http-majordomo2-dir-traversal,http-axis2-dir-traversal,http-tplink-dir-traversal,http-useragent-tester"
portString = ""
for port in ports:
port = port.split("/")[0]
portString += "%s," % port
NMAPSCAN = "nmap -p %s -sC -sV --script=\"%s\" %s" % (portString, SCRIPTS, target)
try:
nmapscanResults = subprocess.check_output(NMAPSCAN, shell=True)
# Write Results #
content = "%s" % printInBox(NMAPSCAN, nmapscanResults)
path = writeToFile(target, NAME, content)
printPlus("Finished scanning HTTP: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % NMAPSCAN)
except Exception:
printErr("Unable to conduct HTTP scan:\n\t%s" % NMAPSCAN)
# Conduct WebDav Scan #
printStd("Trying to identify WebDav")
WEBDAVSCAN = "nmap -p %s --script http-webdav-scan %s -d 2>/dev/null | grep 'http-webdav-scan %s'" % (portString, target, target)
try:
webdavscanResults = subprocess.check_output(WEBDAVSCAN, shell=True)
# Write Results #
content = "%s" % printInBox(WEBDAVSCAN, webdavscanResults)
path = writeToFile(target, NAME, content)
printPlus("Finished scanning WebDav: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % WEBDAVSCAN)
except subprocess.CalledProcessError as ex:
if ex.returncode != 1:
raise Exception
except Exception:
printErr("Unable to perform WebDav analysis:\n\t%s" % WEBDAVSCAN)
# Conduct Brute #
for port in ports:
urlArr = []
urlDir = ["/"]
port = port.split("/")[0]
printStd("Trying to brute-force HTTP directories on port %s" % port)
DIRB = "dirb http://%s:%s /usr/share/wordlists/dirb/common.txt -S -r" % (target, port)
try:
dirbResults = subprocess.check_output(DIRB, shell=True)
# Parse Results for Spider #
urlArr = parse_ip(dirbResults)
urlDir = parse_ip_directories(dirbResults)
# Write Results #
content = "%s" % printInBox(DIRB, dirbResults)
path = writeToFile(target, NAME, content)
printPlus("Finished HTTP brute-force against port %s: %s - Found: %s" % (port, path, len(urlArr)))
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % DIRB)
except Exception:
printErr("Unable to brute-force HTTP on port %s:\n\t%s" % (port, DIRB))
# Conduct Spider #
SCRIPTS = "http-shellshock,http-auth-finder,http-backup-finder,http-comments-displayer,http-config-backup,http-default-accounts,http-dombased-xss,http-errors,http-fileupload-exploiter,http-method-tamper,http-passwd,http-phpmyadmin-dir-traversal,http-phpself-xss,http-rfi-spider,http-sitemap-generator,http-sql-injection,http-stored-xss,http-unsafe-output-escaping"
# Spidered Vulnerability Scans
for url in urlDir:
# Nikto Scan #
NIKTO = "nikto -host http://%s:%s -root %s" % (target, port, urlparse.urlparse(url).path)
try:
printStd("Crawling %s for vulnerabilities (nikto)" % url)
niktoResults = subprocess.check_output(NIKTO, shell=True)
# ...sometimes this doesn't work...?
if "0 host(s) tested" in niktoResults:
niktoResults = subprocess.check_output(NIKTO, shell=True)
if "0 host(s) tested" in niktoResults:
printDbg(niktoResults)
raise Exception
# Write Results #
content = "%s" % printInBox(NIKTO, niktoResults)
path = writeToFile(target, NAME, content)
printPlus("Finished crawling %s for vulnerabilities (nikto): %s" % (url, path))
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % NIKTO)
except Exception as e:
print str(e)
printErr("Unable to conduct HTTP vulnerability crawl (nikto):\n\t%s" % NIKTO)
# Nmap Scan #
SCRIPTARGS = "http-shellshock.uri=%(url)s,http-backup-finder.url=%(url)s,http-config-backup.path=%(url)s,http-default-accounts.category=web,http-default-accounts.basepath=%(url)s,httpspider.url=%(url)s,http-method-tamper.uri=%(url)s,http-passwd.root=%(url)s,http-phpmyadmin-dir-traversal.dir=%(url)s,http-phpself-xss.uri=%(url)s,http-rfi-spider.url=%(url)s,http-sitemap-generator.url=%(url)s,http-sql-injection.url=%(url)s,http-unsafe-output-escaping.url=%(url)s" % {"url":urlparse.urlparse(url).path}
VULNSCAN = "nmap -p %s %s --script=\"%s\" --script-args=\"%s\" 2>&1" % (port, target, SCRIPTS, SCRIPTARGS)
try:
printStd("Crawling %s for vulnerabilities (nmap)" % url)
vulnscanResults = subprocess.check_output(VULNSCAN, shell=True)
# Write Results #
content = "%s" % printInBox(VULNSCAN, vulnscanResults)
path = writeToFile(target, NAME, content)
printPlus("Finished crawling %s for vulnerabilities (nmap): %s" % (url, path))
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % VULNSCAN)
except Exception:
printErr("Unable to conduct HTTP vulnerability crawl (nmap):\n\t%s" % VULNSCAN)
# ========================
# HTTPS
# ========================
def https(target, ports):
printStd("Investigating HTTPS")
NAME = "https"
# Conduct NMAP Scan #
SCRIPTS = "http-methods,http-robots.txt,http-vuln-*,http-shellshock,http-userdir-enum,http-iis-webdav-vuln,http-majordomo2-dir-traversal,http-axis2-dir-traversal,http-tplink-dir-traversal,http-useragent-tester,ssl-*"
portString = ""
for port in ports:
port = port.split("/")[0]
portString += "%s," % port
NMAPSCAN = "nmap -p %s -sV -sC --script=\"%s\" %s" % (portString, SCRIPTS, target)
try:
nmapscanResults = subprocess.check_output(NMAPSCAN, shell=True)
# Write Scan Results #
content = "%s" % printInBox(NMAPSCAN, nmapscanResults)
path = writeToFile(target, NAME, content)
printPlus("Finished scanning HTTPS: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % NMAPSCAN)
except Exception:
printErr("Unable to conduct HTTPS scan:\n\t%s" % NMAPSCAN)
# Conduct WebDav Scan #
printStd("Trying to identify WebDav")
WEBDAVSCAN = "nmap -p %s --script http-webdav-scan %s -d 2>/dev/null | grep 'http-webdav-scan %s'" % (portString, target, target)
try:
webdavscanResults = subprocess.check_output(WEBDAVSCAN, shell=True)
# Write Results #
content = "%s" % printInBox(WEBDAVSCAN, webdavscanResults)
path = writeToFile(target, NAME, content)
printPlus("Finished scanning WebDav: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % WEBDAVSCAN)
except subprocess.CalledProcessError as ex:
if ex.returncode != 1:
raise Exception
except Exception:
printErr("Unable to perform WebDav analysis:\n\t%s" % WEBDAVSCAN)
# Conduct Brute #
for port in ports:
urlArr = []
urlDir = ["/"]
port = port.split("/")[0]
printStd("Trying to brute-force HTTPS directories on port %s" % port)
DIRB = "dirb https://%s:%s /usr/share/wordlists/dirb/common.txt -S -r" % (target, port)
try:
dirbResults = subprocess.check_output(DIRB, shell=True)
# Parse Results for Spider #
urlArr = parse_ip(dirbResults)
urlDir = parse_ip_directories(dirbResults)
# Write Results #
content = "%s" % printInBox(DIRB, dirbResults)
path = writeToFile(target, NAME, content)
printPlus("Finished HTTPS brute-force against port %s: %s - Found: %s" % (port, path, len(urlArr)))
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % DIRB)
except Exception:
printErr("Unable to brute-force HTTPS on port %s:\n\t%s" % (port, DIRB))
# Conduct Spider #
SCRIPTS = "http-auth-finder,http-backup-finder,http-comments-displayer,http-config-backup,http-default-accounts,http-dombased-xss,http-errors,http-fileupload-exploiter,http-method-tamper,http-passwd,http-phpmyadmin-dir-traversal,http-phpself-xss,http-rfi-spider,http-sitemap-generator,http-sql-injection,http-stored-xss,http-unsafe-output-escaping"
# Spidered Vulnerability Scans
for url in urlDir:
# Nikto Scan #
NIKTO = "nikto -host https://%s:%s -root %s -ssl" % (target, port, urlparse.urlparse(url).path)
try:
printStd("Crawling %s for vulnerabilities (nikto)" % url)
niktoResults = subprocess.check_output(NIKTO, shell=True)
# ...sometimes this doesn't work...?
if "0 host(s) tested" in niktoResults:
niktoResults = subprocess.check_output(NIKTO, shell=True)
if "0 host(s) tested" in niktoResults:
raise Exception
# Write Results #
content = "%s" % printInBox(NIKTO, niktoResults)
path = writeToFile(target, NAME, content)
printPlus("Finished crawling %s for vulnerabilities (nikto): %s" % (url, path))
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % NIKTO)
except Exception:
printErr("Unable to conduct HTTPS vulnerability crawl (nikto):\n\t%s" % NIKTO)
# Nmap Scan #
SCRIPTARGS = "http-backup-finder.url=%(url)s,http-config-backup.path=%(url)s,http-default-accounts.category=web,http-default-accounts.basepath=%(url)s,httpspider.url=%(url)s,http-method-tamper.uri=%(url)s,http-passwd.root=%(url)s,http-phpmyadmin-dir-traversal.dir=%(url)s,http-phpself-xss.uri=%(url)s,http-rfi-spider.url=%(url)s,http-sitemap-generator.url=%(url)s,http-sql-injection.url=%(url)s,http-unsafe-output-escaping.url=%(url)s" % {"url":urlparse.urlparse(url).path}
VULNSCAN = "nmap -p %s %s --script=\"%s\" --script-args=\"%s\" 2>&1" % (port, target, SCRIPTS, SCRIPTARGS)
try:
printStd("Crawling %s for vulnerabilities (nmap)" % url)
vulnscanResults = subprocess.check_output(VULNSCAN, shell=True)
# Write Results #
content = "%s" % printInBox(VULNSCAN, vulnscanResults)
path = writeToFile(target, NAME, content)
printPlus("Finished crawling %s for vulnerabilities (nmap): %s" % (url, path))
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % VULNSCAN)
except Exception:
printErr("Unable to conduct HTTPS vulnerability crawl (nmap):\n\t%s" % VULNSCAN)
# ========================
# SNMP
# ========================
def snmp(target, ports):
printStd("Investigating SNMP")
NAME = "snmp"
# Conduct Scans #
portString = ""
for port in ports:
port = port.split("/")[0]
portString += "%s," % port
NMAPSCAN = "nmap -sU -p %s --script=\"snmp-*\" %s" % (portString, target)
ONESIXTYONE = "onesixtyone -c /usr/share/doc/onesixtyone/dict.txt %s 2>&1" % target
ADVICE = "If match community string, use :: snmpwalk -c <community string> -v1 %s :: to enumerate" % target
foundCount = 0
try:
nmapscanResults = subprocess.check_output(NMAPSCAN, shell=True)
# Write Results #
content = "%s" % printInBox(NMAPSCAN, nmapscanResults)
path = writeToFile(target, NAME, content)
onesixtyoneResults = subprocess.check_output(ONESIXTYONE, shell=True)
foundCount = len(onesixtyoneResults.split('\n')) - 1
# Write Results #
content = "%s" % printInBox(ONESIXTYONE, onesixtyoneResults)
path = writeToFile(target, NAME, content)
printPlus("Finished investigating SNMP: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % ONESIXTYONE)
except Exception:
printErr("Unable to conduct SNMP scan:\n\t%s" % ONESIXTYONE)
if foundCount > 1:
printStd("Mapping SNMP")
WALK = "for s in $(onesixtyone -c /usr/share/doc/onesixtyone/dict.txt %s | grep %s | cut -d ' ' -f 2 | sed -e 's/\[//g' -e 's/\]//g');do snmpwalk -c $s -v1 %s;done" % (target, target, target)
try:
walkResults = subprocess.check_output(WALK, shell=True)
# Write Results #
content = "%s" % printInBox(WALK, walkResults)
path = writeToFile(target, NAME, content)
printPlus("Finished mapping SNMP: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % WALK)
except Exception:
printErr("unable to map SNMP:\n\t%s" % WALK)
# ========================
# MS-SQL
# ========================
def ms_sql(target, ports):
printStd("Investigating MS-SQL")
NAME = "ms_sql"
# Conduct nmap Scan #
portString = ""
for port in ports:
port = port.split("/")[0]
portString += "%s," % port
NMAPSCAN = "nmap -p %s -sV -sC %s" % (portString, target)
try:
nmapscanResults = subprocess.check_output(NMAPSCAN, shell=True)
# Write Scan Results #
content = "%s" % printInBox(NMAPSCAN, nmapscanResults)
path = writeToFile(target, NAME, content)
printPlus("Finished scanning MS-SQL: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % NMAPSCAN)
except Exception:
printErr("Unable to conduct MS-SQL scan:\n\t%s" % NMAPSCAN)
# Conduct Brute #
printStd("Trying to brute-force MS-SQL")
BRUTE = "medusa -h %s -U /usr/share/wordlists/metasploit/default_users_for_services_unhash.txt -P /usr/share/wordlists/metasploit/default_pass_for_services_unhash.txt -M mssql -L -f 2>&1" % (target)
try:
bruteResults = subprocess.check_output(BRUTE, shell=True)
# Write Brute Results #
content = "%s" % printInBox(BRUTE, bruteResults)
path = writeToFile(target, NAME, content)
printPlus("Finished conducting MS-SQL brute-force: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % BRUTE)
except Exception:
printErr("Unable to conduct MS-SQL brute-force:\n\t%s" % BRUTE)
# ========================
# MySQL
# ========================
def mysql(target, ports):
printStd("Investigating MySQL")
NAME = "mysql"
# Conduct nmap Scan #
portString = ""
for port in ports:
port = port.split("/")[0]
portString += "%s," % port
NMAPSCAN = "nmap -p %s -sV -sC %s" % (portString, target)
try:
nmapscanResults = subprocess.check_output(NMAPSCAN, shell=True)
# Write Scan Results #
content = "%s" % printInBox(NMAPSCAN, nmapscanResults)
path = writeToFile(target, NAME, content)
printPlus("Finished scanning MySQL: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % NMAPSCAN)
except Exception:
printMinus("Unable to conduct MySQL scan:\n\t%s" % NMAPSCAN)
# Conduct Brute #
printStd("Trying to brute-force MySQL")
BRUTE = "medusa -h %s -U /usr/share/wordlists/metasploit/default_users_for_services_unhash.txt -P /usr/share/wordlists/metasploit/default_pass_for_services_unhash.txt -M mysql -L -f 2>&1" % (target)
try:
bruteResults = subprocess.check_output(BRUTE, shell=True)
# Write Brute Results #
content = "%s" % printInBox(BRUTE, bruteResults)
path = writeToFile(target, NAME, content)
printPlus("Finished conducting MySQL brute-force: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % BRUTE)
except Exception:
printErr("Unable to conudct MySQL brute-foce:\n\t%s" % BRUTE)
# ========================
# NFS
# ========================
def nfs(target, ports):
printStd("Investigating NFS")
NAME = "nfs"
# Conduct rpcinfo #
RPCINFO = "rpcinfo -s %s" % target
try:
rpcinfoResults = subprocess.check_output(RPCINFO, shell=True)
# Write Results #
content = "%s" % printInBox(RPCINFO, rpcinfoResults)
path = writeToFile(target, NAME, content)
printPlus("Finished scanning RPC processes: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % RPCINFO)
except Exception:
printErr("Unable to scan RPC processes:\n\t%s" % RPCINFO)
# Conduct showmount #
printStd("Capturing accessible NFS shares")
SHOWMOUNT = "showmount -e %s" % target
ADVICE = "Use :: mount -t ntf %s:[share] /mnt/%s -o nolock :: to mount share"
try:
showmountResults = subprocess.check_output(SHOWMOUNT, shell=True)
# Write Results #
content = "%s" % printInBox(SHOWMOUNT, "%s\n\n%s" % (showmountResults, ADVICE))
path = writeToFile(target, NAME, content)
printPlus("Captured accessible NFS shares: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % SHOWMOUNT)
except Exception:
printErr("Unable to capture accessible NFS shares:\n\t%s" % SHOWMOUNT)
# Conduct nmap Scan #
printStd("Exploring accessible NFS shares")
portString = ""
for port in ports:
port = port.split("/")[0]
portString += "%s," % port
NMAPSCAN = "nmap -p %s -sV -sC --script=\"nfs-showmount,nfs-ls\" %s" % (portString, target)
try:
nmapResults = subprocess.check_output(NMAPSCAN, shell=True)
# Write Results #
content = "%s" % printInBox(NMAPSCAN, nmapResults)
path = writeToFile(target, NAME, content)
printPlus("Finished investigating NFS: %s" % path)
except KeyboardInterrupt:
printMinus("Skipping:\n\t%s" % NMAPSCAN)
except Exception:
printErr("Unable to conduct NFS scan:\n\t%s" % NMAPSCAN)
# ========================
# ------------------------------------
# Main
# ------------------------------------
KNOWN_SERVICES = {
"ftp" : ftp,
"smtp" : smtp,
"pop3" : pop3,
"imap" : imap,
"netbios-ssn" : smb,
"http" : http,
"http-alt" : http,
"http-proxy" : http,
"https" : https,
"snmp" : snmp,
"ms-sql-s" : ms_sql,
"mysql" : mysql,
"rpcbind" : nfs
}
def main(argv):
if len(sys.argv) != 2:
printUsage()
sys.exit(2)
TARGET = sys.argv[1]
if not validate_ip(TARGET):
printMinus("Invalid IP Address")
printUsage()
sys.exit(2)
printHeader(TARGET)
error = prepareFolder(TARGET)
if None != error:
printMinus("Portfolio for %s already exists at %s" % (TARGET, error))
printUsage()
sys.exit(2)
try:
SERVICES = conductLightNmap(TARGET)
dispatchModules(TARGET, SERVICES)
conductHeavyNmap(TARGET)
except KeyboardInterrupt:
print "\n\nExiting.\n"
sys.exit(1)
if __name__ == "__main__":
main(sys.argv[1:])