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
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'
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'