-
Notifications
You must be signed in to change notification settings - Fork 78
/
MetaSploitFrameWork.py
480 lines (349 loc) · 16.2 KB
/
MetaSploitFrameWork.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
# -*- encoding: utf-8 -*-
#class for connecting with MetaSploit and launch console commands
#metaexploit framwework
import msfrpc
class MetaSploitFrameWork:
def __init__(self, port, host, ip, user, password):
self.client = msfrpc.Msfrpc({'uri':'/msfrpc', 'port':port, 'host':host, 'ssl': True})
self.auth = self.client.login(user,password)
#Escaneo sincrono
self.nm = nmap.PortScanner()
if self.auth:
self.console = self.client.call('console.create')
self.ip = ip
def scanMetaSploitFrameWork(self):
print 'Scannning Port MetaExploitFrameWork....................'
# Check what time the scan started
t1 = datetime.now()
#scan port FTP,SSH,HTTP,SSL,MYSQL,VNC,POSTGRES,MONGODB
self.nm.scan(ip, arguments="-A -sV -p21,22,80,8080,443,5432,3306,27017,1241,9160,5900")
host = self.nm.all_hosts()[0]
print 'Host: ' + host
for port in self.nm[host]['tcp']:
print 'Port {0} --> {1}'.format(port,self.nm[host]['tcp'][port]['state'])
#mysql
if (port==3306) and self.nm[host]['tcp'][port]['state']=='open':
print 'Checking MYSQL scripts......'
self.metaSploitMYSQL()
#FTP
if (port==21) and self.nm[host]['tcp'][port]['state']=='open':
print 'Checking FTP scripts......'
self.metaSploitFTP()
#vnc
if (port==5900) and self.nm[host]['tcp'][port]['state']=='open':
print 'Checking VNC scripts......'
self.metaSploitVNC()
#postgres
if (port==5432) and self.nm[host]['tcp'][port]['state']=='open':
print 'Checking POSTGRES scripts......'
self.metaSploitPostGres()
#mongodb
if (port==27017) and self.nm[host]['tcp'][port]['state']=='open':
print 'Checking MONGODB scripts......'
self.metaSploitMongoDB()
#ssl
if (port==443) and self.nm[host]['tcp'][port]['state']=='open':
print 'Checking SSL scripts......'
self.metaSploitSSL()
#ssh
if (port==22) and self.nm[host]['tcp'][port]['state']=='open':
print 'Checking SSH scripts......'
self.metaSploitSSH()
#http
if (port==80 or port==8080) and self.nm[host]['tcp'][port]['state']=='open':
print 'Checking HTTP scripts......'
# Checking the time again
t2 = datetime.now()
# Calculates the difference of time, to see how long it took to run the script
total = t2 - t1
# Printing the information to screen
print 'Scanning Completed in: ', total
def processData(self, consoleId):
while True:
readedData = self.client.call('console.read',[consoleId])
print readedData['data']
if len(readedData['data']) > 1:
print readedData['data']
if readedData['busy'] == True:
time.sleep(1)
continue
break
#METASPLOIT SSL
def metaSploitSSL(self):
#auxiliary/gather/impersonate_ssl
cmdSSLimpersonate = """auxiliary/gather/impersonate_ssl
set RHOSTS """+ip
cmdSSLimpersonate = cmdSSLimpersonate +"""\nrun
"""
print cmdSSLimpersonate
print self.client.call('console.write',[self.console['id'],cmdSSLimpersonate])
self.processData(self.console['id'])
#auxiliary/scanner/http/ssl
cmdSSLhttp = """auxiliary/scanner/http/ssl
set RHOSTS """ + self.ip
cmdSSLhttp = cmdSSLhttp +"""\nrun
"""
print cmdSSLhttp
print self.client.call('console.write',[self.console['id'],cmdSSLhttp])
self.processData(self.console['id'])
#auxiliary/scanner/http/ssl_version
cmdSSLversion = """auxiliary/scanner/http/ssl_version
set RHOSTS """ + self.ip
cmdSSLversion = cmdSSLversion +"""\nrun
"""
print cmdSSLversion
print self.client.call('console.write',[self.console['id'],cmdSSLversion])
self.processData(self.console['id'])
#METASPLOIT SSH
def metaSploitSSH(self):
#auxiliary/scanner/ssh/cerberus_sftp_enumusers
cmdSSHenumUsers = """auxiliary/scanner/ssh/cerberus_sftp_enumusers
set RHOSTS """ + self.ip
cmdSSHenumUsers = cmdSSHenumUsers +"""\nrun
"""
print cmdSSHenumUsers
print self.client.call('console.write',[self.console['id'],cmdSSHenumUsers])
self.processData(self.console['id'])
#auxiliary/scanner/ssh/detect_kippo
cmdSSHkippo = """auxiliary/scanner/ssh/detect_kippo
set RHOSTS """ + self.ip
cmdSSHkippo = cmdSSHkippo +"""\nrun
"""
print cmdSSHkippo
print self.client.call('console.write',[self.console['id'],cmdSSHkippo])
self.processData(self.console['id'])
#auxiliary/scanner/ssh/ssh_enumusers
cmdSSHenumUsers = """auxiliary/scanner/ssh/ssh_enumusers
set RHOSTS """ + self.ip
cmdSSHenumUsers = cmdSSHenumUsers +"""\nrun
"""
print cmdSSHenumUsers
print self.client.call('console.write',[self.console['id'],cmdSSHenumUsers])
self.processData(self.console['id'])
#auxiliary/scanner/ssh/ssh_identify_pubkeys
cmdSShpubkeys = """auxiliary/scanner/ssh/ssh_identify_pubkeys
set RHOSTS """ + self.ip
cmdSShpubkeys = cmdSShpubkeys +"""\nrun
"""
print cmdSShpubkeys
print self.client.call('console.write',[self.console['id'],cmdSShpubkeys])
self.processData(self.console['id'])
#auxiliary/scanner/ssh/ssh_login
cmdSShLogin = """auxiliary/scanner/ssh/ssh_login
set RHOSTS """ + self.ip
cmdSShLogin = cmdSShLogin +"""\nrun
"""
print cmdSShLogin
print self.client.call('console.write',[self.console['id'],cmdSShLogin])
self.processData(self.console['id'])
#auxiliary/scanner/ssh/ssh_login_pubkey
cmdSShLoginPubKey = """auxiliary/scanner/ssh/ssh_login_pubkey
set RHOSTS """ + self.ip
cmdSShLoginPubKey = cmdSShLoginPubKey +"""\nrun
"""
print cmdSShLoginPubKey
print self.client.call('console.write',[self.console['id'],cmdSShLoginPubKey])
self.processData(self.console['id'])
#auxiliary/scanner/ssh/ssh_version
cmdSShVersion = """auxiliary/scanner/ssh/ssh_version
set RHOSTS """ + self.ip
cmdSShVersion = cmdSShVersion +"""\nrun
"""
print cmdSShVersion
print self.client.call('console.write',[self.console['id'],cmdSShVersion])
self.processData(self.console['id'])
#auxiliary/scanner/ssh/ssh_version
cmdSShVersion = """auxiliary/scanner/ssh/ssh_version
set RHOSTS """ + self.ip
cmdSShVersion = cmdSShVersion +"""\nrun
"""
print cmdSShVersion
print self.client.call('console.write',[self.console['id'],cmdSShVersion])
self.processData(self.console['id'])
#METASPLOIT mongodb
def metaSploitMongoDB(self):
#auxiliary/gather/mongodb_js_inject_collection_enum
cmdMongoDBEnum = """auxiliary/gather/mongodb_js_inject_collection_enum
set RHOSTS """ + self.ip
cmdMongoDBEnum = cmdMongoDBEnum +"""\nrun
"""
print cmdMongoDBEnum
print self.client.call('console.write',[self.console['id'],cmdMongoDBEnum])
self.processData(self.console['id'])
#auxiliary/gather/mongodb_js_inject_collection_enum
cmdMongoDBEnum = """auxiliary/gather/mongodb_js_inject_collection_enum
set RHOSTS """ + self.ip
cmdMongoDBEnum = cmdMongoDBEnum +"""\nrun
"""
print cmdMongoDBEnum
print self.client.call('console.write',[self.console['id'],cmdMongoDBEnum])
self.processData(self.console['id'])
#METASPLOIT FTP
def metaSploitFTP(self):
#auxiliary/scanner/ftp/anonymous
cmdFtpAnonymous="""use auxiliary/scanner/ftp/anonymous
set RHOSTS """ + self.ip
cmdFtpAnonymous = cmdFtpAnonymous +"""\nrun
"""
print cmdFtpAnonymous
print self.client.call('console.write',[self.console['id'],cmdFtpAnonymous])
self.processData(self.console['id'])
#use auxiliary/scanner/ftp/ftp_login
cmdFtpLogin="""use auxiliary/scanner/ftp/ftp_login
set RHOSTS """ + self.ip
cmdFtpLogin = cmdFtpLogin +"""\nrun
"""
print cmdFtpLogin
print self.client.call('console.write',[self.console['id'],cmdFtpLogin])
self.processData(self.console['id'])
#use auxiliary/scanner/ftp/ftp_version
cmdFtpVersion="""use auxiliary/scanner/ftp/ftp_version
set RHOSTS """+ self.ip
cmdFtpVersion = cmdFtpVersion +"""\nrun
"""
print cmdFtpVersion
print self.client.call('console.write',[self.console['id'],cmdFtpVersion])
self.processData(self.console['id'])
#use auxiliary/scanner/portscan/ftpbounce
cmdFtpScanner="""use auxiliary/scanner/portscan/ftpbounce
set RHOSTS """+ self.ip + """
set BOUNCEHOST """ + self.ip
cmdFtpScanner = cmdFtpScanner +"""\nrun
"""
print cmdFtpScanner
print self.client.call('console.write',[self.console['id'],cmdFtpScanner])
self.processData(self.console['id'])
#METASPLOIT MYSQL
def metaSploitMYSQL(self):
#use auxiliary/scanner/mysql/mysql_authbypass_hashdump
cmdMysqlAuth="""use auxiliary/scanner/mysql/mysql_authbypass_hashdump
set RHOSTS """+ self.ip
cmdMysqlAuth = cmdMysqlAuth +"""\nrun
"""
print cmdMysqlAuth
print self.client.call('console.write',[self.console['id'],cmdMysqlAuth])
self.processData(self.console['id'])
#use auxiliary/scanner/mysql/mysql_file_enum
cmdMysqlEnum="""auxiliary/scanner/mysql/mysql_file_enum
set RHOSTS """+ self.ip
cmdMysqlEnum = cmdMysqlEnum +"""\nrun
"""
print cmdMysqlEnum
print self.client.call('console.write',[self.console['id'],cmdMysqlEnum])
self.processData(self.console['id'])
#use auxiliary/scanner/mysql/mysql_login
cmdMysqlLogin="""auxiliary/scanner/mysql/mysql_login
set RHOSTS """ + self.ip
cmdMysqlLogin = cmdMysqlLogin +"""\nrun
"""
print cmdMysqlLogin
print self.client.call('console.write',[self.console['id'],cmdMysqlLogin])
self.processData(self.console['id'])
#use auxiliary/scanner/mysql/mysql_schemadump
cmdMysqlSchema="""auxiliary/scanner/mysql/mysql_schemadump
set RHOSTS """ + self.ip
cmdMysqlSchema = cmdMysqlSchema +"""\nrun
"""
print cmdMysqlSchema
print self.client.call('console.write',[self.console['id'],cmdMysqlSchema])
self.processData(self.console['id'])
#use auxiliary/scanner/mysql/mysql_version
cmdMysqlVersion="""auxiliary/scanner/mysql/mysql_version
set RHOSTS """ + self.ip
cmdMysqlVersion = cmdMysqlVersion +"""\nrun
"""
print cmdMysqlVersion
print self.client.call('console.write',[self.console['id'],cmdMysqlVersion])
self.processData(self.console['id'])
#use auxiliary/server/capture/mysql
cmdMysqlServerCapture="""auxiliary/server/capture/mysql
set RHOSTS """ + self.ip
cmdMysqlServerCapture = cmdMysqlServerCapture +"""\nrun
"""
print cmdMysqlServerCapture
print self.client.call('console.write',[self.console['id'],cmdMysqlServerCapture])
self.processData(self.console['id'])
#METASPLOIT POSTGRES
def metaSploitPostGres(self):
#use auxiliary/scanner/postgres/postgres_dbname_flag_injection
cmdPostgresDBName="""auxiliary/scanner/postgres/postgres_dbname_flag_injection
set RHOSTS """ + self.ip
cmdPostgresDBName = cmdPostgresDBName +"""\nrun
"""
print cmdPostgresDBName
print self.client.call('console.write',[self.console['id'],cmdPostgresDBName])
self.processData(self.console['id'])
#use auxiliary/scanner/postgres/postgres_hashdump
cmdPostgresHashDump="""auxiliary/scanner/postgres/postgres_hashdump
set RHOSTS """ + self.ip
cmdPostgresHashDump = cmdPostgresHashDump +"""\nrun
"""
print cmdPostgresHashDump
print self.client.call('console.write',[self.console['id'],cmdPostgresHashDump])
self.processData(self.console['id'])
#use auxiliary/scanner/postgres/postgres_login
cmdPostgresLogin="""auxiliary/scanner/postgres/postgres_login
set RHOSTS """ + self.ip
cmdPostgresLogin = cmdPostgresLogin +"""\nrun
"""
print cmdPostgresLogin
print self.client.call('console.write',[self.console['id'],cmdPostgresLogin])
self.processData(self.console['id'])
#use auxiliary/scanner/postgres/postgres_version
cmdPostgresVersion="""auxiliary/scanner/postgres/postgres_version
set RHOSTS """ + self.ip
cmdPostgresVersion = cmdPostgresVersion +"""\nrun
"""
print cmdPostgresVersion
print self.client.call('console.write',[self.console['id'],cmdPostgresVersion])
self.processData(self.console['id'])
#use auxiliary/scanner/postgres/postgres_schemadump
cmdPostgresSchema = """auxiliary/scanner/postgres/postgres_schemadump
set RHOSTS """ + self.ip
cmdPostgresSchema = cmdPostgresSchema +"""\nrun
"""
print cmdPostgresSchema
print self.client.call('console.write',[self.console['id'],cmdPostgresSchema])
self.processData(self.console['id'])
#use auxiliary/server/capture/postgresql
cmdPostgresServer = """auxiliary/server/capture/postgresql
set RHOSTS """ + self.ip
cmdPostgresServer = cmdPostgresSchema +"""\nrun
"""
print cmdPostgresServer
print self.client.call('console.write',[self.console['id'],cmdPostgresServer])
self.processData(self.console['id'])
#METASPLOIT VNC
def metaSploitVNC(self):
#auxiliary/scanner/vnc/vnc_login
cmdVNCLgoin = """auxiliary/scanner/vnc/vnc_login
set RHOSTS """ + self.ip
cmdVNCLgoin = cmdVNCLgoin +"""\nrun
"""
print cmdVNCLgoin
print self.client.call('console.write',[self.console['id'],cmdVNCLgoin])
self.processData(self.console['id'])
#auxiliary/scanner/vnc/vnc_none_auth
cmdVNCAuth = """auxiliary/scanner/vnc/vnc_none_auth
set RHOSTS """ + self.ip
cmdVNCAuth = cmdVNCAuth +"""\nrun
"""
print cmdVNCAuth
print self.client.call('console.write',[self.console['id'],cmdVNCAuth])
self.processData(self.console['id'])
#auxiliary/server/capture/vnc
cmdVNCServer = """auxiliary/server/capture/vnc
set RHOSTS """ + self.ip
cmdVNCServer = cmdVNCServer +"""\nrun
"""
print cmdVNCServer
print self.client.call('console.write',[self.console['id'],cmdVNCServer])
self.processData(self.console['id'])
#auxiliary/admin/vnc/realvnc_41_bypass
cmdVNCByPass = """auxiliary/admin/vnc/realvnc_41_bypass
set RHOSTS """+ self.ip
cmdVNCByPass = cmdVNCByPass +"""\nrun
"""
print cmdVNCByPass
print self.client.call('console.write',[self.console['id'],cmdVNCByPass])
self.processData(self.console['id'])