Commit Graph

7 Commits

Author SHA1 Message Date
Harald Welte 67f9e9b72f NAS: Implement patching of ID; Fix patching of EPSID
this needs more work:
* unify handling of EPSID and ID
* implement other ID types than IMSI
2019-09-27 11:23:39 +02:00
Harald Welte f0206b949b Catch exceptions while decoding the packet
If any exceptions are found while decoding the packet, remove it from
the output trace to ensure no information leaks.

In my real-world traces, I e.g. got the following exception terminating
the program:

CHOICE._from_per: S1AP-PDU, unknown extension index 699866529169900427952657872967740904512772918212192949539462653507496501180206847298869570851487786014667431700603926958879953036143148400114887836583469249625472224706264417515341607478659710751184333540332091231808038155414952989252906034887075176400074366401692584783210687966823902077240699797242085375
Traceback (most recent call last):
  File "./s1ap_reiniger.py", line 245, in <module>
    handle_pcap(sys.argv[1], sys.argv[2])
  File "./s1ap_reiniger.py", line 215, in handle_pcap
    pkt = handle_sctp_pkt(pkt, i)
  File "./s1ap_reiniger.py", line 193, in handle_sctp_pkt
    success = handle_sctp_chunk(chunk, pkt_number)
  File "./s1ap_reiniger.py", line 167, in handle_sctp_chunk
    handle_s1ap(s1ap(), pkt_number)
  File "./s1ap_reiniger.py", line 122, in handle_s1ap
    log.info("Processing S1AP message '%s:%s' (Packet %d)" % (msg[0], msg[1]['value'][0], pkt_number))
TypeError: byte indices must be integers or slices, not str
2019-09-27 10:04:54 +02:00
Harald Welte a45e8b354c don't blindly assume a nAS-PDU in S1AP; check for it
Fixes

Traceback (most recent call last):
  File "/tmp/s1ap_reiniger.py", line 243, in <module>
    handle_pcap(sys.argv[1], sys.argv[2])
  File "/tmp/s1ap_reiniger.py", line 214, in handle_pcap
    pkt = handle_sctp_pkt(pkt)
  File "/tmp/s1ap_reiniger.py", line 193, in handle_sctp_pkt
    success = handle_sctp_chunk(chunk)
  File "/tmp/s1ap_reiniger.py", line 167, in handle_sctp_chunk
    handle_s1ap(s1ap())
  File "/tmp/s1ap_reiniger.py", line 149, in handle_s1ap
    find_and_handle_s1ap_nested_nas_pdu(msg[1]['value'])
  File "/tmp/s1ap_reiniger.py", line 118, in find_and_handle_s1ap_nested_nas_pdu
    pdu = handle_nas_pdu(item['value'][1]['nAS-PDU'], dl = True)
KeyError: 'nAS-PDU'
2019-09-27 09:52:16 +02:00
Harald Welte 0968f13a5d Print packet number while processing for easier debugging
When an error message is printed, it's useful to have context
information around showing _which_ packet has caused the error.
2019-09-27 09:52:16 +02:00
Harald Welte 4626b5c2f0 Fix bug trying to use encode method on byte object
Traceback (most recent call last):
  File "/tmp/s1ap_reiniger.py", line 242, in <module>
    handle_pcap(sys.argv[1], sys.argv[2])
  File "/tmp/s1ap_reiniger.py", line 213, in handle_pcap
    pkt = handle_sctp_pkt(pkt)
  File "/tmp/s1ap_reiniger.py", line 192, in handle_sctp_pkt
    success = handle_sctp_chunk(chunk)
  File "/tmp/s1ap_reiniger.py", line 166, in handle_sctp_chunk
    handle_s1ap(s1ap())
  File "/tmp/s1ap_reiniger.py", line 152, in handle_s1ap
    find_and_handle_s1ap_nas_pdu(msg[1]['value'], dl = False)
  File "/tmp/s1ap_reiniger.py", line 103, in find_and_handle_s1ap_nas_pdu
    pdu = handle_nas_pdu(ie['value'][1], dl)
  File "/tmp/s1ap_reiniger.py", line 30, in handle_nas_pdu
    log.debug("Processing %s NAS PDU: %s" % ("Downlink" if dl else "Uplink", pdu.encode('hex')))
AttributeError: 'bytes' object has no attribute 'encode'
2019-09-27 09:52:16 +02:00
Harald Welte 521d22c553 change to executable; explicitly use Python 3 2019-09-27 09:33:34 +02:00
Vadim Yanitskiy 9dcedc7cfd Initial import of s1ap_reiniger.py 2019-09-27 09:32:52 +02:00