-
Notifications
You must be signed in to change notification settings - Fork 4
/
QuickMetasploit.py
executable file
·275 lines (246 loc) · 12 KB
/
QuickMetasploit.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
#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from collections import defaultdict
from ConfigParser import SafeConfigParser
import cmd
import subprocess
import sys
import time
import socket
import fcntl
import struct
import math
import random
import blessings
import string
import shlex
import re
term = blessings.Terminal() # terminal size
config = SafeConfigParser()
config.read('config.ini')
DEFAULT_MODULE = config.get('main', 'Module')
DEFAULT_PAYLOAD = config.get('main' , 'Payload')
DEFAULT_LPORT = config.get('main' , 'Lport')
COLOURS = [term.red_bold, term.blue_bold, term.green_bold, term.yellow_bold, term.magenta_bold]
def get_ip_address(ifname): # Gets ip from interface using sockets
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack(b'256s', ifname[:15])
)[20:24])
default_variables = frozenset('iface module defaultmodule defaultpayload defaultlport'.split())
module_variables = defaultdict(lambda : default_variables)
module_variables.update({module: default_variables | other_variables for module, other_variables in
{'exploit/multi/handler': {'payload', 'lhost', 'lport'},
'auxiliary/scanner/smb/smb_login': {'rhosts', 'rport'},
'auxiliary/scanner/rservices/rlogin_login': {'rhosts', 'rport', 'username', 'fromuser'},
'auxiliary/scanner/snmp/snmp_enum': {'rhosts', 'rport', 'snmpversion', 'community'}
}.items()})
short_module_names = {'smb_login': 'auxiliary/scanner/smb/smb_login',
'multi_handler': 'exploit/multi/handler',
'rlogin_login': 'auxiliary/scanner/rservices/rlogin_login',
'snmp_enum': 'auxiliary/scanner/snmp/snmp_enum'
}
class Handler(cmd.Cmd):
lport = DEFAULT_LPORT
payload = DEFAULT_PAYLOAD
lhost = ''
iface = b'eth0'
module = short_module_names[DEFAULT_MODULE]
rhosts = ''
rhost = ''
rport = ''
username = ''
fromuser = 'root'
community = 'public'
snmpversion = '1'
defaultlport = config.get('main', 'Lport')
defaultmodule = config.get('main', 'Module')
defaultpayload = config.get('main', 'Payload')
possible_modules = short_module_names.keys()
possible_snmpversion = ('1' ,'2c')
possible_community = ('public' , 'private' , 'admin' , 'CISCO' , 'system' , 'switch' , 'secret')
possible_usernames = ('foobar' , 'root' , 'admin' , 'sysadmin')
possible_payloads = ('windows/meterpreter/reverse_tcp' , 'linux/shell/revserse_tcp')
possible_iface = ('eth0', 'lo' , 'wlan0')
def __init__(self):
cmd.Cmd.__init__(self)
self.lhost = get_ip_address(self.iface)
self.variables = module_variables[self.module]
def do_nmap(self, arg):
"""Runs an nmap scan with Specified options and specified ip"""
result = subprocess.check_output(['nmap'] + shlex.split(arg))
print result
try:
if re.search('514/tcp', result):
print "RLOGIN is open!"
self.module = 'rlogin_login'
self.module = short_module_names[self.module]
self.variables = module_variables[self.module]
print "Setting Module to %s"%(self.module)
ip = re.search('Nmap scan report for (.+)' , result).group(1)
self.rhosts = ip
print "Setting Rhosts to %s"%(ip)
except ValueError:
print "RLOGIN isnt open!"
def do_set(self, line):
"""Use Tab To Show Variables You Can Set"""
print term.clear
try:
firstvalue, secondvalue = line.split()
if firstvalue == 'module':
module = secondvalue = short_module_names[secondvalue]
self.variables = module_variables[module]
elif firstvalue == 'iface':
iface = secondvalue
self.lhost = get_ip_address(iface)
setattr(self, firstvalue, secondvalue)
config.set('main' , 'Module' , self.defaultmodule)
config.set('main' , 'Payload' , self.defaultpayload)
config.set('main' , 'Lport' , self.defaultlport)
self.do_showoptions(None)
except KeyError:
width = term.width
print term.clear
self.do_showoptions(None)
print term.on_black + ""
print term.red_bold + "="*term.width
print term.blue + "You Typed An Incorrect Value!".center(width, ' ')
print term.red + "="*term.width +term.normal
except ValueError:
width = term.width
print term.clear
self.do_showoptions(None)
print term.on_black + ""
print term.red_bold + "="*term.width
print term.blue + "Please choose a option and a value to set!".center(width, ' ')
print term.red + "="*term.width +term.normal
def do_easteregg(self, line):
"""OOoooohhh Secret"""
print term.clear
easter = raw_input("Enter The Code: ")
counter = 0
while True:
if easter == "1337":
print " "*(49 - int(46*math.sin(counter))) + random.choice(COLOURS) + "**--CharlieDean--**--Dario--**--Alex--**"
print " "*(49 - int(-46*math.sin(counter))) + random.choice(COLOURS) + "**--CharlieDean--**--Dario--**--Alex--**"
time.sleep(0.01)
counter += 0.1
else:
print "Wrong Code!"
def do_listallpayloads(self, line):
"""Shows All The Avalible Payloads"""
print term.clear
subprocess.call(["msfcli", "multi/handler", "P"])
def do_exit(self, line):
"""Exits Program"""
sys.exit()
def complete_set(self, text, line, begidx, endidx):
cmdtokens = line.split(' ')[:-1]
if cmdtokens == ['set']:
return [v for v in self.variables if v.startswith(text)]
elif cmdtokens == ['set', 'module'] or cmdtokens ==['set', 'defaultmodule']:
return [m for m in self.possible_modules if m.startswith(text)]
elif cmdtokens == ['set', 'snmpversion']:
return [g for g in self.possible_snmpversion if g.startswith(text)]
elif cmdtokens == ['set', 'community']:
return [f for f in self.possible_community if f.startswith(text)]
elif cmdtokens == ['set', 'username'] or cmdtokens == ['set', 'fromuser']:
return [t for t in self.possible_usernames if t.startswith(text)]
elif cmdtokens == ['set', 'payload'] or cmdtokens == ['set', 'defaultpayload']:
return [e for e in self.possible_payloads if e.startswith(text)]
elif cmdtokens == ['set', 'iface']:
return [r for r in self.possible_iface if r.startswith(text)]
else:
return []
def do_showoptions(self, line):
"""Shows Options For Module"""
width = term.width
if self.module == "exploit/multi/handler":
print term.clear
print term.on_black + ""
print term.red_bold +"="*width
print term.blue + ("payload = %s"% (self.payload)).center(width, ' ')
print term.blue + ("lhost = %s"% (self.lhost)).center(width, ' ')
print term.blue + ("lport = %s"% (self.lport)).center(width, ' ')
print term.blue + ("module = %s"% (self.module)).center(width, ' ')
print term.red + "="*width +term.normal
elif self.module == "auxiliary/scanner/smb/smb_login":
print term.clear
print term.on_black + ""
print term.red_bold + "="*width
print term.blue + ("rhosts = %s"% (self.rhosts)).center(width, ' ')
print term.blue + ("rport = %s"% (self.rport)).center(width, ' ')
print term.blue + ("module = %s"% (self.module)).center(width, ' ')
print term.red + "="*width +term.normal
elif self.module == "auxiliary/scanner/rservices/rlogin_login":
print term.clear
print term.on_black + ""
print term.red_bold + "="*width
print term.blue + ("rhosts = %s"% (self.rhosts)).center(width, ' ')
print term.blue + ("rport = %s"% (self.rport)).center(width, ' ')
print term.blue + ("module = %s"% (self.module)).center(width, ' ')
print term.blue + ("username = %s"% (self.username)).center(width, ' ')
print term.blue + ("fromuser = %s"% (self.fromuser)).center(width, ' ')
print term.red + "="*width +term.normal
elif self.module == "auxiliary/scanner/snmp/snmp_enum":
print term.clear
print term.on_black + ""
print term.red_bold + "="*width
print term.blue + ("rhosts = %s"% (self.rhosts)).center(width, ' ')
print term.blue + ("rport = %s"% (self.rport)).center(width, ' ')
print term.blue + ("module = %s"% (self.module)).center(width, ' ')
print term.blue + ("community = %s"% (self.community)).center(width, ' ')
print term.blue + ("snmpversion = %s"% (self.snmpversion)).center(width, ' ')
print term.red + "="*width +term.normal
else:
print "The module (%s) isn't supported yet!" % self.module +term.normal
def do_run(self, line):
"""Runs The Module With Settings"""
if self.module == "exploit/multi/handler":
subprocess.call(["msfcli", self.module, "payload=%s" %self.payload, "lhost=%s" %self.lhost, "lport=%s" %self.lport, "E"])
elif self.module == "auxiliary/scanner/smb/smb_login":
subprocess.call(["msfcli", self.module, "rhosts=%s" %self.rhosts, "rport=%s" %self.rport, "E"])
elif self.module == "auxiliary/scanner/rservices/rlogin_login":
subprocess.call(["msfcli", self.module, "rhosts=%s" %self.rhosts, "rport=%s" %self.rport, "username=%s" %self.username, "fromuser=%s" %self.fromuser, "E"])
elif self.module == "auxiliary/scanner/snmp/snmp_enum":
subprocess.call(["msfcli", self.module, "rhosts=%s" %self.rhosts, "rport=%s" %self.rport, "community=%s" %self.community, "version=%s" %self.snmpversion, "E"])
else:
print "The module (%s) isn't supported yet!" % self.module
if __name__ == '__main__':
print term.clear
width = term.width
print term.on_black + ""
print term.red_bold + "="*width
print term.blue + ("––•–√\/––√\/––•––" + term.green + "QuickMetasploit" + term.blue + "––•–√\/––√\/––•––").center(width + 9, ' ')
print term.blue + "Type Help To List All Commands".center(width, ' ')
print term.blue + "Type Help (Command) For Specific Help".center(width, ' ')
print term.blue + "Local Ip Will Be Automaticaly Set".center(width, ' ')
print term.blue + "CTRL + C To Exit".center(width, ' ')
print term.blue + "Written By CharlieDean".center(width, ' ')
print term.red + "="*width
print term.green + ("Default Module is %s" %DEFAULT_MODULE).center(width, ' ')
print term.green + ("Default Payload is %s" %DEFAULT_PAYLOAD).center(width, ' ')
print term.green + ("Default Lport is %s" %DEFAULT_LPORT).center(width, ' ')
print term.red + "="*width +term.normal
while(True):
try:
prompt = Handler()
prompt.prompt = '(>>)'
prompt.cmdloop('')
except (KeyboardInterrupt, SystemExit):
while(True):
try:
time.sleep(0.05)
exit = raw_input (term.green_bold + "\n\nAre You Sure You Want To Quit? y/[n] (>>)" +term.normal)
if exit and exit.lower()[0] == "y":
print term.red + "Exiting...*e48e13207341b6bffb7fb1622282247b*"
with open('config.ini', 'w') as f:
config.write(f)
sys.exit()
else:
prompt.cmdloop('')
except KeyboardInterrupt:
pass