From dd8edfe4c0cd22ecb8ccfdc6f54ecafb20069f2f Mon Sep 17 00:00:00 2001 From: Cooper Quintin Date: Tue, 17 Dec 2024 09:26:16 -0800 Subject: [PATCH] fix nits --- tools/nasparse.py | 3 +++ tools/pcap_check.py | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/nasparse.py b/tools/nasparse.py index ee581e7..61713b1 100755 --- a/tools/nasparse.py +++ b/tools/nasparse.py @@ -24,6 +24,9 @@ def parse_nas_message(buffer, uplink=None): parsed = NASLTE.parse_NASLTE_MT(bin) else: parsed = NASLTE.parse_NASLTE_MT(bin) + + if parsed[0] is None: # Not a NAS Packet + raise parsed[1] return parsed[0] def heur_ue_imsi_sent(msg): diff --git a/tools/pcap_check.py b/tools/pcap_check.py index e3b9df7..70ec5fa 100755 --- a/tools/pcap_check.py +++ b/tools/pcap_check.py @@ -10,13 +10,12 @@ def process_pcap(pcap_path): print('Opening {}...'.format(pcap_path)) count = 0 - for (pkt_data, pkt_metadata,) in RawPcapNgReader(pcap_path): + for pkt_data, pkt_metadata in RawPcapNgReader(pcap_path): count += 1 gsmtap_len = pkt_data[UDP_LEN+1] * 4 # gsmtap header length is stored in the 2nd byte of GSMTAP as a number of 32 bit words header_end = gsmtap_len + UDP_LEN #length of UDP/IP header plus GSMTAP header - gsmtap_end_idx = (len(pkt_data) - header_end) * -1 - gsmtap_hdr = pkt_data[UDP_LEN:gsmtap_end_idx] + gsmtap_hdr = pkt_data[UDP_LEN:header_end] if gsmtap_hdr[2] != TYPE_LTE_NAS: continue @@ -26,7 +25,7 @@ def process_pcap(pcap_path): uplink = (gsmtap_hdr[4] & 0b01000000) >> 6 buffer = pkt_data[header_end:] msg = nasparse.parse_nas_message(buffer, uplink) - (triggered, message)= nasparse.heur_ue_imsi_sent(msg) + triggered, message = nasparse.heur_ue_imsi_sent(msg) if triggered: print(f"Frame {count} triggered heuristic: {message}")