-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJaegerScript.py
More file actions
2413 lines (2344 loc) · 174 KB
/
JaegerScript.py
File metadata and controls
2413 lines (2344 loc) · 174 KB
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
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import subprocess, threading
import os,signal
from subprocess import Popen, PIPE
#This tool was made by Rafael Gil
#depasonico@gmail.com
#
#
#This is the main menu in this section we choose the kind of pentest to be deployed
#It is important use the new structure of Python 3
#
def main_menu ():
menu = {} #array for the menu
menu['1']="Internal Pentest" #list for Internal pentest
menu['2']="External Pentest" #list for external pentest
menu['3']="Version"
menu['4']="Exit" #option to break the cicle
while True: #with this boolean we keep the menu every time
print ('1', menu['1']) #printing the values in the array
print ('2', menu['2']) #do not use sort the result is different
print ('3', menu['3'])
print ('4', menu['4'])
selection=input("Please Select:") #new function for capturing data from keyboard
if selection =='1': # this function calls internal_pentest() the one for the internal part
internal_pentest()
elif selection == '2':
external_pentest()
elif selection == '3':
print ("Version 1.0")
elif selection == '4':
break
else:
print ("Unknown Option Selected!") #exception for any malformed input
# This function is in charge of deploying the internal part and menu
#this function is in different parts and call different other functions
#still in development adding new functions
#
def internal_pentest ():
menu = {} #same kind of menu that the main menu
menu['1']="Common Services"
menu['2']="Extended"
menu['3']="Collector"
menu['4']="Exit"
while True:
print ('1', menu['1'])
print ('2', menu['2'])
print ('3', menu['3'])
print ('4', menu['4'])
selection=input("Please Select:")
if selection =='1':
common_intenal_pentest() #this function is in charge of deploying the most common pentest in the most common ports
elif selection == '2':
extended_internal_pentest() #this function is in charge of deploying no common ports scan
elif selection == '3':
collector()
elif selection == '4':
break
else:
print ("Unknown Option Selected!")
def external_pentest():
menu = {} #same kind of menu that the main menu
menu['1']="Common External Pentest"
menu['2']="Advance External (3l33t)"
menu['3']="Collector"
menu['4']="Exit"
while True:
print ('1', menu['1'])
print ('2', menu['2'])
print ('3', menu['3'])
print ('4', menu['4'])
selection=input("Please Select:")
if selection =='1':
common_external() #this function is in charge of deploying the most common pentest in the most common ports
elif selection == '2':
print ("Under Contruction 2016") #this function is in charge of deploying no common ports scan
elif selection == '3':
collector()
elif selection == '4':
break
else:
print ("Unknown Option Selected!")
#This function is one of the biggest in this script
#it contains three parts
#1.- Discovery the segment to scan, after it generates a file with all the live IPs using PE in nmap
#2.- TCP scanning for the common ports
#3.- UDP scanning for the common ports
def common_intenal_pentest ():
import nmap #using python nmap library
import os #library to create directories and use other OS functions
import datetime
import time
print ('Provide the name of the company')
company = input ("Company: ")
print ('Provide the IP range to scan: \n IP: 192.168.1.1 \n Range: 192.168.1.1/24 \n Range: 192.168.1.1-254 \n Domain: google.com')
IP_segment = input("IP: ") #it can get range or single ip
host = str(IP_segment) #change the type
ts = time.time() #getting time
st = datetime.datetime.fromtimestamp(ts).strftime('_%Y_%m_%d_%H_%M') #human read
timestamp = str(st) #changinf the type
directory = company + timestamp #company and time of the scan
directory = str(directory) #change the type
f = open('/tmp/directory.txt', 'w') #create the file for directory
f.write('/root/pentest'+directory+'/discovery') #write the string
f.close()
os.mkdir('/root/pentest'+directory) #create the directory
os.mkdir('/root/pentest'+directory+'/discovery') #create the directory
os.mkdir ('/root/pentest'+directory+'/discovery/logs')
os.mkdir ('/root/pentest'+directory+'/discovery/collector')
pentest = nmap.PortScanner() #create a type scanner form nmap library
pentest.scan(hosts= host, arguments='-sn') #this function in the labrary calls nmap the usage is hosts, ports, arguments
f = open('/root/pentest'+directory+'/discovery/logs/logalive', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f.write('nmap hosts alive started = ' + timestamp+"\n\n")
hosts_list = [(x, pentest[x]['status']['state']) for x in pentest.all_hosts()]
#create the list for the live IPs
#the value x is echange for the value in the list in the library in all_hosts
#pentes.all_hosts() is a function to list all the hosts scanned
print ('-------------------- Live Host -----------------------------')
for host, status in hosts_list: #loop to check the status of all the hosts
if 'up' in status: #condintion to detect is the host is up
print('{0}:{1}'.format(host, status)) #print it
f = open('/root/pentest'+directory+'/discovery/LiveIPs.txt','a') #create the initial txt file of all the live IP
f.write('{0}'.format(host) + '\n') #it only prints the host
print ('-------------------- Live Host -----------------------------')#tag
f = open('/root/pentest'+directory+'/discovery/logs/logalive', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f.write('nmap hosts alive finished = ' + timestamp+"\n\n")
print ("""\n\n\n***********************************************************
Scanning for TCP ports in all the live Hosts
(Coffee Time)
*********************************************************\n\n\n
""")
pentest = nmap.PortScanner() #new type of scan
#This area could be improved later on
#The list of common ports
#Services, versions, SO, hostnames.
pentest.scan(arguments='-sV -vv -O -Pn --top-ports 50 --open -iL /root/pentest'+directory+'/discovery/LiveIPs.txt')
f = open('/root/pentest'+directory+'/discovery/logs/logscanning', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f.write('nmap scanning services started = ' + timestamp+"\n\n")
for host in pentest.all_hosts(): #loop to print and store the results by host and port
try:
print('-------------' + host +'---------------------------') #tag
Hostname = str(pentest[host].hostname()) #changinf the type of this value to string
print ('Hostname: '+Hostname) #printing
f = open('/root/pentest'+directory+'/discovery/Hostnames.csv','a') #create the file with the possible hostname
f.write(host + ',' + Hostname + '\n')
except KeyError as e:
print ("Something wrong with nmap \(No results for scripts\)")
pass
lport = pentest[host]['tcp'].keys() #new list with all the tcp ports in each host
for port in lport: #this section looks for each possible port in the list above
status = str(pentest[host]['tcp'][port]['state']) #store the state of each port in status list
if 'open' in status: #condition to detect open ports
print ('port : %s\tstate : %s' % (port, pentest[host]['tcp'][port]['state'])) #printing if it is open
host = str(host) #change the type
product = str(pentest[host]['tcp'][port]['product']) #this option allows to know the service
version = str(pentest[host]['tcp'][port]['version']) #this option allows to know the version
name = str(pentest[host]['tcp'][port]['name']) #this option allows to know more details for the service
OS = str(pentest[host]['tcp'][port]['cpe']) #if nmap can detect the OS this option will show it
Extra = str(pentest[host]['tcp'][port]['extrainfo']) #any extra information to fill the report
f = open('/root/pentest'+directory+'/discovery/OpenPorts.csv','a') #file containing all open porst by host
f.write(host + ',' + name + ',' + str(port) + ',' + status + ',' + product + ',' + ',' + version + ',' +'\n')
f = open('/root/pentest'+directory+'/discovery/DiscoverOS.csv','a') #file containing the possible OS if found
f.write(host + ',' + OS + ',' + Extra +'\n')
#This section extracts all the possible ports
#and generates the files for the next stage
#this dection can be improved later on
if '21' in str(port):
f = open('/root/pentest'+directory+'/discovery/FTP21.txt','a')
f.write('{0}'.format(host) + '\n')
if '22' in str(port):
f = open('/root/pentest'+directory+'/discovery/SSH22.txt','a')
f.write('{0}'.format(host) + '\n')
if '23' in str(port):
f = open('/root/pentest'+directory+'/discovery/TELNET23.txt','a')
f.write('{0}'.format(host) + '\n')
if '25' in str(port):
f = open('/root/pentest'+directory+'/discovery/SMTP25.txt','a')
f.write('{0}'.format(host) + '\n')
if '53' in str(port):
f = open('/root/pentest'+directory+'/discovery/DNS53.txt','a')
f.write('{0}'.format(host) + '\n')
if '80' in str(port):
f = open('/root/pentest'+directory+'/discovery/HTTP80.txt','a')
f.write('{0}'.format(host) + '\n')
if '139' in str(port):
f = open('/root/pentest'+directory+'/discovery/NETBIOS139.txt','a')
f.write('{0}'.format(host) + '\n')
if '443' in str(port):
f = open('/root/pentest'+directory+'/discovery/HTTPS443.txt','a')
f.write('{0}'.format(host) + '\n')
if '8080' in str(port):
f = open('/root/pentest'+directory+'/discovery/HTTP8080.txt','a')
f.write('{0}'.format(host) + '\n')
if '445' in str(port):
f = open('/root/pentest'+directory+'/discovery/SMB445.txt','a')
f.write('{0}'.format(host) + '\n')
if '513' in str(port):
f = open('/root/pentest'+directory+'/discovery/RLOGIN513.txt','a')
f.write('{0}'.format(host) + '\n')
if '514' in str(port):
f = open('/root/pentest'+directory+'/discovery/RSH514.txt','a')
f.write('{0}'.format(host) + '\n')
if '2048' in str(port):
f = open('/root/pentest'+directory+'/discovery/NFS2048.txt','a')
f.write('{0}'.format(host) + '\n')
if '2049' in str(port):
f = open('/root/pentest'+directory+'/discovery/NFS2049.txt','a')
f.write('{0}'.format(host) + '\n')
if '111' in str(port):
f = open('/root/pentest'+directory+'/discovery/NFS111.txt','a')
f.write('{0}'.format(host) + '\n')
if '1433' in str(port):
f = open('/root/pentest'+directory+'/discovery/MSSQL1433.txt','a')
f.write('{0}'.format(host) + '\n')
if '3306' in str(port):
f = open('/root/pentest'+directory+'/discovery/MYSQL3306.txt','a')
f.write('{0}'.format(host) + '\n')
if '1521' in str(port):
f = open('/root/pentest'+directory+'/discovery/ORACLE1521.txt','a')
f.write('{0}'.format(host) + '\n')
if '389' in str(port):
f = open('/root/pentest'+directory+'/discovery/LDAP389.txt','a')
f.write('{0}'.format(host) + '\n')
if '135' in str(port):
f = open('/root/pentest'+directory+'/discovery/MSRPC135.txt','a')
f.write('{0}'.format(host) + '\n')
if '6000' in str(port):
f = open('/root/pentest'+directory+'/discovery/X116000.txt','a')
f.write('{0}'.format(host) + '\n')
if '79' in str(port):
f = open('/root/pentest'+directory+'/discovery/FINGER79.txt','a')
f.write('{0}'.format(host) + '\n')
if '5900' in str(port):
f = open('/root/pentest'+directory+'/discovery/VNC5900.txt','a')
f.write('{0}'.format(host) + '\n')
if '5800' in str(port):
f = open('/root/pentest'+directory+'/discovery/VNC5800.txt','a')
f.write('{0}'.format(host) + '\n')
if '587' in str(port):
f = open('/root/pentest'+directory+'/discovery/MICRODS.txt','a')
f.write('{0}'.format(host) + '\n')
if '512' in str(port):
f = open('/root/pentest'+directory+'/discovery/EXEC512.txt','a')
f.write('{0}'.format(host) + '\n')
if '3268' in str(port):
f = open('/root/pentest'+directory+'/discovery/GC3268.txt','a')
f.write('{0}'.format(host) + '\n')
if '3269' in str(port):
f = open('/root/pentest'+directory+'/discovery/GCLSSL3269.txt','a')
f.write('{0}'.format(host) + '\n')
if '3389' in str(port):
f = open('/root/pentest'+directory+'/discovery/RDP3389.txt','a')
f.write('{0}'.format(host) + '\n')
if '50000' in str(port):
f = open('/root/pentest'+directory+'/discovery/DB2.txt','a')
f.write('{0}'.format(host) + '\n')
f = open('/root/pentest'+directory+'/discovery/logs/logalive', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f.write('nmap scanning services finished = ' + timestamp+"\n\n")
#new type of scane for UDP
#for UDP the arguments are different and the results
pentest = nmap.PortScanner()
pentest.scan(arguments='-d --max-retries 6 -sU -T5 -n -P0 --top-ports 50 -iL /root/pentest'+directory+'/discovery/LiveIPs.txt')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f.write('nmap scanning services UDP started = ' + timestamp+"\n\n")
print ('-------------Now UDP scan sit and pray-----------------') #tag
for host in pentest.all_hosts(): #loop to check all the hosts scanned
print('-------------' + host +'---------------------------') #tag
lport = pentest[host].all_udp() #list containing all udp ports scanned for each host
for port in lport: #checking port by poart
status = str(pentest[host]['udp'][port]['state']) #first obtaining the state of the service
if 'open' in status or 'open|filtered' in status: #conditional if to detect if it is open or filtered (for UDP both can be useful)
print ('port : %s\tstate : %s' % (port, pentest[host]['udp'][port]['state'])) #printing
host = str(host)# change type
#The same technique as in TCP
#Set variables for different information
product = str(pentest[host]['udp'][port]['product'])
version = str(pentest[host]['udp'][port]['version'])
name = str(pentest[host]['udp'][port]['name'])
OS = str(pentest[host]['udp'][port]['cpe'])
Extra = str(pentest[host]['udp'][port]['extrainfo'])
#Write the information in OpenPorts file
#But this new conditional is going to print only open ports in the file
if 'open' in status and not 'open|filtered' in status:
f = open('/root/pentest'+directory+'/discovery/OpenPorts.csv','a')
#Creates the CSV file with the information we need
f.write(host + ',' + name + ',' + str(port) + ',' + status + ',' + product + ',' + ',' + version + ',' +'\n')
#This section is the same as in TCP but for UDP ports
#Each file is for each service (here we store open and open|filter)
if '69' in str(port):
f = open('/root/pentest'+directory+'/discovery/TFTP69.txt','a')
f.write('{0}'.format(host) + '\n')
if '53' in str(port):
f = open('/root/pentest'+directory+'/discovery/DNS53.txt','a')
f.write('{0}'.format(host) + '\n')
if '161' in str(port):
f = open('/root/pentest'+directory+'/discovery/SNMP161.txt','a')
f.write('{0}'.format(host) + '\n')
if '123' in str(port):
f = open('/root/pentest'+directory+'/discovery/NTP123.txt','a')
f.write('{0}'.format(host) + '\n')
if '111' in str(port):
f = open('/root/pentest'+directory+'/discovery/RPCBIND111.txt','a')
f.write('{0}'.format(host) + '\n')
if '500' in str(port):
f = open('/root/pentest'+directory+'/discovery/IKE500.txt','a')
f.write('{0}'.format(host) + '\n')
if '2049' in str(port):
f = open('/root/pentest'+directory+'/discovery/NFS2049.txt','a')
f.write('{0}'.format(host) + '\n')
if '2048' in str(port):
f = open('/root/pentest'+directory+'/discovery/NFS2048.txt','a')
f.write('{0}'.format(host) + '\n')
if '1434' in str(port):
f = open('/root/pentest'+directory+'/discovery/MSSQLUDP1434.txt','a')
f.write('{0}'.format(host) + '\n')
if '137' in str(port):
f = open('/root/pentest'+directory+'/discovery/NETBIOSU137.txt','a')
f.write('{0}'.format(host) + '\n')
if '138' in str(port):
f = open('/root/pentest'+directory+'/discovery/NETBIOS138.txt','a')
f.write('{0}'.format(host) + '\n')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f.write('nmap scanning services UDP finished = ' + timestamp+"\n\n")
def common_external():
import nmap #using python nmap library
import os #library to create directories and use other OS functions
import datetime
import time
print ('Provide the name of the company')
company = input ("Company: ")
print ('Provide the list of IP range to scan: \n IP: 192.168.1.1 \n Range: 192.168.1.1/24 \n Range: 192.168.1.1-254 \n Domain: google.com')
IP_segment = input("File: ") #it can get range or single ip
hosts = str(IP_segment) #change the type
File = os.path.isfile(hosts)
if File == True:
ts = time.time() #getting time
st = datetime.datetime.fromtimestamp(ts).strftime('_%Y_%m_%d_%H_%M') #human read
timestamp = str(st) #changinf the type
directory = company + timestamp #company and time of the scan
directory = str(directory) #change the type
f = open('/tmp/directory.txt', 'w') #create the file for directory
f.write('/root/pentest'+directory+'/discovery') #write the string
f.close()
os.mkdir('/root/pentest'+directory) #create the directory
os.mkdir('/root/pentest'+directory+'/discovery') #create the directory
os.mkdir ('/root/pentest'+directory+'/discovery/logs')
os.mkdir ('/root/pentest'+directory+'/discovery/collector')
print ("""\n\n\n***********************************************************
Scanning for TCP ports in all the Hosts
(Coffee Time)
*********************************************************\n\n\n
""")
pentest = nmap.PortScanner() #new type of scan
#This area could be improved later on
#The list of common ports
#Services, versions, SO, hostnames.
pentest.scan(arguments='-sV -O -Pn --top-ports 50 --open -iL '+hosts)
f = open('/root/pentest'+directory+'/discovery/logs/logscanning', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f.write('nmap scanning services started = ' + timestamp+"\n\n")
for host in pentest.all_hosts(): #loop to print and store the results by host and port
print('-------------' + host +'---------------------------') #tag
Hostname = str(pentest[host].hostname()) #changinf the type of this value to string
print ('Hostname: '+Hostname) #printing
f = open('/root/pentest'+directory+'/discovery/Hostnames.csv','a') #create the file with the possible hostname
f.write(host + ',' + Hostname + '\n')
lport = pentest[host]['tcp'].keys() #new list with all the tcp ports in each host
for port in lport: #this section looks for each possible port in the list above
status = str(pentest[host]['tcp'][port]['state']) #store the state of each port in status list
if 'open' in status: #condition to detect open ports
print ('port : %s\tstate : %s' % (port, pentest[host]['tcp'][port]['state'])) #printing if it is open
host = str(host) #change the type
product = str(pentest[host]['tcp'][port]['product']) #this option allows to know the service
version = str(pentest[host]['tcp'][port]['version']) #this option allows to know the version
name = str(pentest[host]['tcp'][port]['name']) #this option allows to know more details for the service
OS = str(pentest[host]['tcp'][port]['cpe']) #if nmap can detect the OS this option will show it
Extra = str(pentest[host]['tcp'][port]['extrainfo']) #any extra information to fill the report
f = open('/root/pentest'+directory+'/discovery/OpenPorts.csv','a') #file containing all open porst by host
f.write(host + ',' + name + ',' + str(port) + ',' + status + ',' + product + ',' + ',' + version + ',' +'\n')
f = open('/root/pentest'+directory+'/discovery/DiscoverOS.csv','a') #file containing the possible OS if found
f.write(host + ',' + OS + ',' + Extra +'\n')
#This section extracts all the possible ports
#and generates the files for the next stage
#this dection can be improved later on
if '21' in str(port):
f = open('/root/pentest'+directory+'/discovery/FTP21.txt','a')
f.write('{0}'.format(host) + '\n')
if '22' in str(port):
f = open('/root/pentest'+directory+'/discovery/SSH22.txt','a')
f.write('{0}'.format(host) + '\n')
if '23' in str(port):
f = open('/root/pentest'+directory+'/discovery/TELNET23.txt','a')
f.write('{0}'.format(host) + '\n')
if '25' in str(port):
f = open('/root/pentest'+directory+'/discovery/SMTP25.txt','a')
f.write('{0}'.format(host) + '\n')
if '53' in str(port):
f = open('/root/pentest'+directory+'/discovery/DNS53.txt','a')
f.write('{0}'.format(host) + '\n')
if '80' in str(port):
f = open('/root/pentest'+directory+'/discovery/HTTP80.txt','a')
f.write('{0}'.format(host) + '\n')
if '139' in str(port):
f = open('/root/pentest'+directory+'/discovery/NETBIOS139.txt','a')
f.write('{0}'.format(host) + '\n')
if '443' in str(port):
f = open('/root/pentest'+directory+'/discovery/HTTPS443.txt','a')
f.write('{0}'.format(host) + '\n')
if '8080' in str(port):
f = open('/root/pentest'+directory+'/discovery/HTTP8080.txt','a')
f.write('{0}'.format(host) + '\n')
if '445' in str(port):
f = open('/root/pentest'+directory+'/discovery/SMB445.txt','a')
f.write('{0}'.format(host) + '\n')
if '513' in str(port):
f = open('/root/pentest'+directory+'/discovery/RLOGIN513.txt','a')
f.write('{0}'.format(host) + '\n')
if '514' in str(port):
f = open('/root/pentest'+directory+'/discovery/RSH514.txt','a')
f.write('{0}'.format(host) + '\n')
if '2048' in str(port):
f = open('/root/pentest'+directory+'/discovery/NFS2048.txt','a')
f.write('{0}'.format(host) + '\n')
if '2049' in str(port):
f = open('/root/pentest'+directory+'/discovery/NFS2049.txt','a')
f.write('{0}'.format(host) + '\n')
if '1433' in str(port):
f = open('/root/pentest'+directory+'/discovery/MSSQL1433.txt','a')
f.write('{0}'.format(host) + '\n')
if '3306' in str(port):
f = open('/root/pentest'+directory+'/discovery/MYSQL3306.txt','a')
f.write('{0}'.format(host) + '\n')
if '1521' in str(port):
f = open('/root/pentest'+directory+'/discovery/ORACLE1521.txt','a')
f.write('{0}'.format(host) + '\n')
if '389' in str(port):
f = open('/root/pentest'+directory+'/discovery/LDAP389.txt','a')
f.write('{0}'.format(host) + '\n')
if '135' in str(port):
f = open('/root/pentest'+directory+'/discovery/MSRPC135.txt','a')
f.write('{0}'.format(host) + '\n')
if '111' in str(port):
f = open('/root/pentest'+directory+'/discovery/RPCBIND111.txt','a')
f.write('{0}'.format(host) + '\n')
if '6000' in str(port):
f = open('/root/pentest'+directory+'/discovery/X116000.txt','a')
f.write('{0}'.format(host) + '\n')
if '79' in str(port):
f = open('/root/pentest'+directory+'/discovery/FINGER79.txt','a')
f.write('{0}'.format(host) + '\n')
if '5900' in str(port):
f = open('/root/pentest'+directory+'/discovery/VNC5900.txt','a')
f.write('{0}'.format(host) + '\n')
if '5800' in str(port):
f = open('/root/pentest'+directory+'/discovery/VNC5800.txt','a')
f.write('{0}'.format(host) + '\n')
if '587' in str(port):
f = open('/root/pentest'+directory+'/discovery/MICRODS.txt','a')
f.write('{0}'.format(host) + '\n')
if '512' in str(port):
f = open('/root/pentest'+directory+'/discovery/EXEC512.txt','a')
f.write('{0}'.format(host) + '\n')
if '3268' in str(port):
f = open('/root/pentest'+directory+'/discovery/GC3268.txt','a')
f.write('{0}'.format(host) + '\n')
if '3269' in str(port):
f = open('/root/pentest'+directory+'/discovery/GCLSSL3269.txt','a')
f.write('{0}'.format(host) + '\n')
if '3389' in str(port):
f = open('/root/pentest'+directory+'/discovery/RDP3389.txt','a')
f.write('{0}'.format(host) + '\n')
if '50000' in str(port):
f = open('/root/pentest'+directory+'/discovery/DB2.txt','a')
f.write('{0}'.format(host) + '\n')
f = open('/root/pentest'+directory+'/discovery/logs/logalive', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f.write('nmap scanning services finished = ' + timestamp+"\n\n")
#new type of scane for UDP
#for UDP the arguments are different and the results
pentest = nmap.PortScanner()
pentest.scan(arguments='-d --max-retries 6 -sU -T5 -n -P0 --top-ports 50 -iL '+hosts)
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f.write('nmap scanning services UDP started = ' + timestamp+"\n\n")
print ('-------------Now UDP scan sit and pray-----------------') #tag
for host in pentest.all_hosts(): #loop to check all the hosts scanned
print('-------------' + host +'---------------------------') #tag
lport = pentest[host].all_udp() #list containing all udp ports scanned for each host
for port in lport: #checking port by poart
status = str(pentest[host]['udp'][port]['state']) #first obtaining the state of the service
if 'open' in status or 'open|filtered' in status: #conditional if to detect if it is open or filtered (for UDP both can be useful)
print ('port : %s\tstate : %s' % (port, pentest[host]['udp'][port]['state'])) #printing
host = str(host)# change type
#The same technique as in TCP
#Set variables for different information
product = str(pentest[host]['udp'][port]['product'])
version = str(pentest[host]['udp'][port]['version'])
name = str(pentest[host]['udp'][port]['name'])
OS = str(pentest[host]['udp'][port]['cpe'])
Extra = str(pentest[host]['udp'][port]['extrainfo'])
#Write the information in OpenPorts file
#This will be addedd to the TCP information
if 'open' in status and not 'open|filtered' in status:
f = open('/root/pentest'+directory+'/discovery/OpenPorts.csv','a')
#Creates the CSV file with the information we need
f.write(host + ',' + name + ',' + str(port) + ',' + status + ',' + product + ',' + ',' + version + ',' +'\n')
#This section is the same as in TCP but for UDP ports
#Each file is for each service (here we store open and open|filter)
if '69' in str(port):
f = open('/root/pentest'+directory+'/discovery/TFTP69.txt','a')
f.write('{0}'.format(host) + '\n')
if '53' in str(port):
f = open('/root/pentest'+directory+'/discovery/DNS53.txt','a')
f.write('{0}'.format(host) + '\n')
if '161' in str(port):
f = open('/root/pentest'+directory+'/discovery/SNMP161.txt','a')
f.write('{0}'.format(host) + '\n')
if '123' in str(port):
f = open('/root/pentest'+directory+'/discovery/NTP123.txt','a')
f.write('{0}'.format(host) + '\n')
if '111' in str(port):
f = open('/root/pentest'+directory+'/discovery/RPCBIND111.txt','a')
f.write('{0}'.format(host) + '\n')
if '500' in str(port):
f = open('/root/pentest'+directory+'/discovery/IKE500.txt','a')
f.write('{0}'.format(host) + '\n')
if '2049' in str(port):
f = open('/root/pentest'+directory+'/discovery/NFS2049.txt','a')
f.write('{0}'.format(host) + '\n')
if '2048' in str(port):
f = open('/root/pentest'+directory+'/discovery/NFS2048.txt','a')
f.write('{0}'.format(host) + '\n')
if '1434' in str(port):
f = open('/root/pentest'+directory+'/discovery/MSSQLUDP1434.txt','a')
f.write('{0}'.format(host) + '\n')
if '137' in str(port):
f = open('/root/pentest'+directory+'/discovery/NETBIOSU137.txt','a')
f.write('{0}'.format(host) + '\n')
if '138' in str(port):
f = open('/root/pentest'+directory+'/discovery/NETBIOS138.txt','a')
f.write('{0}'.format(host) + '\n')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f.write('nmap scanning services UDP finished = ' + timestamp+"\n\n")
if File == False:
print("*******\n\nThe file does not exist or the path is wrong! \n\n********")
#This function look for no common ports in the network
#The base of this function is TCP and UDP like common but this scan looks for higher ports
def extended_internal_pentest ():
import datetime
import time
print ('This part of the script needs common pentest before execution')
print ('And the file LiveIPs.txt in /root/pentest/discovery (default)')
import nmap #using python nmap library
print ("""\n\n\n***********************************************************
Scanning for No-common TCP ports in all the live Hosts
(Malware could be found here, brace yourself!)
Alert: This scan takes so much time to complete
***********************************************************************\n\n\n
""")
pentest = nmap.PortScanner() #new type of scan
#This area could be improved later on
#The list of common ports
#Services, versions, SO, hostnames.
f = open('/tmp/directory.txt', 'r')
directory = f.read()
directory = str(directory)
pentest.scan(arguments='-sV -Pn -sC -p 1025-65535 -T4 --script auth-spoof,dns-zeustracker,ftp-proftpd-backdoor,ftp-vsftpd-backdoor,http-google-malware,http-malware-host,irc-unrealircd-backdoor,smtp-strangeport,irc-botnet-channels,qconn-exec -iL '+directory+'/LiveIPs.txt')
f = open(directory+'/logs/logscanning', 'a')
import datetime
import time
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f.write('nmap scanning extended services started = ' + timestamp +"\n\n")
try:
for host in pentest.all_hosts(): #loop to print and store the results by host and port
print('-------------' + host +'---------------------------') #tag
lport = pentest[host]['tcp'].keys() #new list with all the tcp ports in each host
for port in lport: #this section looks for each possible port in the list above
status = str(pentest[host]['tcp'][port]['state']) #store the state of each port in status list
if 'open' in status: #condition to detect open ports
print ('port : %s\tstate : %s' % (port, pentest[host]['tcp'][port]['state'])) #printing if it is open
host = str(host) #change the type
product = str(pentest[host]['tcp'][port]['product']) #this option allows to know the service
version = str(pentest[host]['tcp'][port]['version']) #this option allows to know the version
name = str(pentest[host]['tcp'][port]['name']) #this option allows to know more details for the service
script = str(pentest[host]['tcp'][port]['script']) #any extra information to fill the report
f = open(directory+'/OpenPortsNoCommon.csv','a') #file containing all open porst by host
f.write(host + ',' + name + ',' + str(port) + ',' + status + ',' + product + ',' + version + ',' + script +'\n')
except KeyError as e:
print ("Something wrong with nmap (No results for scripts)")
pass
print ("""\n\n\n\nThe process has finished please refer to
/root/pentest/discovery/OpenPortsNoCommon.csv
....................................\n\n\n\n
""")
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f.write('nmap scanning extended services finished = ' + timestamp +"\n\n")
def collector():
print ("\n\n###############################################################\n\nWelcome to collector here is where you can select indivually or all at once\n\n###############################################################\n\n")
menu = {} #same kind of menu that the main menu
menu['1']="ALL"
menu['2']="HTTP"
menu['3']="SSL"
menu['4']="DNS"
menu['5']="SNMP"
menu['6']="SMB"
menu['7']="SMTP"
menu['8']="RDP"
menu['9']="LDAP"
menu['10']="VNC"
menu['11']="CISCO"
menu['12']="ORACLE"
menu['13']="MSSQL"
menu['14']="IKE"
menu['15']="FTP"
menu['16']="SSH"
menu['17']="Exit"
while True:
print ('1', menu['1'])
print ('2', menu['2'])
print ('3', menu['3'])
print ('4', menu['4'])
print ('5', menu['5'])
print ('6', menu['6'])
print ('7', menu['7'])
print ('8', menu['8'])
print ('9', menu['9'])
print ('10', menu['10'])
print ('11', menu['11'], '***Cisco Collector is only for Internal Pentest***')
print ('12', menu['12'])
print ('13', menu['13'])
print ('14', menu['14'])
print ('15', menu['15'])
print ('16', menu['16'])
print ('17', menu['17'])
selection=input("Please Select:")
if selection =='1':
Check_All()
elif selection == '2':
Check_HTTP()
elif selection == '3':
Check_SSL()
elif selection == '4':
Check_DNS()
elif selection == '5':
Check_SNMP()
elif selection == '6':
Check_SMB()
elif selection == '7':
Check_SMTP()
elif selection == '8':
Check_RDP()
elif selection == '9':
Check_LDAP()
elif selection == '10':
Check_VNC()
elif selection == '11':
Check_Cisco()
elif selection == '12':
Check_Oracle()
elif selection == '13':
Check_MSSQL()
elif selection == '14':
Check_IKE()
elif selection == '15':
Check_FTP()
elif selection == '16':
Check_SSH()
elif selection == '17':
break
def Check_HTTP():
print ("""\n\n\nThis script needs the following tools to work:
bannergrab
Nikto
Hoppy
nmap scripts for HTTP
All of them should be in the system path\n\n\n""")
import os.path
import datetime
import time
#Importing libraries to control directories and time for logs
f = open('/tmp/directory.txt', 'r')
#Extracting the path used before ToDo: Improve this using memory
directory = f.read()
#Read the whole file (possible vulnerability)
directory = str(directory)
print("*************Looking for files in discovery folder**************")
time.sleep(5)
#Checking that the files exist
HttpFile = os.path.isfile(directory+"/HTTP80.txt")
HttpFile2 = os.path.isfile(directory+"/HTTP8080.txt")
if HttpFile != False:
#Check for the directory and creates it
if not os.path.exists(directory+"/collector/http"):
os.mkdir(directory+"/collector/http")
else:
f1 = open(directory+'/logs/logHTTP', 'a')
import datetime
import time
time.sleep(1)
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f1.write('HTTP Collector Started = ' + timestamp +"\n\n")
f2 = open(directory+"/HTTP80.txt", "r")
print ("Executing bannergrab on 80 and 8080")
f1 = open(directory+'/logs/logHTTP', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f1.write('Bannergrab Collector Started = ' + timestamp +"\n\n")
for line in f2:
try:
line = line.rstrip('\n')
from subprocess import Popen, PIPE
f = open(directory+'/collector/http/HTTPCollector.txt','a') #file containing all open porst by host
f.write("\nBannergrab Version 3.5\n")
cmd = "bannergrab --no-hex " + line +" 80"+" >> "+directory+"/collector/http/HTTPCollector.txt"
print (cmd)
p = Popen(cmd , shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
f.write("\n\n\n#########################################################\n")
except:
pass
if HttpFile2 != False:
if not os.path.exists(directory+"/collector/http"):
os.mkdir(directory+"/collector/http")
else:
f1 = open(directory+'/logs/logHTTP', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f1.write('Bannergrab Collector Started port 8080 = ' + timestamp +"\n\n")
f2 = open(directory+"/HTTP8080.txt", "r")
for line in f2:
try:
line = line.rstrip('\n')
from subprocess import Popen, PIPE
f = open(directory+'/collector/http/HTTPCollector.txt','a') #file containing all open porst by host
f.write("\nBannergrab Version 3.5\n")
cmd = "bannergrab --no-hex " + line +" 8080"+" >> "+directory+"/collector/http/HTTPCollector.txt"
print (cmd)
p = Popen(cmd , shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
f.write("\n\n\n#########################################################\n")
except:
pass
f1 = open(directory+'/logs/logHTTP', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f1.write('Bannergrab Collector Finished = ' + timestamp +"\n\n")
if HttpFile != False:
if not os.path.exists(directory+"/collector/http"):
os.mkdir(directory+"/collector/http")
else:
print ("""Executing Nikto on 80 and 8080 """)
f1 = open(directory+'/logs/logHTTP', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f1.write('Nikto Collector Started Port 80 = ' + timestamp +"\n\n")
f2 = open(directory+"/HTTP80.txt", "r")
for line in f2:
line = line.rstrip('\n')
from subprocess import Popen, PIPE
cmd = "nikto -host " + "http://"+line+" >> "+directory+"/collector/http/HTTPCollector.txt"
print (cmd)
command = Command(cmd)
command.run(timeout=600)
f = open(directory+'/collector/http/HTTPCollector.txt','a') #file containing all open porst by host
f.write("\n#########################################################\n")
f1 = open(directory+'/logs/logHTTP', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f1.write('Nikto Collector Finished Port 80 = ' + timestamp +"\n\n")
f1.write('Nikto Collector Started Port 8080 = ' + timestamp +"\n\n")
if HttpFile2 != False:
if not os.path.exists(directory+"/collector/http"):
os.mkdir(directory+"/collector/http")
else:
f2 = open(directory+"/HTTP8080.txt", "r")
for line in f2:
line = line.rstrip('\n')
from subprocess import Popen, PIPE
cmd = "nikto -host " + "http://"+line+":8080"+" >> "+directory+"/collector/http/HTTPCollector.txt"
print (cmd)
command = Command(cmd)
command.run(timeout=600)
f2 = open(directory+'/collector/http/HTTPCollector.txt','a') #file containing all open porst by host
f2.write("\n#########################################################\n")
f2.write("\n\n"+ cmd + "\n"+ HttpoutTxt +"\n\n\n")
f1 = open(directory+'/logs/logHTTP', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f1.write('Nikto Collector Finished Port 8080 = ' + timestamp +"\n\n")
f1.write('Hoppy Collector Started Port 80 = ' + timestamp +"\n\n")
if HttpFile != False:
if not os.path.exists(directory+"/collector/http"):
os.mkdir(directory+"/collector/http")
else:
print ("""Executing Hoppy on 80 and 8080 """)
f1 = open(directory+"/HTTP80.txt", "r")
for line in f1:
line = line.rstrip('\n')
from subprocess import Popen, PIPE
f2 = open(directory+'/collector/http/HTTPCollector.txt','a') #file containing all open porst by host
f2.write("\n#########################################################\n")
cmd = "hoppy -h " + "http://"+line+" >> "+directory+"/collector/http/HTTPCollector.txt"
#cmd = "echo hi"
print (cmd)
command = Command(cmd)
command.run(timeout=600)
f1 = open(directory+'/logs/logHTTP', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f1.write('Hoppy Collector Finished Port 80 = ' + timestamp +"\n\n")
f1.write('Hoppy Collector Started Port 8080 = ' + timestamp +"\n\n")
if HttpFile2 != False:
if not os.path.exists(directory+"/collector/http"):
os.mkdir(directory+"/collector/http")
else:
f1 = open(directory+"/HTTP8080.txt", "r")
for line in f1:
line = line.rstrip('\n')
from subprocess import Popen, PIPE
f2 = open(directory+'/collector/http/HTTPCollector.txt','a') #file containing all open porst by host
f2.write("\n#########################################################\n")
cmd = "hoppy -h " + "http://"+line+":8080"+" >> "+directory+"/collector/http/HTTPCollector.txt"
print (cmd)
command = Command(cmd)
command.run(timeout=600)
f1 = open(directory+'/logs/logHTTP', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f1.write('Hoppy Collector Finished Port 8080 = ' + timestamp +"\n\n")
f1.write('Nmap Collector Started Port 80 = ' + timestamp +"\n\n")
if HttpFile != False:
if not os.path.exists(directory+"/collector/http"):
os.mkdir(directory+"/collector/http")
else:
f = open(directory+'/collector/http/HTTPCollector.txt','a') #file containing all open porst by host
f.write("\n#########################################################\n")
print ("***********Executing all nmap scripts in HTTP ports 80 and 8080********")
import nmap
pentest = nmap.PortScanner() #new type of scan
pentest.scan(arguments='-sV -sC -Pn -p 80 -T5 --script http-adobe-coldfusion-apsa1301,http-affiliate-id,http-auth-finder,http-axis2-dir-traversal,http-cisco-anyconnect,http-config-backup,http-date,http-default-accounts,http-dlink-backdoor,http-drupal-enum-users,http-exif-spider,http-frontpage-login,http-headers,http-huawei-hg5xx-vuln,http-iis-short-name-brute,http-iis-webdav-vuln,http-majordomo2-dir-traversal,http-malware-host,http-method-tamper,http-methods,http-mobileversion-checker,http-php-version,http-phpmyadmin-dir-traversal,http-qnap-nas-info,http-referer-checker,http-robtex-reverse-ip,http-robtex-shared-ns,http-slowloris-check,http-tplink-dir-traversal,http-useragent-tester,http-userdir-enum,http-vuln-cve2006-3392,http-vuln-cve2009-3960,http-vuln-cve2010-0738,http-vuln-cve2010-2861,http-vuln-cve2011-3368,http-vuln-cve2012-1823,http-vuln-cve2013-0156,http-vuln-cve2013-7091,http-vuln-cve2014-2127,http-vuln-wnr1000-creds --script=http-apache-negotiation --script-args http-apache-negotiation.root=/root/ --script http-auth --script-args http-auth.path=/login --script http-awstatstotals-exec.nse --script-args \'http-awstatstotals-exec.cmd=\"uname -a\", http-awstatstotals-exec.uri=/awstats/index.php\' --script http-barracuda-dir-traversal --script-args http-max-cache-size=5000000 --script http-coldfusion-subzero --script-args basepath=/cf/ --script=http-drupal-modules --script-args http-drupal-modules.root="/path/",http-drupal-modules.number=1000 --script http-litespeed-sourcecode-download --script-args http-litespeed-sourcecode-download.uri=/phpinfo.php --script http-ntlm-info --script-args http-ntlm-info.root=/root/ --script http-vuln-cve2011-3192.nse --script-args http-vuln-cve2011-3192.hostname=nmap.scanme.org -iL '+directory+'/HTTP80.txt')
try:
for host in pentest.all_hosts(): #loop to print and store the results by host and port
print('-------------' + host +'---------------------------') #tag
lport = pentest[host]['tcp'].keys() #new list with all the tcp ports in each host
for port in lport: #this section looks for each possible port in the list above
status = str(pentest[host]['tcp'][port]['state']) #store the state of each port in status list
if 'open' in status: #condition to detect open ports
print ('checking on '+ host + ' Port 80') #printing if it is open
host = str(host) #change the type
product = str(pentest[host]['tcp'][port]['product']) #this option allows to know the service
version = str(pentest[host]['tcp'][port]['version']) #this option allows to know the version
name = str(pentest[host]['tcp'][port]['name']) #this option allows to know more details for the service
script = str(pentest[host]['tcp'][port]['script']) #any extra information to fill the report
f = open(directory+'/collector/http/HTTPCollector.txt','a') #file containing all open porst by host
list_scripts = script.split(", \'")
f.write("\n#########################################################\n")
for line in list_scripts:
f.write(host + ' ' + str(port) + ' ' + product + ' ' + version + '\n\n\n' + line +'\n\n\n\n')
except KeyError as e:
print ("Something wrong with nmap \(No results for scripts\)")
pass
f1 = open(directory+'/logs/logHTTP', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f1.write('Nmap Collector Finished Port 80 = ' + timestamp +"\n\n")
f1.write('Nmap Collector Starteded Port 8080 = ' + timestamp +"\n\n")
if HttpFile2 != False:
if not os.path.exists(directory+"/collector/http"):
os.mkdir(directory+"/collector/http")
else:
pentest.scan(arguments='-sV -Pn -p 8080 -T4 --script http-adobe-coldfusion-apsa1301,http-affiliate-id,http-auth-finder,http-axis2-dir-traversal,http-cisco-anyconnect,http-config-backup,http-date,http-default-accounts,http-dlink-backdoor,http-drupal-enum-users,http-exif-spider,http-frontpage-login,http-headers,http-huawei-hg5xx-vuln,http-iis-short-name-brute,http-iis-webdav-vuln,http-majordomo2-dir-traversal,http-malware-host,http-method-tamper,http-methods,http-mobileversion-checker,http-php-version,http-phpmyadmin-dir-traversal,http-qnap-nas-info,http-referer-checker,http-robtex-reverse-ip,http-robtex-shared-ns,http-slowloris-check,http-tplink-dir-traversal,http-useragent-tester,http-userdir-enum,http-vuln-cve2006-3392,http-vuln-cve2009-3960,http-vuln-cve2010-0738,http-vuln-cve2010-2861,http-vuln-cve2011-3368,http-vuln-cve2012-1823,http-vuln-cve2013-0156,http-vuln-cve2013-7091,http-vuln-cve2014-2127,http-vuln-wnr1000-creds --script=http-apache-negotiation --script-args http-apache-negotiation.root=/root/ --script http-auth --script-args http-auth.path=/login --script http-awstatstotals-exec.nse --script-args \'http-awstatstotals-exec.cmd=\"uname -a\", http-awstatstotals-exec.uri=/awstats/index.php\' --script http-barracuda-dir-traversal --script-args http-max-cache-size=5000000 --script http-coldfusion-subzero --script-args basepath=/cf/ --script=http-drupal-modules --script-args http-drupal-modules.root="/path/",http-drupal-modules.number=1000 --script http-litespeed-sourcecode-download --script-args http-litespeed-sourcecode-download.uri=/phpinfo.php --script http-ntlm-info --script-args http-ntlm-info.root=/root/ --script http-vuln-cve2011-3192.nse --script-args http-vuln-cve2011-3192.hostname=nmap.scanme.org -iL '+directory+'/HTTP8080.txt')
try:
for host in pentest.all_hosts(): #loop to print and store the results by host and port
print('-------------' + host +'---------------------------') #tag
lport = pentest[host]['tcp'].keys() #new list with all the tcp ports in each host
for port in lport: #this section looks for each possible port in the list above
status = str(pentest[host]['tcp'][port]['state']) #store the state of each port in status list
if 'open' in status: #condition to detect open ports
print ('checking on '+ host + 'Port 8080') #printing if it is open
host = str(host) #change the type
product = str(pentest[host]['tcp'][port]['product']) #this option allows to know the service
version = str(pentest[host]['tcp'][port]['version']) #this option allows to know the version
name = str(pentest[host]['tcp'][port]['name']) #this option allows to know more details for the service
script = str(pentest[host]['tcp'][port]['script']) #any extra information to fill the report
f = open(directory+'/collector/http/HTTPCollector.txt','a') #file containing all open porst by host
list_scripts = script.split(", \'") #separator for each script output
f.write("\n#########################################################\n")
for line in list_scripts:
f.write('Nmap 6.47 '+host + ' ' + str(port) + ' ' + product + ' ' + version + '\n\n\n' + line +'\n\n\n\n') #printing each script in the file
except KeyError as e:
print ("Something wrong with nmap \(No results for scripts\)")
pass
f1 = open(directory+'/logs/logHTTP', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f1.write('Nmap Collector Finished Port 8080 = ' + timestamp +"\n\n")
print ("*******HTTP collector has finished please check the results in "+directory+"/collector/http/HTTPCollector.txt **********")
f1 = open(directory+'/logs/logHTTP', 'a')
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f1.write('HTTP Collector Finished = ' + timestamp +"\n\n")
def Check_SSL ():
import datetime
import time
import os.path
import nmap
print ("""\n\n\nThis script needs the following tools to work:
SSLscan
nmap scripts for HTTP
All of them should be in the system path\n\n\n""")
f = open('/tmp/directory.txt', 'r')
directory = f.read()
directory = str(directory)
f1 = open(directory+'/logs/logSSL', 'a')
time.sleep(5)
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f1.write('SSL Collector Started Port 443 = ' + timestamp +"\n\n")
print("*************Looking for files in discovery folder**************")
HttpFile = os.path.isfile(directory+"/HTTPS443.txt")
if HttpFile != False:
#Check for the directory and creates it
if not os.path.exists(directory+"/collector/https"):
os.mkdir(directory+"/collector/https")
else:
f1 = open(directory+'/logs/logSSL', 'a')
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
timestamp = str(st)
f1.write('SSLscan Collector Started Port 443 = ' + timestamp +"\n\n")
f = open(directory+"/HTTPS443.txt", "r")
print ("Executing SSLscan on 443")
for line in f:
line = line.rstrip('\n')
from subprocess import Popen, PIPE
cmd = "sslscan --show-certificate --show-client-cas --no-colour " + line +" >> "+directory+"/collector/https/HTTPSCollector.txt"
print (cmd)
command = Command(cmd)
command.run(timeout=6000)
f = open(directory+'/collector/https/HTTPSCollector.txt','a') #file containing all open porst by host