1
1
#!/usr/bin/python
2
2
3
+ # currently no data logging fot BT devices
4
+
3
5
from logging .handlers import RotatingFileHandler
4
6
import argparse
5
7
import sys
10
12
conf .verb = 0
11
13
import datetime
12
14
import logging
15
+ import threading
13
16
import collections
14
17
from os import system , path , getuid , uname
15
18
@@ -87,6 +90,7 @@ def parse_args():
87
90
parser .add_argument ('-l' , '--location' , default = 'None' , help = "Location of survey" )
88
91
parser .add_argument ('-a' , '--access' , default = False , help = "Include AP's into the survey" )
89
92
parser .add_argument ('-b' , '--bt' , default = False , help = "Scans BT Devices too (will need a BT dongle)" )
93
+ parser .add_argument ('-q' , '--quiet' , default = False , help = "Quiet Mode (Stops all output to screen" )
90
94
91
95
return parser .parse_args ()
92
96
@@ -140,7 +144,8 @@ def PacketHandler(pkt):
140
144
try :
141
145
btscanning ()
142
146
except Exception , e :
143
- print 'Caught exception while running BT Sniffing' ,e
147
+ if not args .quiet :
148
+ print 'Caught exception while running BT Sniffing' ,e
144
149
145
150
def PrintPacketAP (pkt ):
146
151
global Numap , Currentloc
@@ -178,12 +183,14 @@ def PrintPacketAP(pkt):
178
183
if ssid_probe not in accessPoints and ssid_probe != "" :
179
184
accessPoints .append (ssid_probe )
180
185
macAP .append (mac )
181
- print W + '[' + R + 'AP' + W + ':' + C + manufacture + W + '/' + B + mac + W + '] [' + T + crypto + W + '] [' + G + 'SSID' + W + ': ' + O + ssid_probe .decode ("utf-8" ) + W + '] [' + P + 'RSSI' + W + ':' + T + rssival + W + ']'
186
+ if not args .quiet :
187
+ print W + '[' + R + 'AP' + W + ':' + C + manufacture + W + '/' + B + mac + W + '] [' + T + crypto + W + '] [' + G + 'SSID' + W + ': ' + O + ssid_probe .decode ("utf-8" ) + W + '] [' + P + 'RSSI' + W + ':' + T + rssival + W + ']'
182
188
Numap += 1
183
189
# if ssid is in clients but mac isnt seen before then print out and add the mac to the list
184
190
elif ssid_probe in accessPoints and mac not in macAP :
185
191
macAP .append (mac )
186
- print W + '[' + R + 'AP' + W + ':' + C + manufacture + W + '/' + B + mac + W + '] [' + T + crypto + W + '] [' + G + 'SSID' + W + ': ' + O + ssid_probe .decode ("utf-8" ) + W + '] [' + P + 'RSSI' + W + ':' + T + rssival + W + ']'
192
+ if not args .quiet :
193
+ print W + '[' + R + 'AP' + W + ':' + C + manufacture + W + '/' + B + mac + W + '] [' + T + crypto + W + '] [' + G + 'SSID' + W + ': ' + O + ssid_probe .decode ("utf-8" ) + W + '] [' + P + 'RSSI' + W + ':' + T + rssival + W + ']'
187
194
Numap += 1
188
195
189
196
logger .info (args .delimiter .join (fields ))
@@ -223,16 +230,19 @@ def PrintPacketClient(pkt):
223
230
if ssid_probe not in clients and ssid_probe != "" :
224
231
clients .append (ssid_probe )
225
232
macClient .append (mac )
226
- print W + '[' + R + 'Client' + W + ':' + C + manufacture + W + '/' + B + mac + W + '] [' + G + 'SSID' + W + ': ' + O + ssid_probe .decode ("utf-8" ) + W + '] [' + P + 'RSSI' + W + ':' + T + rssival + W + ']'
233
+ if not args .quiet :
234
+ print W + '[' + R + 'Client' + W + ':' + C + manufacture + W + '/' + B + mac + W + '] [' + G + 'SSID' + W + ': ' + O + ssid_probe .decode ("utf-8" ) + W + '] [' + P + 'RSSI' + W + ':' + T + rssival + W + ']'
227
235
# if ssid is in clients but mac isnt seen before then print out and add the mac to the list
228
236
elif ssid_probe in clients and mac not in macClient :
229
237
macClient .append (mac )
230
- print W + '[' + R + 'Client' + W + ':' + C + manufacture + W + '/' + B + mac + W + '] [' + G + 'SSID' + W + ': ' + O + ssid_probe .decode ("utf-8" ) + W + '] [' + P + 'RSSI' + W + ':' + T + rssival + W + ']'
238
+ if not args .quiet :
239
+ print W + '[' + R + 'Client' + W + ':' + C + manufacture + W + '/' + B + mac + W + '] [' + G + 'SSID' + W + ': ' + O + ssid_probe .decode ("utf-8" ) + W + '] [' + P + 'RSSI' + W + ':' + T + rssival + W + ']'
231
240
Numclients += 1
232
241
# if mac is not in the list and the probe has a broadcast (empty) then add mac to list
233
242
elif mac not in macClient and ssid_probe == "" :
234
243
macClient .append (mac )
235
- print W + '[' + R + 'Client' + W + ':' + C + manufacture + W + '/' + B + mac + W + '] [' + GR + '*New Client*' + W + '] [' + P + 'RSSI' + W + ':' + T + rssival + W + ']'
244
+ if not args .quiet :
245
+ print W + '[' + R + 'Client' + W + ':' + C + manufacture + W + '/' + B + mac + W + '] [' + GR + '*New Client*' + W + '] [' + P + 'RSSI' + W + ':' + T + rssival + W + ']'
236
246
Numclients += 1
237
247
238
248
logger .info (args .delimiter .join (fields ))
@@ -261,16 +271,19 @@ def getWirelessInterfacesList():
261
271
262
272
def startup_checks ():
263
273
if getuid () != 0 :
264
- print R + "User is not Root."
274
+ if not args .quiet :
275
+ print R + "User is not Root."
265
276
sys .exit ()
266
277
267
278
if uname ()[0 ].startswith ("Linux" ) and not "Darwin" not in uname ():
268
- print R + "Wrong OS."
279
+ if not args .quiet :
280
+ print R + "Wrong OS."
269
281
sys .exit ()
270
282
return ;
271
283
272
284
def logo ():
273
- print O + '''
285
+ if not args .quiet :
286
+ print O + '''
274
287
%s______ _
275
288
| ___ \ | |
276
289
| |_/ /__ __ _ _ __ _ _| |_ ___
@@ -284,22 +297,49 @@ def logo():
284
297
%sCode%s: stuart@sensepost.com // @NoobieDog
285
298
%sVisit%s: www.sensepost.com // @sensepost
286
299
''' % (B ,C ,R ,W ,R ,W ,R ,W ,R ,W )
287
- print '[' + G + '*' + W + '] Wifi and BT Probe Investigator'
288
- print '[' + G + '-----------------------------------------------------' + W + ']'
300
+ print '[' + G + '*' + W + '] Wifi and BT Probe Investigator'
301
+ print '[' + G + '-----------------------------------------------------' + W + ']'
289
302
290
303
def main (intf ):
291
304
try :
292
305
sniff (iface = intf , prn = PacketHandler , store = 0 )
293
306
except Exception , e :
294
- print 'Caught exception while running sniff()' ,e
307
+ if not args .quiet :
308
+ print 'Caught exception while running sniff()' ,e
295
309
296
310
def btscanning ():
311
+ ts = time .time ()
312
+ st = datetime .datetime .fromtimestamp (ts ).strftime ('%Y-%m-%d %H:%M' )
313
+
314
+ if args .gpstrack :
315
+ gpslat = str (gpsd .fix .latitude )
316
+ gpslong = str (gpsd .fix .longitude )
317
+ else :
318
+ gpslat = "nil"
319
+ gpslong = "nil"
320
+
321
+ # Logging info
322
+ fields = []
323
+ fields .append (st ) # Log Time
324
+ fields .append ('BT' ) # Log Client or AP
325
+ fields .append (addr ) # Log Mac Address
326
+ fields .append ('nil' ) # Log Device Manufacture
327
+ fields .append (name ) # Log BT Name
328
+ fields .append ('nil' ) # Log Crypto
329
+ fields .append (gpslat ) # Log GPS data
330
+ fields .append (gpslong ) # Log GPS data
331
+ fields .append (args .location ) # Log Location data
332
+ fields .append ('nil' ) # RSSI
333
+
297
334
devices = bluetooth .discover_devices (duration = 1 , lookup_names = True )
298
335
299
336
for addr , name in devices :
300
337
if addr not in btclients :
301
- print W + '[' + R + 'Bluetooth Client' + W + ':' + B + addr + W + '] [' + G + 'Name' + W + ': ' + O + name + W + ']'
302
- btclients .append (addr )
338
+ if not args .quiet :
339
+ print W + '[' + R + 'Bluetooth Client' + W + ':' + B + addr + W + '] [' + G + 'Name' + W + ': ' + O + name + W + ']'
340
+ btclients .append (addr )
341
+
342
+ logger .info (args .delimiter .join (fields ))
303
343
304
344
if __name__ == "__main__" :
305
345
args = parse_args ()
@@ -317,7 +357,8 @@ def btscanning():
317
357
intf = args .interface
318
358
319
359
if "mon" not in intf : # yes i know this doesnt work with ubuntu/mint at the mo...
320
- print '[' + G + '*' + W + '] Setting Wireless card into Monitor Mode'
360
+ if not args .quiet :
361
+ print '[' + G + '*' + W + '] Setting Wireless card into Monitor Mode'
321
362
if 'mon' not in getWirelessInterfacesList ():
322
363
#call(['airmon-ng', 'check', 'kill'], stdout=DN, stderr=DN)
323
364
cmd = ['airmon-ng' , 'start' ,intf ]
@@ -333,12 +374,14 @@ def btscanning():
333
374
try :
334
375
gpsp = GpsPoller () # create the thread
335
376
except Exception , e :
336
- print 'Caught exception while running GPS' ,e
377
+ if not args .quiet :
378
+ print 'Caught exception while running GPS' ,e
337
379
338
380
try :
339
381
gpsp .start () # start it up
340
382
except Exception , e :
341
- print 'Caught exception while running GPS' ,e
383
+ if not args .quiet :
384
+ print 'Caught exception while running GPS' ,e
342
385
gpsp .running = False
343
386
gpsp .join () # wait for the thread to finish what it's doing
344
387
sys .exit ()
@@ -350,17 +393,20 @@ def btscanning():
350
393
351
394
# Finish off with Tidy up of CSV.
352
395
353
- print '\n \033 [31m%d \033 [0mClients | \033 [33m%d \033 [0mAPs' % (Numclients , Numap )
396
+ if not args .quiet :
397
+ print '\n \033 [31m%d \033 [0mClients | \033 [33m%d \033 [0mAPs' % (Numclients , Numap )
354
398
355
399
outfile = args .output + '.csv'
356
400
357
- print G + '\n Creating CSV' + W + ': ' + outfile
401
+ if not args .quiet :
402
+ print G + '\n Creating CSV' + W + ': ' + outfile
358
403
try :
359
404
with open (args .output , 'rb' ) as inf , open (outfile , 'wb' ) as outf :
360
405
outf .writelines (collections .OrderedDict .fromkeys (inf ))
361
406
except Exception , e :
362
- print R + 'Caught exception while creating CSV File' ,e
407
+ if not args .quiet :
408
+ print R + 'Caught exception while creating CSV File' ,e
363
409
364
410
# Print Program Time
365
-
366
- print G + '\n Elapsed Time' + W + ': %s' % (time .time () - start )
411
+ if not args . quiet :
412
+ print G + '\n Elapsed Time' + W + ': %s' % (time .time () - start )
0 commit comments