Compare commits

...

3 Commits

3 changed files with 53 additions and 56 deletions

View File

@ -1,11 +1,18 @@
#! /usr/bin/python
import reporter, sniffer
import reporter, sniffer, packet_processer
def main():
print("Starting up...")
snfr = sniffer.Sniffer("walfa0")
#print(snfr.sniff(5))
data = snfr.parse_sniff("/tmp/SUSTMP_hyMIo/cap-1666770829-01.csv")
snfr.destroy_sniffs()
print("Sniffing...")
ap_data, client_data = snfr.sniff(120)
#ap_data, client_data = snfr.parse_sniff("/tmp/SUSTMP_csMIF/cap-1666824383-01.csv")# "/tmp/test/test-01.csv")
print("Parsing...")
print( len(packet_processer.get_unique_clients_packets(client_data)) )
#print("Cleaning up...")
#snfr.destroy_sniffs()
if __name__ == "__main__":
main()

View File

@ -1,33 +1,44 @@
import pcap, dpkt
from scapy.all import Ether, ARP
from time import sleep
def process_packet(info, timestamp, packet):
src = packet.src
dst = packet.dst
print(f"{timestamp} | {src}[{1 if is_ap(src) else 0}] --> {packet.dst}[{1 if is_ap(dst) else 0}]")
#packet.display()
#sleep(.5)
def get_scapy_packet(raw_packet):
eth_frame = dpkt.ethernet.Ethernet(raw_packet)
return Ether(raw_packet)
def is_ap(mac_address):
aruba_ouis = ['94:60:D5', '48:2F:6B', '94:64:24', 'A8:5B:F7', 'F0:61:C0', 'EC:50:AA', '6C:C4:9F']
aruba_ouis = ["00:0B:86","00:1A:1E","00:24:6C","04:BD:88","0C:97:5F","10:4F:58",
"18:64:72","18:7A:3B","1C:28:AF","20:4C:03","20:9C:B4","24:62:CE","24:DE:C6",
"28:DE:65","34:3A:20","34:8A:12","38:10:F0","38:21:C7","38:BD:7A","40:E3:D6",
"44:12:44","44:5B:ED","48:2F:6B","48:B4:C3","54:D7:E3","60:26:EF","64:E8:81",
"6C:C4:9F","6C:F3:7F","70:3A:0E","74:9E:75","7C:57:3C","84:D4:7E","88:25:10",
"88:3A:30","8C:85:C1","90:20:C2","94:60:D5","94:64:24","94:B4:0F","9C:1C:12",
"A0:A0:01","A4:0E:75","A8:5B:F7","AC:A3:1E","B0:1F:8C","B4:5D:50","B8:3A:5A",
"B8:D4:E7","BC:9F:E4","BC:D7:A5","CC:88:C7","CC:D0:83","D0:15:A6","D0:4D:C6",
"D0:D3:E0","D4:E0:53","D8:C7:C8","DC:B7:AC","E8:26:89","EC:02:73","EC:50:AA",
"F0:1A:A0","F0:5C:19","F0:61:C0","F4:2E:7F","F8:60:F0","FC:7F:F1"]
for oui in aruba_ouis:
if oui in mac_address:
return True
return False
def sniff(interface, timeout_ms=500):
info = {}
sniff = pcap.pcap(name=interface, promisc=True, timeout_ms=timeout_ms)
def get_unique_clients_packets(packets):
unique_client_packets = []
for packet in packets:
if not "Station MAC" in packet:
continue
print( f"{packet['Station MAC']} --> {packet['BSSID']}" )
mac = packet["Station MAC"].strip()
if not (mac in unique_client_packets ): #or is_ap(mac)):
#FILTERS
#print(packet["Power"].strip())
#if int(packet["Power"].strip()) >= -70:
# continue
for timestamp, raw_packet in sniff:
packet = get_scapy_packet(raw_packet)
info = process_packet(info, timestamp, packet)
#if not is_ap(packet["BSSID"].strip()):
# continue
unique_client_packets.append(packet)
#print( unique_client_packets )
for packet in unique_client_packets:
print(packet)
return unique_client_packets

View File

@ -40,7 +40,7 @@ class Sniffer:
timeout = int(timeout+0.5)
dump_file = f"{self.base_dir}/cap-{ int(time.time()) }"
stdout, stderr, code = run_cmd(f"airodump-ng --write {dump_file} --write-interval 1 --output-format csv walfa0", timeout=timeout)
stdout, stderr, code = run_cmd( f"airodump-ng --write {dump_file} --write-interval 1 --output-format csv walfa0", timeout=timeout )
if code != 0 and code != -1:
return code
@ -55,28 +55,6 @@ class Sniffer:
file_data.append(item)
return file_data
def parse_into_dicts_safe(self, csv_data):
template = []
sniff_data = []
for line_index in range(len(csv_data)):
line = csv_data[line_index]
if line_index == 0:
continue
if line_index == 1:
for item in line:
template.append(item)
continue
temp = {}
if line == []:
break
for item_index in range(len(line)):
temp[template[item_index]] = line[item_index]
sniff_data.append(temp)
return sniff_data
def parse_into_dicts(self, csv_data):
template = []
sniff_data = []
@ -89,26 +67,27 @@ class Sniffer:
if not sniff_data == []:
sniff_data_parts.append(sniff_data)
sniff_data = []
continue
if make_template:
template = []
for item in line:
template.append(item)
template.append(item.strip())
make_template = False
continue
temp = {}
for item_index in range(len(line)):
temp[template[item_index]] = line[item_index]
try:
temp[template[item_index]] = line[item_index]
except:
pass
sniff_data.append(temp)
return sniff_data_parts
def parse_sniff(self, full_filepath):
file_data = self.parse_csv()
sniff_data = self.pars_into_dicts(file_data)
for packet in sniff_data[1]:
print(packet)
file_data = self.parse_csv(full_filepath)
sniff_data = self.parse_into_dicts(file_data)
return sniff_data