jookies / jasmin

Jasmin - Open source SMS gateway
http://jasminsms.com
Other
991 stars 540 forks source link

SMPP Connection is dropped as Received unparsable PDU #1124

Open ausphone opened 11 months ago

ausphone commented 11 months ago

Hello,

Could you please check this issue? MO SMS is received from SMPP Server and forwarded to SMPP Client via MO Static Route.

Message is delivered to user, but when user is sending deliver_ok - SMPP connection is dropped, reestablishing and message delivered again.

2023-08-09 09:57:15 INFO 902 DELIVER_SM [uid:client_name] [from:b'614YYYYYYYY'] [to:b'614XXXXXXXX'] [content:b'Check message'] 2023-08-09 09:57:15 ERROR 902 Unknown Error: Field must be null Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/smpp/twisted/protocol.py", line 211, in rawMessageReceived pdu = self.encoder.decode(BytesIO(message)) File "/usr/local/lib/python3.10/dist-packages/smpp/pdu/pdu_encoding.py", line 1038, in decode self.decodeBody(file, pdu, headerParams['command_length'] - self.HEADER_LEN) File "/usr/local/lib/python3.10/dist-packages/smpp/pdu/pdu_encoding.py", line 1080, in decodeBody mandatoryParams = self.decodeRequiredParams(pdu.mandatoryParams, self.getRequiredParamEncoders(pdu), file) File "/usr/local/lib/python3.10/dist-packages/smpp/pdu/pdu_encoding.py", line 1190, in decodeRequiredParams params[paramName] = encoderMap[paramName].decode(file) File "/usr/local/lib/python3.10/dist-packages/smpp/pdu/pdu_encoding.py", line 99, in decode raise PDUParseError("Field must be null", pdu_types.CommandStatus.ESME_RUNKNOWNERR) smpp.pdu.error.PDUParseError: Unknown Error: Field must be null 2023-08-09 09:57:15 CRITICAL 902 Received unparsable PDU b'00000022800000050000000000000067313639313537353033353237373235383600' 2023-08-09 09:57:15 INFO 902 Dropped CommandId.bind_transceiver bind for 'client_name'. Active binds: CommandId.bind_transceiver: 0, CommandId.bind_transmitter: 0, CommandId.bind_receiver: 0. 2023-08-09 09:57:15 WARNING 902 SMPP 185.16.XX.XX disconnected from port 2775: [Failure instance: Traceback: <class 'AttributeError'>: type object 'DeliverSMResp' has no attribute 'requireAck' /usr/lib/python3/dist-packages/twisted/python/log.py:80:callWithContext /usr/lib/python3/dist-packages/twisted/python/context.py:117:callWithContext /usr/lib/python3/dist-packages/twisted/python/context.py:82:callWithContext /usr/lib/python3/dist-packages/twisted/internet/posixbase.py:696:_doReadOrWrite --- --- /usr/lib/python3/dist-packages/twisted/internet/posixbase.py:683:_doReadOrWrite /usr/lib/python3/dist-packages/twisted/internet/tcp.py:247:doRead /usr/lib/python3/dist-packages/twisted/internet/tcp.py:252:_dataReceived /usr/local/lib/python3.10/dist-packages/smpp/twisted/protocol.py:142:dataReceived /usr/local/lib/python3.10/dist-packages/smpp/twisted/protocol.py:222:rawMessageReceived ] 2023-08-09 09:57:17 WARNING 902 SMPP connection established from 185.16.XX.XX to port 2775 2023-08-09 09:57:17 INFO 902 Added CommandId.bind_transceiver bind for 'client_name'. Active binds: CommandId.bind_transceiver: 1, CommandId.bind_transmitter: 0, CommandId.bind_receiver: 0. 2023-08-09 09:58:15 ERROR 902 Request timed out for system id client_name after 60 secs: PDU [command: CommandId.deliver_sm, sequence_number: 103, command_status: CommandStatus.ESME_ROK service_type: b'' source_addr_ton: <AddrTon.INTERNATIONAL: 2> source_addr_npi: <AddrNpi.ISDN: 2> source_addr: b'614YYYYYYYY' dest_addr_ton: <AddrTon.INTERNATIONAL: 2> dest_addr_npi: <AddrNpi.ISDN: 2> destination_addr: b'614XXXXXXXX' esm_class: EsmClass[mode: EsmClassMode.DEFAULT, type: EsmClassType.DEFAULT, gsmFeatures: set()] protocol_id: 0 priority_flag: <PriorityFlag.LEVEL_0: 1> schedule_delivery_time: None validity_period: None registered_delivery: RegisteredDelivery[receipt: RegisteredDeliveryReceipt.NO_SMSC_DELIVERY_RECEIPT_REQUESTED, smeOriginatedAcks: set(), intermediateNotification: False] replace_if_present_flag: <ReplaceIfPresentFlag.DO_NOT_REPLACE: 1> data_coding: DataCoding[scheme: DataCodingScheme.DEFAULT, schemeData: DataCodingDefault.SMSC_DEFAULT_ALPHABET] sm_default_msg_id: 0 short_message: b'Check message' ] 2023-08-09 09:58:15 WARNING 902 Shutdown requested...disconnecting 2023-08-09 09:58:15 WARNING 902 Disconnecting... 2023-08-09 09:58:45 INFO 902 DELIVER_SM [uid:client_name] [from:b'614YYYYYYYY'] [to:b'614XXXXXXXX'] [content:b'Check message'] 2023-08-09 09:58:45 ERROR 902 Unknown Error: Field must be null Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/smpp/twisted/protocol.py", line 211, in rawMessageReceived pdu = self.encoder.decode(BytesIO(message)) File "/usr/local/lib/python3.10/dist-packages/smpp/pdu/pdu_encoding.py", line 1038, in decode self.decodeBody(file, pdu, headerParams['command_length'] - self.HEADER_LEN) File "/usr/local/lib/python3.10/dist-packages/smpp/pdu/pdu_encoding.py", line 1080, in decodeBody mandatoryParams = self.decodeRequiredParams(pdu.mandatoryParams, self.getRequiredParamEncoders(pdu), file) File "/usr/local/lib/python3.10/dist-packages/smpp/pdu/pdu_encoding.py", line 1190, in decodeRequiredParams params[paramName] = encoderMap[paramName].decode(file) File "/usr/local/lib/python3.10/dist-packages/smpp/pdu/pdu_encoding.py", line 99, in decode raise PDUParseError("Field must be null", pdu_types.CommandStatus.ESME_RUNKNOWNERR) smpp.pdu.error.PDUParseError: Unknown Error: Field must be null 2023-08-09 09:58:45 CRITICAL 902 Received unparsable PDU b'00000022800000050000000000000003313639313537353132353237373431363300' 2023-08-09 09:58:45 INFO 902 Dropped CommandId.bind_transceiver bind for 'client_name'. Active binds: CommandId.bind_transceiver: 0, CommandId.bind_transmitter: 0, CommandId.bind_receiver: 0. 2023-08-09 09:58:45 WARNING 902 SMPP 185.16.XX.XX disconnected from port 2775: [Failure instance: Traceback: <class 'AttributeError'>: type object 'DeliverSMResp' has no attribute 'requireAck' /usr/lib/python3/dist-packages/twisted/python/log.py:80:callWithContext /usr/lib/python3/dist-packages/twisted/python/context.py:117:callWithContext /usr/lib/python3/dist-packages/twisted/python/context.py:82:callWithContext /usr/lib/python3/dist-packages/twisted/internet/posixbase.py:696:_doReadOrWrite --- --- /usr/lib/python3/dist-packages/twisted/internet/posixbase.py:683:_doReadOrWrite /usr/lib/python3/dist-packages/twisted/internet/tcp.py:247:doRead /usr/lib/python3/dist-packages/twisted/internet/tcp.py:252:_dataReceived /usr/local/lib/python3.10/dist-packages/smpp/twisted/protocol.py:142:dataReceived /usr/local/lib/python3.10/dist-packages/smpp/twisted/protocol.py:222:rawMessageReceived ] 2023-08-09 09:58:47 WARNING 902 SMPP connection established from 185.16.XX.XX to port 2775 2023-08-09 09:58:47 INFO 902 Added CommandId.bind_transceiver bind for 'client_name'. Active binds: CommandId.bind_transceiver: 1, CommandId.bind_transmitter: 0, CommandId.bind_receiver: 0. 2023-08-09 09:59:45 ERROR 902 Request timed out for system id client_name after 60 secs: PDU [command: CommandId.deliver_sm, sequence_number: 3, command_status: CommandStatus.ESME_ROK service_type: b'' source_addr_ton: <AddrTon.INTERNATIONAL: 2> source_addr_npi: <AddrNpi.ISDN: 2> source_addr: b'614YYYYYYYY' dest_addr_ton: <AddrTon.INTERNATIONAL: 2> dest_addr_npi: <AddrNpi.ISDN: 2> destination_addr: b'614XXXXXXXX' esm_class: EsmClass[mode: EsmClassMode.DEFAULT, type: EsmClassType.DEFAULT, gsmFeatures: set()] protocol_id: 0 priority_flag: <PriorityFlag.LEVEL_0: 1> schedule_delivery_time: None validity_period: None registered_delivery: RegisteredDelivery[receipt: RegisteredDeliveryReceipt.NO_SMSC_DELIVERY_RECEIPT_REQUESTED, smeOriginatedAcks: set(), intermediateNotification: False] replace_if_present_flag: <ReplaceIfPresentFlag.DO_NOT_REPLACE: 1> data_coding: DataCoding[scheme: DataCodingScheme.DEFAULT, schemeData: DataCodingDefault.SMSC_DEFAULT_ALPHABET] sm_default_msg_id: 0 short_message: b'Check message' ] 2023-08-09 09:59:45 WARNING 902 Shutdown requested...disconnecting 2023-08-09 09:59:45 WARNING 902 Disconnecting...


