-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PoC of python nas heuristic #85
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
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] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for some reason this took me forever to wrap my head around lol. would There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah good call, I for some reason forgot you could do a fixed end index for a slice. |
||||||
|
||||||
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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
|
||||||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we're not handling the case of an invalid NAS message here, in which case i think
msg == None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is handled in line 30 by the heuristic, but we could also handle it here instead, never call the heuristic, and also throw an error.