mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-07-22 23:38:10 -07:00
proof of concept pcap reader for nas heuristic
This commit is contained in:
committed by
Will Greenberg
parent
94e9a88a91
commit
b2cd735a07
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/python3
|
||||
import nasparse
|
||||
from scapy.utils import RawPcapNgReader
|
||||
import sys
|
||||
|
||||
TYPE_LTE_NAS = 0x12
|
||||
UDP_LEN = 28
|
||||
|
||||
def process_pcap(pcap_path):
|
||||
print('Opening {}...'.format(pcap_path))
|
||||
|
||||
count = 0
|
||||
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]
|
||||
|
||||
if gsmtap_hdr[2] != TYPE_LTE_NAS:
|
||||
continue
|
||||
|
||||
# uplink status is the 7th bit of the 5th byte of the GSMTAP header.
|
||||
# Uplink (Mobile originated) = 0 Downlink (mobile terminated) = 1
|
||||
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)
|
||||
if triggered:
|
||||
print(f"Frame {count} triggered heuristic: {message}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print("usage: pcap_check.py [path/to/pcap/file]")
|
||||
exit(1)
|
||||
|
||||
pcap_path = sys.argv[1]
|
||||
process_pcap(pcap_path)
|
||||
Reference in New Issue
Block a user