129 lines
3.8 KiB
Python
129 lines
3.8 KiB
Python
# Chaos macht Schule
|
|
# Wi-Fi Printer
|
|
# Prints SSIDs, MAC addresses, and their vendors on a thermal printer.
|
|
|
|
import os, sys
|
|
import pickle
|
|
import collections
|
|
import trackerjacker
|
|
|
|
from escpos import printer
|
|
|
|
|
|
__config__ = {'trigger_cooldown': 10} # No need to call more than once for a single device
|
|
REPORT_FILE = 'top_manufacturers.txt'
|
|
|
|
|
|
class Trigger:
|
|
def __init__(self):
|
|
self.manufacturer_to_count = collections.Counter()
|
|
self.devices_seen = set()
|
|
self.packets_seen = 0
|
|
self.ssids_seen = []
|
|
|
|
path = os.path.dirname(trackerjacker.__file__)
|
|
|
|
self.p = printer.Usb(0x0493, 0x8760, in_ep=0x81, out_ep=0x03)
|
|
self.p.text("\n\n")
|
|
self.p.image(path+"/plugins/cms.png")
|
|
|
|
self.p.text("Chaospott Essen\n")
|
|
self.p.text("Wir sind da wat am hacken dran!\n")
|
|
self.p.text("https://www.chaospott.de/\n")
|
|
self.p.text("\n\n")
|
|
|
|
print("")
|
|
print("")
|
|
print("Chaos macht Schule")
|
|
print("Chaospott Essen - Wir sind da wat am hacken dran")
|
|
print("https://www.chaospott.de")
|
|
print("")
|
|
|
|
|
|
|
|
# Called when new device is found
|
|
def __call__(self, dev_id=None, vendor=None, ssid=None, bssid=None, iface=None, power=None, **kwargs):
|
|
|
|
# Store SSID in list if its not already in there
|
|
if ssid not in self.ssids_seen:
|
|
self.ssids_seen.append(ssid)
|
|
|
|
# Output on screen
|
|
print('Neues Netzwerk: {}, Netzwerke insgesamt: {}\n\n'
|
|
.format(ssid, len(self.ssids_seen)))
|
|
|
|
# Output on printer
|
|
self.p.text('SSID: {},\nNetzwerke insgesamt: {}\n\n'
|
|
.format(ssid, len(self.ssids_seen)))
|
|
|
|
|
|
# Check if the device's new
|
|
if vendor and dev_id not in self.devices_seen:
|
|
self.devices_seen |= {dev_id}
|
|
self.manufacturer_to_count[vendor] += 1
|
|
|
|
# Output on screen
|
|
print('Neues Gerät: {}) von Hersteller: {};\n Anzahl Geräte von Hersteller {}: {}\n'
|
|
.format(dev_id, vendor, vendor, self.manufacturer_to_count[vendor]))
|
|
|
|
# Output on printer
|
|
self.p.text('Ger\20\204\04t: {}\nHersteller: {}\n\n'.format(dev_id, vendor))
|
|
|
|
|
|
# Print each n packets a summary
|
|
self.packets_seen += 1
|
|
if self.packets_seen % 100 == 0:
|
|
self.output_report()
|
|
|
|
|
|
# Print report
|
|
def output_report(self):
|
|
|
|
# Calculate results
|
|
descending_order = sorted([(count, vendor) for vendor, count in self.manufacturer_to_count.items()], reverse=True)
|
|
|
|
total_ssid_count = len(self.ssids_seen)
|
|
|
|
total_device_count = 0
|
|
for (count, vendor) in descending_order:
|
|
total_device_count += count
|
|
|
|
|
|
# Output to file for plot and further evaluation
|
|
with open(REPORT_FILE, 'w') as f:
|
|
for (count, vendor) in descending_order:
|
|
f.write('{}: {}\n'.format(count, vendor))
|
|
|
|
|
|
# Output on printer
|
|
self.p.text("\n\n")
|
|
self.p.text("############\n")
|
|
self.p.text("# Ergebnis #\n")
|
|
self.p.text("############\n\n")
|
|
|
|
self.p.text('Netzwerke gefunden: {}\n\n'
|
|
.format(total_ssid_count))
|
|
|
|
self.p.text('Ger\20\204\04te gefunden: {}\n\n'
|
|
.format(total_device_count))
|
|
|
|
for (count, vendor) in descending_order:
|
|
self.p.text('{0:1}: {1}\n'.format(count, vendor))
|
|
|
|
self.p.text("\n\n\n")
|
|
|
|
|
|
# Output to screen
|
|
print('\n{}\n Ergebnis\n {}\n\n'.format('='*100, '='*100))
|
|
|
|
print('Netzwerke gefunden: {}\n\n'
|
|
.format(total_ssid_count))
|
|
|
|
print('Geräte gefunden: {}\n\n'
|
|
.format(total_device_count))
|
|
|
|
|
|
for (count, vendor) in descending_order:
|
|
print('{0:8}: {1}\n'.format(count, vendor))
|
|
|