-
Notifications
You must be signed in to change notification settings - Fork 322
/
zarp.py
executable file
·277 lines (256 loc) · 9.8 KB
/
zarp.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
#! /usr/bin/python
from os import getcwd, getuid, _exit
from os.path import exists
from sys import path, argv, exit, version, version_info
path.insert(0, getcwd() + '/src/')
path.insert(0, getcwd() + '/src/core/')
path.insert(0, getcwd() + '/src/modules/')
path.insert(0, getcwd() + '/src/lib/')
from subprocess import check_output
# module loading
from src.modules import poison, dos, scanner, services
from src.modules import sniffer, parameter, attacks
import config
import database
from colors import color
import platform
import util
try:
# load py2.7 stuff here so we can get to the depends check
import parse_cmd
import importlib
import session_manager
import stream
except:
pass
class LoadedModules:
""" Load modules
"""
def __init__(self):
self.total = 0
self.poison = []
self.dos = []
self.sniffers = []
self.services = []
self.scanner = []
self.parameter = []
self.attacks = []
def load(self):
""" Load modules. Verify the module loads successfully
before loading it up into the module list; this prevents
crashes related to unmet dependencies.
"""
for module in poison.__all__:
if util.check_dependency('src.modules.poison.%s' % module):
mod = getattr(importlib.import_module(
'src.modules.poison.%s' % module, 'poison'),
module)
self.poison.append(mod)
self.total += 1
for module in dos.__all__:
if util.check_dependency('src.modules.dos.%s' % module):
mod = getattr(importlib.import_module(
'src.modules.dos.%s' % module, 'dos'),
module)
self.dos.append(mod)
self.total += 1
for module in scanner.__all__:
if util.check_dependency('src.modules.scanner.%s' % module):
mod = getattr(importlib.import_module(
'src.modules.scanner.%s' % module, 'scanner'),
module)
self.scanner.append(mod)
self.total += 1
for module in services.__all__:
if util.check_dependency('src.modules.services.%s' % module):
mod = getattr(importlib.import_module(
'src.modules.services.%s' % module, 'services'),
module)
self.services.append(mod)
self.total += 1
for module in sniffer.__all__:
if util.check_dependency('src.modules.sniffer.%s' % module):
mod = getattr(importlib.import_module(
'src.modules.sniffer.%s' % module, 'sniffer'),
module)
self.sniffers.append(mod)
self.total += 1
for module in parameter.__all__:
if util.check_dependency('src.modules.parameter.%s' % module):
mod = getattr(importlib.import_module(
'src.modules.parameter.%s' % module, 'parameter'),
module)
self.parameter.append(mod)
self.total += 1
for module in attacks.__all__:
if util.check_dependency('src.modules.attacks.%s' % module):
mod = getattr(importlib.import_module(
'src.modules.attacks.%s' % module, 'attacks'),
module)
self.attacks.append(mod)
self.total += 1
def main():
""" Zarp entry point
"""
# set up configuration
config.initialize()
# set up database
database.initialize()
# load modules
loader = LoadedModules()
loader.load()
util.Msg('Loaded %d modules.' % loader.total)
# handle command line options first
if len(argv) > 1:
parse_cmd.parse(argv, loader)
# menus
main_menu = ['Poisoners', 'DoS Attacks', 'Sniffers', 'Scanners',
'Parameter', 'Services', 'Attacks', 'Sessions']
running = True
choice = -1
while running:
util.header()
choice = util.print_menu(main_menu)
if choice == 0:
# check if they've got running sessions!
cnt = stream.get_session_count()
if cnt > 0:
display = color.B_YELLOW + 'You have %d sessions running. ' + \
'Are you sure? ' + color.B_GREEN + '[' + color.B_YELLOW + \
'Y' + color.B_GREEN + '/' + color.B_YELLOW + 'n' + \
color.B_GREEN + '] ' + color.END
choice = raw_input(display % cnt)
if 'y' in choice.lower() or choice == '':
util.Msg('Shutting all sessions down...')
stream.stop_session('all', -1)
running = False
else:
util.debug("Exiting with session count: %d" % (cnt))
util.Msg("Exiting...")
running = False
# remove zarp temporary directory
util.init_app('rm -fr /tmp/.zarp/')
# recheck that all sessions are down
cnt = stream.get_session_count()
if cnt <= 0:
# some libs dont clean up their own threads, so
# we need to hard quit those to avoid hanging; FIXME
_exit(1)
elif choice == 1:
while True:
choice = util.print_menu([x().which for x in loader.poison])
if choice == 0:
break
elif choice == -1:
pass
elif choice > len(loader.poison):
continue
else:
stream.initialize(loader.poison[choice - 1])
elif choice == 2:
while True:
choice = util.print_menu([x().which for x in loader.dos])
if choice == 0:
break
elif choice == -1:
pass
elif choice > len(loader.dos):
continue
else:
stream.initialize(loader.dos[choice - 1])
elif choice == 3:
while True:
choice = util.print_menu([x().which for x in loader.sniffers])
if choice == 0:
break
elif choice == -1:
pass
elif choice > len(loader.sniffers):
continue
else:
stream.initialize(loader.sniffers[choice - 1])
elif choice == 4:
while True:
choice = util.print_menu([x().which for x in loader.scanner])
if choice == 0:
break
elif choice == -1:
pass
elif choice > len(loader.scanner):
continue
else:
stream.initialize(loader.scanner[choice - 1])
elif choice == 5:
while True:
choice = util.print_menu([x().which for x in loader.parameter])
if choice == 0:
break
elif choice == -1:
pass
elif choice > len(loader.parameter):
continue
else:
stream.initialize(loader.parameter[choice - 1])
elif choice == 6:
while True:
choice = util.print_menu([x().which for x in loader.services])
if choice == 0:
break
elif choice == -1:
pass
elif choice > len(loader.services):
continue
else:
stream.initialize(loader.services[choice - 1])
elif choice == 7:
while True:
choice = util.print_menu([x().which for x in loader.attacks])
if choice == 0:
break
elif choice == -1:
pass
elif choice > len(loader.attacks):
continue
else:
stream.initialize(loader.attacks[choice - 1])
elif choice == 8:
session_manager.menu()
elif choice == -1:
pass
# Application entry; dependency checks, etc.
if __name__ == "__main__":
# perm check
if int(getuid()) > 0:
util.Error('Please run as root.')
_exit(1)
# check python version
if version_info[1] < 7:
util.Error('zarp must be run with Python 2.7.x. You are currently using %s'
% version)
_exit(1)
# check for forwarding
system = platform.system().lower()
if system == 'darwin':
if not check_output('sysctl -n net.inet.ip.forwarding') == '1':
util.Msg('IPv4 forwarding disabled. Enabling..')
tmp = check_output(
'sudo sh -c \'sysctl -w net.inet.ip.forwarding=1\'')
if 'not permitted' in tmp:
util.Error('Error enabling IPv4 forwarding.')
exit(1)
elif system == 'linux':
if not check_output('cat /proc/sys/net/ipv4/ip_forward') == '1':
util.Msg('IPv4 forwarding disabled. Enabling..')
tmp = check_output(
'sudo sh -c \'echo "1" > /proc/sys/net/ipv4/ip_forward\'')
if len(tmp) > 0:
util.Error('Error enabling IPv4 forwarding.')
exit(1)
else:
util.Error('Unknown operating system. Cannot IPv4 forwarding.')
exit(1)
# create temporary directory for zarp to stash stuff
if exists("/tmp/.zarp"):
util.init_app("rm -fr /tmp/.zarp")
util.init_app("mkdir /tmp/.zarp")
main()