forked from Tylous/SniffAir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SniffAir.py
executable file
·600 lines (558 loc) · 22.8 KB
/
SniffAir.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
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
#!/usr/bin/python
import sys, os, os.path, signal, readline, time, threading, subprocess
sys.path.insert(0, 'module/')
sys.path.insert(0, 'lib/')
from Sniffer import *
from Connect2DB import *
from Queries import *
import Discover_Hidden_SSID
from Discover_Hidden_SSID import *
import SSID_stat
import export
class colors:
GRN = '\033[92m'
RD = '\033[91m'
NRM = '\033[0m'
class Spinner:
busy = False
delay = 0.1
@staticmethod
def spinning_cursor():
while 1:
for cursor in '|/-\\':
yield cursor
def __init__(self, delay=None):
self.spinner_generator = self.spinning_cursor()
if delay and float(delay): self.delay = delay
def spinner_task(self):
while self.busy:
sys.stdout.write(next(self.spinner_generator))
sys.stdout.flush()
time.sleep(self.delay)
sys.stdout.write('\b')
sys.stdout.flush()
def start(self):
self.busy = True
threading.Thread(target=self.spinner_task).start()
def stop(self):
sys.stdout.write('\b')
sys.stdout.flush()
self.busy = False
time.sleep(self.delay)
menu_actions = {}
name = "default"
module = ""
try:
workspace = ['workspace create', 'workspace delete', 'workspace list', 'workspace load']
show = ['show SSIDS', 'show AP_MAC', 'show Vendor', 'show Channel', 'show Client', 'show Encrpytion', 'show table', 'show inscope', 'show modules', 'show inscope']
table = ['show table AP', 'show table proberequests', 'show table proberesponses', 'show table EAP', 'show table hiddenssids', 'show table LOOT', 'show table inscope_AP', 'show table inscope_proberequests', 'show table inscope_proberesponses',]
modules = ['use Hidden SSID', 'use Evil Twin', 'use Captive Portal', 'use Auto EAP', 'use Exporter']
modset = ['set BSSID', 'set Channel', 'set Encryption', 'set SSID', 'set Interface', 'set WPA', 'set Key Management', 'set Password', 'set Username File', 'set Path']
def completer(text, state):
if text.startswith("workspace"):
workspace_list = [x for x in workspace if x.startswith(text)]
try:
return workspace_list[state]
except IndexError:
return None
if text.startswith("show table"):
table_list = [x for x in table if x.startswith(text)]
try:
return table_list[state]
except IndexError:
return None
elif text.startswith("show"):
show_list = [x for x in show if x.startswith(text)]
try:
return show_list[state]
except IndexError:
return None
if text.startswith("use"):
module_list = [x for x in modules if x.startswith(text)]
try:
return module_list[state]
except IndexError:
return None
if text.startswith("set"):
modset_list = [x for x in modset if x.startswith(text)]
try:
return modset_list[state]
except IndexError:
return None
else:
options = [x for x in menu_actions if x.startswith(text)]
try:
return options[state]
except IndexError:
return None
def choice():
global name
global module
try:
if module == "":
readline.set_completer(completer)
readline.set_completer_delims('')
if 'libedit' in readline.__doc__:
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind("tab: complete")
raw_choice = raw_input(" >> [" + name + "]# ")
choice = raw_choice
exec_menu(choice)
else:
readline.set_completer(completer)
readline.set_completer_delims('')
if 'libedit' in readline.__doc__:
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind("tab: complete")
raw_choice = raw_input(" >> [" + name + "][" + module + "]# ")
choice = raw_choice
exec_menu(choice)
except EOFError:
pass
except KeyboardInterrupt:
exec_menu('exit')
def main_menu():
name = ''
choice()
return
def exec_menu(choice):
global option
ch = choice
if ch == '':
menu_actions['main_menu']()
else:
ch1 = ch.split(' ')
cmd = ch1[0]
try:
if cmd not in menu_actions:
print colors.RD + "Invalid selection, please try again.\n" + colors.NRM
menu_actions['main_menu']()
else:
option = str(ch1[1:])[1:-1].replace('\'', '').replace(",","")
menu_actions[cmd]()
except KeyError:
print colors.RD + "Invalid selection, please try again.\n" + colors.NRM
menu_actions['main_menu']()
except IndexError:
option = ""
menu_actions[cmd]()
return
def db_check():
if name == "default":
print colors.RD + "Error: No workspace selected. Please create or load a workspace.\n"+ colors.NRM
menu_actions['main_menu']()
else:
return
def Workspace():
global name
global workspace
if option == "":
print " Manages workspaces"
print " Command Option: workspaces [create|list|load|delete]"
menu_actions['main_menu']()
else:
wso = option.split(' ')
if wso[0] == "create" and wso[1] == "":
print colors.RD + "Missing workspace name, please try again.\n" + colors.NRM
menu_actions['main_menu']()
if wso[0] == "create" and wso[1]:
workspace = "db/" + wso[1] + ".db"
Connect2DB.db_name(workspace)
name = wso[1]
Connect2DB.create_connection()
print colors.GRN + "[+]"+ colors.NRM +" Workspace %s created" % (wso[1])
if wso[0] == "load" and wso[1] == "":
print colors.RD + "Missing workspace name, please try again.\n" + colors.NRM
menu_actions['main_menu']()
if wso[0] == "load" and wso[1]:
workspace = "db/" + wso[1] + ".db"
Connect2DB.db_name(workspace)
name = wso[1]
Connect2DB.create_connection()
print colors.GRN + "[+]"+ colors.NRM +" Workspace %s loaded" % (wso[1])
d = queries()
d.db_connect(workspace)
IS = dp.read_sql('select * from INSCOPE_SSIDS', d.db_connect(workspace))
if IS.empty:
pass
else:
print colors.GRN + "[+] " + colors.NRM + "Inscope ESSIDs Observed"
print IS.ESSID.value_counts().to_string()
EO = dp.read_sql('select * from accessPoints', d.db_connect(workspace))
if EO.empty:
pass
else:
print colors.GRN + "[+] " + colors.NRM + "Top 5 ESSIDs Observed"
print EO.ESSID.value_counts().head(5).to_string()
print "\n"
menu_actions['main_menu']()
if wso[0] == "list":
Connect2DB.display_list()
if wso[0] == "delete":
if wso[1] == "":
print colors.RD + "Missing workspace name, please try again.\n" + colors.NRM
menu_actions['main_menu']()
else:
Connect2DB.delete_workspace(wso[1])
choice()
exec_menu(choice)
return
def Live_Capture():
db_check()
if option == "":
print colors.RD + "Error: No interface selected, please try again.\n" + colors.NRM
menu_actions['main_menu']()
else:
try:
global interface
global band
band = raw_input(" >> Do you want to sniff 2.4ghz, 5.5ghz or both?[2.4/5.5/both]# ")
interface = option
c = packet_sniffer()
c.live_capture(interface, band)
print colors.GRN + "[+] " + colors.NRM + "Cleaning Up Duplicates"
d = queries()
d.db_connect(workspace)
d.clean_up()
except socket.error:
print colors.RD + "Error: Non-existant interface, please try again.\n" + colors.NRM
choice()
exec_menu(choice)
return
def Offline_Capture_List():
db_check()
if option == "":
print colors.RD + "Error: Non-existant file, please try again.\n" + colors.NRM
menu_actions['main_menu']()
else:
try:
spinner = Spinner()
spinner.start()
d = queries()
d.db_connect(workspace)
filepath = option
listOfPcaps = open(filepath, 'r')
for x in listOfPcaps:
x = x
path = x.replace('\n','')
c = packet_sniffer()
c.file(path)
spinner.stop()
d.clean_up()
print colors.GRN + "[+] " + colors.NRM + "Cleaning Up Duplicates"
d = queries()
d.db_connect(workspace)
d.clean_up()
print colors.GRN + "[+] " + colors.NRM + "ESSIDs Observed"
EO = dp.read_sql('select * from accessPoints', d.db_connect(workspace))
print EO.ESSID.value_counts().to_string()
print "\n"
except IOError:
spinner.stop()
print colors.RD + "Error: Non-existant path, please try again.\n" + colors.NRM
choice()
exec_menu(choice)
return
def Offline_Capture():
db_check()
if option == "":
print colors.RD + "Error: Non-existant file, please try again.\n" + colors.NRM
menu_actions['main_menu']()
else:
try:
spinner = Spinner()
spinner.start()
path = option
c = packet_sniffer()
c.file(path)
spinner.stop()
print colors.GRN + "[+] " + colors.NRM + "Cleaning Up Duplicates"
d = queries()
d.db_connect(workspace)
d.clean_up()
print colors.GRN + "[+] " + colors.NRM + "ESSIDs Observed"
EO = dp.read_sql('select * from accessPoints', d.db_connect(workspace))
print EO.ESSID.value_counts().to_string()
print "\n"
choice()
exec_menu(choice)
return
except IOError:
spinner.stop()
print colors.RD + "Error: Non-existant path, please try again.\n" + colors.NRM
choice()
exec_menu(choice)
return
def SSID_Info():
db_check()
d = queries()
d.db_connect(workspace)
SSID_stat.main(workspace)
choice()
exec_menu(choice)
return
def Show():
db_check()
d = queries()
d.db_connect(workspace)
if option.startswith("table"):
rawr = option.split(' ')
d.show_table(rawr[1])
if option.startswith("inscope"):
result = d.show_inscope_ssids()
print (str(result))
if option.startswith("modules"):
print "Available Modules"
print "[+] Run Hidden SSID"
print "[+] Evil Twin"
print "[+] Captive Portal"
print "[+] Auto EAP"
print "[+] Exporter"
d.show(option)
choice()
exec_menu(choice)
return
def inscope():
db_check()
d = queries()
d.db_connect(workspace)
d.in_scope(option)
choice()
exec_menu(choice)
return
def Query():
db_check()
if option == "":
print colors.RD + "Error: Invalid query, please try again.\n" + colors.NRM
menu_actions['main_menu']()
else:
d = queries()
d.db_connect(workspace)
d.Custom_Queries(option)
choice()
exec_menu(choice)
return
def clear():
os.system('clear')
choice()
exec_menu(choice)
return
def Help():
print "Commands"
print "========"
print "workspace Manages workspaces (create, list, load, delete)"
print "live_capture Initiates a valid wireless interface to collect wireless pakcets to be parsed (requires the interface name)"
print "offline_capture Begins parsing wireless packets using a pcap file-kismet .pcapdump work best (requires the full path)"
print "offline_capture_list Begins parsing wireless packets using a list of pcap file-kismet .pcapdump work best (requires the full path)"
print "query Executes a query on the contents of the acitve workspace"
print "help Displays this help menu"
print "clear Clears the screen"
print "show Shows the contents of a table, specific information across all tables or the available modules"
print "inscope Add ESSID to scope. inscope [ESSID]"
print "SSID_Info Displays all information (i.e all BSSID, Channels and Encrpytion) related to the inscope SSIDS"
print "use Use a SniffAir module"
print "info Displays all variable information regarding the selected module"
print "set Sets a variable in module"
print "exploit Runs the loaded module"
print "run Runs the loaded module"
print "exit Exit SniffAir"
choice()
exec_menu(choice)
return
def exit():
print "\n"
print "Good Bye..."
sys.exit()
def info():
if module == "":
print colors.RD + "Error: No module selected, please select one.\n" + colors.NRM
else:
print "Globally Set Varibles"
print "====================="
try:
if (list1['Module']) in ["Evil Twin"]:
print " Module: "+(list1['Module'])
print " Interface: "+(list1['Interface'])
print " SSID: "+(list1['SSID'])
print " Channel: "+(list1['Channel'])
print " WPA Version: "+(list1['WPA'])
if (list1['Module']) in ["Captive Portal"]:
print " Module: "+(list1['Module'])
print " Interface: "+(list1['Interface'])
print " SSID: "+(list1['SSID'])
print " Channel: "+(list1['Channel'])
print " Template: Cisco (More to be added soon)"
if (list1['Module']) in ["Auto EAP"]:
print " Module: "+(list1['Module'])
print " Interface: "+(list1['Interface'])
print " SSID: "+(list1['SSID'])
print " Encryption: "+(list1['Encryption'])
print " Key Management: "+(list1['Key_Management'])
print " Password: "+(list1['Password'])
print " Username File: "+(list1['Username_File'])
if (list1['Module']) in ["Exporter"]:
print " Module: "+(list1['Module'])
print " Path: "+(list1['Path'])
except NameError:
pass
choice()
exec_menu(choice)
return
def use():
if option == "":
print colors.RD + "Missing Module name, please try again.\n" + colors.NRM
menu_actions['main_menu']()
else:
global module
global list1
list1 = {'Module': '','Interface': '','SSID': '','BSSID': '','Channel': '','Encryption': '','WPA': '','Key_Management': '','Password': '', 'Username_File': '', 'Path': ''}
if option in ["Evil Twin"]:
module = option
list1.update(Module = module)
elif option in ["Captive Portal"]:
module = option
list1.update(Module = module)
elif option in ["Auto EAP"]:
module = option
list1.update(Module = module)
elif option in ["Hidden SSID"]:
module = option
list1.update(Module = module)
Discover_Hidden_SSID.main(workspace)
elif option in ["Exporter"]:
module = option
list1.update(Module = module)
else:
print colors.RD + "Error: Non-existant module, please try again.\n" + colors.NRM
choice()
exec_menu(choice)
return
def set():
if module == "":
print colors.RD + "Missing Module name, please try again.\n" + colors.NRM
menu_actions['main_menu']()
else:
varibles = option.split(' ')
if varibles[0] == "":
print "Missing Varibles name, please try again.\n"
menu_actions['main_menu']()
try:
if varibles[0] in ["BSSID"]:
global bssid
list1.update(BSSID = varibles[1])
bssid = varibles[1]
if varibles[0] in ["Channel"]:
global channel
list1.update(Channel = varibles[1])
if varibles[0] in ["Encryption"]:
global encryption
list1.update(Encryption = varibles[1])
if varibles[0] in ["SSID"]:
global ssid
list1.update(SSID = varibles[1])
if varibles[0] in ["Interface"]:
global interface
interface = varibles[1]
list1.update(Interface = varibles[1])
if varibles[0] in ["WPA"]:
global wpa
list1.update(WPA = varibles[1])
if varibles[0]+' '+varibles[1] in ["Key Management"]:
global Key_MGT
list1.update(Key_Management = varibles[2])
if varibles[0] in ["Password"]:
global password
list1.update(Password = varibles[1])
if varibles[0]+' '+varibles[1] in ["Username File"]:
global Username_File
list1.update(Username_File = varibles[2])
if varibles[0] in ["Path"]:
global Path
list1.update(Path = varibles[1])
except NameError:
pass
choice()
exec_menu(choice)
return
def exploit():
if module == "":
print colors.RD + "No module selected, please try again.\n" + colors.NRM
menu_actions['main_menu']()
global p###?what isthis?
else:
try:
if module in ['Hidden SSID']:
d = queries()
d.db_connect(workspace)
Discover_Hidden_SSID.main(workspace)
if module in ['Exporter']:
d = queries()
d.db_connect(workspace)
export.main(workspace, list1['Path'], name)
if module in ['Evil Twin']:
if list1['SSID'] and list1['Channel'] and list1['Interface']:
args = ' -s '+ list1['SSID']+' -c '+ list1['Channel'] +' -a \'Evil Twin\' -w '+ list1['WPA']+' -i '+ list1['Interface']+' -d '+workspace+''
os.system('python module/hostapd.py'+args+'')
else:
print "Error: Invalid or Missing Arguements"
if module in ['Captive Portal']:
if list1['SSID'] and list1['Channel'] and list1['Interface']:
args = ' -s '+ list1['SSID']+' -c '+ list1['Channel'] +' -a \'Captive Portal\' -i '+ list1['Interface']+' -d '+workspace+''
os.system('python module/hostapd.py' +args+'')
else:
print "Error: Invalid or Missing Arguements"
if module in ['Auto EAP']:
if list1['SSID'] and list1['Key_Management'] and list1['Encryption'] and list1['Password'] and list1['Interface']:
if not list1['Username_File']:
args = ' -s '+ list1['SSID']+' -K '+ list1['Key_Management'] +' -E '+list1['Encryption'] +' -W '+workspace+' -p '+ list1['Password']+' -i '+ list1['Interface']
else:
args = ' -s '+ list1['SSID']+' -K '+ list1['Key_Management'] +' -E '+list1['Encryption'] +' -U '+list1['Username_File']+' -p '+ list1['Password']+' -i '+ list1['Interface']+' -W '+workspace+''
os.system('cd module/Auto_EAP/ && python Auto_EAP.py' +args+'&& cd ../../')
else:
print "Error: Invalid or Missing Arguements"
except KeyboardInterrupt:
pass
choice()
exec_menu(choice)
return
# =======================
# Menu Options
# =======================
menu_actions = {
'main_menu': main_menu,
'workspace': Workspace,
'offline_capture_list': Offline_Capture_List,
'live_capture': Live_Capture,
'offline_capture': Offline_Capture,
'help': Help,
'show' : Show,
'Query' : Query,
'SSID_Info' : SSID_Info,
'inscope' : inscope,
'query' : Query,
'set' : set,
'info' : info,
'clear' : clear,
'exploit' : exploit,
'run': exploit,
'use': use,
'exit': exit,
}
except Exception:
pass
def banner():
f = open('banner', 'r')
print f.read()
f.close()
if __name__ == "__main__":
banner()
print "\n"
if len(sys.argv) > 1:
ws = sys.argv[1]
if os.path.exists('db/' + ws + '.db'):
exec_menu('workspace load ' + ws)
else:
exec_menu('workspace create ' + ws)
main_menu()