Frame 128: 133 bytes on wire (1064 bits), 133 bytes captured (1064 bits) on interface ens34, id 0 Ethernet II, Src: VMware_c2:17:d9 (00:0c:29:c2:17:d9), Dst: Routerbo_ce:16:b7 (dc:2c:6e:ce:16:b7) Internet Protocol Version 4, Src: 10.10.0.245, Dst: 185.16.XX.XX Transmission Control Protocol, Src Port: 2775, Dst Port: 65504, Seq: 1, Ack: 1, Len: 67 Short Message Peer to Peer, Command: Deliver_sm, Seq: 103, Len: 67 Length: 67 Operation: Deliver_sm (0x00000005) Sequence #: 103 Service type: (Default) Type of number (originator): International (0x01) Numbering plan indicator (originator): ISDN (E163/E164) (0x01) Originator address: 614XXXXXXXX Type of number (recipient): International (0x01) Numbering plan indicator (recipient): ISDN (E163/E164) (0x01) Recipient address: 614YYYYYYYY .... ..00 = Messaging mode: Default SMSC mode (0x0) ..00 00.. = Message type: Default message type (0x0) 00.. .... = GSM features: No specific features selected (0x0) Protocol id.: 0x00 Priority level: GSM: None ANSI-136: Bulk IS-95: Normal (0x00) Scheduled delivery time: Immediate delivery Validity period: SMSC default validity period .... ..00 = Delivery receipt: No SMSC delivery receipt requested (0x0) .... 00.. = Message type: No recipient SME acknowledgement requested (0x0) ...0 .... = Intermediate notif: No intermediate notification requested (0x0) .... ...0 = Replace: Don't replace (0x0) Data coding: SMSC default alphabet (0x00) Predefined message: 0 Message length: 12 Message bytes: 436865636b2073796d62696f

