P1sec / pysctp

SCTP stack for Python
http://www.p1sec.com
165 stars 67 forks source link

Byte-ordering is incorrect when trying to use ppid attribute of sctp_send #46

Open btsimon97 opened 1 year ago

btsimon97 commented 1 year ago

When trying to use the ppid attribute, the integer value is sent over the wire with the byte order swapped from the correct value for the specified number.

For example, if I were to specify a PPID of 46 (the ppid of Diameter which in hex is 0x0000002e) in Python, the ppid that is sent over the wire is instead 771751936 (which in hex is 0x2e000000).

If I instead specified a ppid of 0x2e000000, the ppid sent over the wire is 46 (0x0000002e). This seems to indicate that a byte-ordering error is occurring between when the integer is specified in python and when it is sent over the wire.

p1-bmu commented 1 year ago

The Linux SCTP API handles the PPID as a big-endian, so do PySCTP. I know it's misleading, but the intention is to stick with the Linux API. Therefore, you need to use ntohl and htonl from the socket module for converting the value to your CPU endianness.

You can have a look on the sctp_echo_server to see how PPID and others parameters are managed: https://github.com/P1sec/pysctp/blob/modern_api/sctp_echo_srv.py

CorruptBandit commented 7 months ago

I think we need a flag to have the ability to switch between big and little endian for the PPID