Skip to content

Commit 823c9f1

Browse files
committed
small update with quiet mode and BT logging of data
1 parent d4190ca commit 823c9f1

File tree

2 files changed

+68
-22
lines changed

2 files changed

+68
-22
lines changed

manuf.pyc

-364 Bytes
Binary file not shown.

peanuts.py

+68-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/python
22

3+
# currently no data logging fot BT devices
4+
35
from logging.handlers import RotatingFileHandler
46
import argparse
57
import sys
@@ -10,6 +12,7 @@
1012
conf.verb = 0
1113
import datetime
1214
import logging
15+
import threading
1316
import collections
1417
from os import system, path, getuid, uname
1518

@@ -87,6 +90,7 @@ def parse_args():
8790
parser.add_argument('-l', '--location', default='None', help="Location of survey")
8891
parser.add_argument('-a', '--access', default=False, help="Include AP's into the survey")
8992
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")
9094

9195
return parser.parse_args()
9296

@@ -140,7 +144,8 @@ def PacketHandler(pkt):
140144
try:
141145
btscanning()
142146
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
144149

145150
def PrintPacketAP(pkt):
146151
global Numap, Currentloc
@@ -178,12 +183,14 @@ def PrintPacketAP(pkt):
178183
if ssid_probe not in accessPoints and ssid_probe != "":
179184
accessPoints.append(ssid_probe)
180185
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+ ']'
182188
Numap += 1
183189
# if ssid is in clients but mac isnt seen before then print out and add the mac to the list
184190
elif ssid_probe in accessPoints and mac not in macAP:
185191
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+ ']'
187194
Numap += 1
188195

189196
logger.info(args.delimiter.join(fields))
@@ -223,16 +230,19 @@ def PrintPacketClient(pkt):
223230
if ssid_probe not in clients and ssid_probe != "":
224231
clients.append(ssid_probe)
225232
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+ ']'
227235
# if ssid is in clients but mac isnt seen before then print out and add the mac to the list
228236
elif ssid_probe in clients and mac not in macClient:
229237
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+ ']'
231240
Numclients += 1
232241
# if mac is not in the list and the probe has a broadcast (empty) then add mac to list
233242
elif mac not in macClient and ssid_probe == "":
234243
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+ ']'
236246
Numclients += 1
237247

238248
logger.info(args.delimiter.join(fields))
@@ -261,16 +271,19 @@ def getWirelessInterfacesList():
261271

262272
def startup_checks():
263273
if getuid() != 0:
264-
print R + "User is not Root."
274+
if not args.quiet:
275+
print R + "User is not Root."
265276
sys.exit()
266277

267278
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."
269281
sys.exit()
270282
return;
271283

272284
def logo():
273-
print O + '''
285+
if not args.quiet:
286+
print O + '''
274287
%s______ _
275288
| ___ \ | |
276289
| |_/ /__ __ _ _ __ _ _| |_ ___
@@ -284,22 +297,49 @@ def logo():
284297
%sCode%s: stuart@sensepost.com // @NoobieDog
285298
%sVisit%s: www.sensepost.com // @sensepost
286299
''' %(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+']'
289302

290303
def main(intf):
291304
try:
292305
sniff(iface=intf, prn=PacketHandler, store=0)
293306
except Exception, e:
294-
print 'Caught exception while running sniff()',e
307+
if not args.quiet:
308+
print 'Caught exception while running sniff()',e
295309

296310
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+
297334
devices = bluetooth.discover_devices(duration=1, lookup_names = True)
298335

299336
for addr, name in devices:
300337
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))
303343

304344
if __name__=="__main__":
305345
args = parse_args()
@@ -317,7 +357,8 @@ def btscanning():
317357
intf = args.interface
318358

319359
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'
321362
if 'mon' not in getWirelessInterfacesList():
322363
#call(['airmon-ng', 'check', 'kill'], stdout=DN, stderr=DN)
323364
cmd = ['airmon-ng', 'start' ,intf]
@@ -333,12 +374,14 @@ def btscanning():
333374
try:
334375
gpsp = GpsPoller() # create the thread
335376
except Exception, e:
336-
print 'Caught exception while running GPS',e
377+
if not args.quiet:
378+
print 'Caught exception while running GPS',e
337379

338380
try:
339381
gpsp.start() # start it up
340382
except Exception, e:
341-
print 'Caught exception while running GPS',e
383+
if not args.quiet:
384+
print 'Caught exception while running GPS',e
342385
gpsp.running = False
343386
gpsp.join() # wait for the thread to finish what it's doing
344387
sys.exit()
@@ -350,17 +393,20 @@ def btscanning():
350393

351394
# Finish off with Tidy up of CSV.
352395

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)
354398

355399
outfile = args.output + '.csv'
356400

357-
print G + '\n Creating CSV' +W+ ': ' + outfile
401+
if not args.quiet:
402+
print G + '\n Creating CSV' +W+ ': ' + outfile
358403
try:
359404
with open(args.output, 'rb') as inf, open(outfile, 'wb') as outf:
360405
outf.writelines(collections.OrderedDict.fromkeys(inf))
361406
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
363409

364410
# 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

Comments
 (0)