Frame 137: 100 bytes on wire (800 bits), 100 bytes captured (800 bits) on interface ens34, id 0 Ethernet II, Src: Routerbo_ce:16:b7 (dc:2c:6e:ce:16:b7), Dst: VMware_c2:17:d9 (00:0c:29:c2:17:d9) Internet Protocol Version 4, Src: 185.16.XX.XX, Dst: 10.10.0.245 Transmission Control Protocol, Src Port: 65504, Dst Port: 2775, Seq: 1, Ack: 68, Len: 34 Short Message Peer to Peer, Command: Deliver_sm - resp, Status: "Ok", Seq: 103, Len: 34 Length: 34 Operation: Deliver_sm - resp (0x80000005) Result: Ok (0x00000000) Sequence #: 103 Message id.: 16915750352772586

farirat commented 11 months ago

Seems to be a corrupt message using non-standard smpp protocol stack, can you share a pcap ?

ausphone commented 11 months ago

Sure, please find full PCAP attached.

farirat commented 11 months ago

Duplicate/related-to #681

farirat commented 11 months ago

The root cause of this issue is the error raising this message: ERROR 902 Unknown Error: Field must be null

Based on smpp 3.4 specs:

Notification_Center

But your smpp client is returning a deliver_sm_resp pdu with a non-null message_id:

jasmin_crash_pcap

This causes jasmin to declare the connection as corrupt.

ausphone commented 11 months ago

Thank you very much for your assistance and pointing us to the right direction.

The client was modified, to send message as below, that works now, no link crash.

However, I belive that would be very valuable to avoid link crash even if an unexpected message ID is received.

Link crash is quite hard and unexpected outcome to message response.

Thanks again.


Frame 63: 83 bytes on wire (664 bits), 83 bytes captured (664 bits) on interface ens34, id 0 Ethernet II, Src: Routerbo_ce:16:b7 (dc:2c:6e:ce:16:b7), Dst: VMware_c2:17:d9 (00:0c:29:c2:17:d9) Internet Protocol Version 4, Src: 185.16.XX.XX, Dst: 10.10.0.245 Transmission Control Protocol, Src Port: 35776, Dst Port: 2775, Seq: 65, Ack: 142, Len: 17 Short Message Peer to Peer, Command: Deliver_sm - resp, Status: "Ok", Seq: 1, Len: 17 Length: 17 Operation: Deliver_sm - resp (0x80000005) Result: Ok (0x00000000) Sequence #: 1