-
Notifications
You must be signed in to change notification settings - Fork 43
/
Interface.py
308 lines (245 loc) · 9.58 KB
/
Interface.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
# coding=utf-8
from cmd2 import Cmd
from binascii import hexlify, unhexlify
from FENRIR2 import *
import threading
class Interface(Cmd):
FENRIR = FENRIR()
FenrirThread = None
stop_event = None
promptBase = "FENRIR"
prompt = "\n\033[1m\033[31m" + promptBase + " >\033[0m "
intro = """\n\033[1m
,a8b
,,od8 8
d8' 8b
d8'ba aP'
o8' aP'
YaaaP' ba
\033[31mFENRIR\033[0m\033[1m Y8' 88
,8\" `P
,d8P' ba
ooood8888888P\"\"\"' P'
,od 8
,dP o88o o'
,dP 8 8
,d' oo 8 ,8
$ d$\"8 8 Y Y o 8
d d d8 od \"\"boooaaaaoob d\"\"8 8
$ 8 d ood'-I 8 b 8 '8 b
$ $ 8 8 d d8 `b d '8 b
$ $ 8 b Y d8 8 ,P '8 b
`$$ Yb b 8b 8b 8 8, '8 o,
`Y b 8o $$ d b b $o
8 '$ 8$,,$\" $ $o '$o$$
$o$$P\" $$o$
\033[0m"""
def __init__(self):
Cmd.__init__(self)
### TOOLBOX ###
def hexToStr(self, hexstr):
string = hexlify(hexstr).decode('ascii')
return string[:2] + ":" + string[2:4] + ":" + string[4:6] + ":" + string[6:8] + ":" + string[8:10] + ":" + string[-2:]
def strToHex(self, string):
hexes = string.split(":")
hexstr = ''.join(hexes).encode("ascii")
return unhexlify(hexstr)
def changeRunningState(self, state):
if state == True:
self.prompt = "\n\033[1m\033[32m" + self.promptBase + " >\033[0m "
self.FENRIR.isRunning = True
elif state == False:
self.prompt = "\n\033[1m\033[31m" + self.promptBase + " >\033[0m "
self.FENRIR.isRunning = False
def do_create_virtual_tap(self,s):
self.FENRIR.createTap()
def help_create_virtual_tap(self):
print("Creates the virtual tap for FENRIR core module")
def do_destroy_virtual_tap(self,s):
self.FENRIR.downTap()
def help_destroy_virtual_tap(self):
print("Deletes the virtual tap for FENRIR core module")
def do_show(self,argString):
args = argString.split()
if len(args) != 1:
print("*** Invalid number of arguments")
self.help_show()
else:
if args[0] == "tap" and self.FENRIR.tap != None:
print("tap :")
print("Address ===> " + self.FENRIR.tap.addr)
print("MAC ===> " + self.hexToStr(self.FENRIR.tap.hwaddr))
print("mtu ===> " + str(self.FENRIR.tap.mtu))
elif args[0] == "host_ip" and self.FENRIR.hostip != None:
print("host_ip ===> " + self.FENRIR.hostip)
elif args[0] == "host_mac" and self.FENRIR.hostmac != None:
print("host_mac ===> " + self.hexToStr(self.FENRIR.hostmac))
elif args[0] == "rules":
if self.FENRIR.FenrirFangs.ruleCount == 0:
print("No rule added (yet)")
else:
num = 0
for rule in self.FENRIR.FenrirFangs.userRules:
num += 1
print("Rule " + str(num) +" : \n\tport = " + str(rule.dst_port) + "\n\ttype = " + rule.type + "\n\tproto = " + rule.proto)
elif args[0] == "netIface":
print("netIface ===> " + self.FENRIR.switchIface)
elif args[0] == "hostIface":
print("hostIface ===> " + self.FENRIR.LhostIface)
elif args[0] == "all":
self.do_show("tap")
self.do_show("host_ip")
self.do_show("host_mac")
self.do_show("hostIface")
self.do_show("netIface")
self.do_show("rules")
def help_show(self):
print("USAGE : show <attribute>")
def complete_show(self, match, line, bindex, eindex):
COMPLETION_ARRAY = ('tap', 'host_ip', 'host_mac', 'rules', 'hostIface ', 'netIface ', 'all')
return [i for i in COMPLETION_ARRAY if i.startswith(match)]
def do_set(self, argString):
args = argString.split()
if len(args) != 2:
print("*** Invalid number of arguments")
self.help_set()
else:
if args[0] == "debug":
Cmd.do_set(self, argString)
elif args[0] == "host_mac":
attrValue = self.strToHex(args[1])
else:
attrValue = args[1]
if self.FENRIR.setAttribute(args[0], attrValue) == False:
print("*** Invalid argument")
self.help_set()
else:
print(args[0] + " ===> " + args[1])
def help_set(self):
print("USAGE : set <attribute> <value>")
print("Attributes = host_ip, host_mac, netIface, hostIface, verbosity <0-3>")
def complete_set(self, match, line, bindex, eindex):
COMPLETION_ARRAY = ('host_ip ', 'host_mac ', 'verbosity ', 'netIface ', 'hostIface ')
if bindex == 4:
return [i for i in COMPLETION_ARRAY if i.startswith(match)]
else:
return ('')
def do_stats(self,s):
if self.FENRIR.isRunning == True:
print("Packet(s) processed by FENRIR : " + str(self.FENRIR.pktsCount))
def do_add_reverse_rule(self, argString):
args = argString.split()
if len(args) != 3:
print("*** Invalid number of arguments")
self.help_add_rule()
else:
try:
args[0] = int(args[0])
except:
print("*** First agument must be a number")
self.help_add_rule()
TYPES_ARRAY = ('unique', 'multi')
if args[0] <= 65535 and args[0] > 0 and args[1] in TYPES_ARRAY:
self.FENRIR.FenrirFangs.addRule(args[0], args[2], args[1])
print("New rule added : \n\tport = " + str(args[0]) + "\n\ttype = " + args[1] + "\n\tproto = " + args[2])
else:
print("*** Invalid arguments")
self.help_add_rule()
def help_add_reverse_rule(self):
print("USAGE : add_reverse_rule <port> <type = unique> <proto = IP>")
print("Interface for adding port-specific rules to allow reverse connection to reach FENRIR. This is useful for reverse shell or for server-based exploits & fun (Responder)")
print("Types include : \n\tunique = rule is triggered once before being deleted (useful to get a reverse shell from one host) \n\tmulti = rule can be triggered multiple times (useful for MitM stuff)")
def complete_add_reverse_rule(self, match, line, bindex, eindex):
if bindex <= 16:
return (' ')
elif bindex > 16:
if line.count(' ') == 2:
COMPLETION_ARRAY = ('unique ', 'multi ')
return [i for i in COMPLETION_ARRAY if i.startswith(match)]
elif line.count(' ') >= 3:
return ('')
else:
return ('')
else:
return ('')
def do_autoconf(self,s):
print("Running initAutoconf...")
self.FENRIR.initAutoconf()
self.do_show('all')
def help_autoconf(self):
print("Runs the auto-configuration module")
def do_run(self,s):
if self.FENRIR.tap == None:
self.do_create_virtual_tap("")
if self.FENRIR.tap != None and self.FENRIR.hostip != '' and self.FENRIR.hostmac != '':
self.FENRIR.setAttribute("verbosity", 0)
self.changeRunningState(True)
self.stop_event = threading.Event()
self.FenrirThread = threading.Thread(target=self.FENRIR.initMANGLE, args=(self.stop_event,))
self.FenrirThread.daemon = True
self.FenrirThread.start()
# self.FENRIR.initMANGLE()
else:
print("*** FENRIR PANIC : Configuration problem")
self.help_run()
def help_run(self):
print("USAGE : run")
print("This will launch FENRIR core in a new thread and remove any verbosity !")
print("(Disclaimer : you must have run the auto-configuration module or given correct information manually before running this command ! You need at least host_ip, host_mac and a virtual tap created !)")
def do_run_debug(self,s):
if self.FENRIR.tap == None:
self.do_create_virtual_tap("")
if self.FENRIR.tap != None and self.FENRIR.hostip != '' and self.FENRIR.hostmac != '':
self.changeRunningState(True)
self.stop_event = threading.Event()
self.FENRIR.initMANGLE(self.stop_event)
else:
print("*** FENRIR PANIC : Configuration problem")
self.help_run_debug()
def help_run_debug(self):
print("USAGE : run_debug")
print("This will launch FENRIR core WITHOUT creating a new thread !")
print("(Disclaimer : you must have run the auto-configuration module or given correct information manually before running this command ! You need at least host_ip, host_mac and a virtual tap created !)")
def do_stop(self,s):
if self.FENRIR.isRunning == True:
self.stop_event.set()
self.FenrirThread.join()
self.changeRunningState(False)
print("Fenrir was stopped")
else:
print("Fenrir is not running at the moment...")
def help_stop(self):
print("Stops the FENRIR thread")
def do_cookie(self,s):
print("This cookie machine is brought to you by Valérian LEGRAND valerian.legrand@orange.com\n")
print("COOKIE COOKIE COOKIE")
print("COOKIE COOKIE COOKIE")
print("COOKIE COOKIE COOKIE")
print("COOKIE COOKIE COOKIE")
print("COOKIE COOKIE COOKIE")
def do_exit(self, s):
return True
def do_help(self,s):
if s == '' :
print("FENRIR Commands :")
print("\tcookie")
print("\tcreate_virtual_tap")
print("\tdestroy_virtual_tap")
print("\tadd_reverse_rule")
print("\trun")
print("\trun_debug")
print("\tset")
print("\tshell")
print("\tshortcuts")
print("\tautoconf")
print("\tstop")
print("\tquit")
print("\thelp")
else :
Cmd.do_help(self,s)
def complete_help(self, match, line, bindex, eindex):
COMPLETION_ARRAY = ('cookie', 'create_virtual_tap', 'destroy_virtual_tap', 'add_reverse_rule', 'run', 'run_debug', 'set', 'shell', 'shortcuts', 'autoconf', 'stop', 'quit', 'exit', 'help')
return [i for i in COMPLETION_ARRAY if i.startswith(match)]
if __name__ == '__main__':
app = Interface()
app.cmdloop()