From f0206b949bdfdb6e3c4192b1e5e43de81dc910ef Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 27 Sep 2019 10:04:54 +0200 Subject: [PATCH] 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 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 --- s1ap_reiniger.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/s1ap_reiniger.py b/s1ap_reiniger.py index 62791af..f121134 100755 --- a/s1ap_reiniger.py +++ b/s1ap_reiniger.py @@ -164,7 +164,11 @@ def handle_sctp_chunk(chunk, pkt_number): log.error("Malformed packet, skipping...") return False - handle_s1ap(s1ap(), pkt_number) + try: + handle_s1ap(s1ap(), pkt_number) + except: + log.error("Failed to decode S1AP payload (Packet %d)", (pkt_number)) + return False # Encapsulate the new payload # TODO: reset checksum fields