简体   繁体   中英

add option in tcp with scapy

Upon the receive of a TCP ACK (with option experiment) like this

在此处输入图片说明

I want to generate a TCP SYN+ACK (with option experiment and Fast Open Cookie) as indicated below

在此处输入图片说明

I want to generate the TCP SYN+ACK with scapy so I added

So I added 254 : ("RFC3692-style Experiment","!HHH") in the / usr/share/pyshared/scapy/layers/inet.py like this

TCPOptions = (
              { 0 : ("EOL",None),
                1 : ("NOP",None),
                2 : ("MSS","!H"),
                3 : ("WScale","!B"),
                4 : ("SAckOK",None),
                5 : ("SAck","!"),
                8 : ("Timestamp","!II"),
                14 : ("AltChkSum","!BH"),
                15 : ("AltChkSumOpt",None),
                25 : ("Mood","!p"),
                254 : ("Experiment","!HHHH")
                },
              { "EOL":0,
                "NOP":1,
                "MSS":2,
                "WScale":3,
                "SAckOK":4,
                "SAck":5,
                "Timestamp":8,
                "AltChkSum":14,
                "AltChkSumOpt":15,
                "Mood":25,
                "Experiment":254
                } )

And upon the receive of the TCP ACK (with experiment option), I executhe the following scapy function:

TCP_SYNACK=TCP(sport=Ddport, dport=Ssport, flags="SA", seq=SeqNr, ack=AckNr, options=[('Experiment',0xf989,0xcafe,0x0102,0x0002),('NOP',0),('NOP',0)])
ANSWER=sr1(ip/TCP_SYNACK)

But I got a python error. It looks like I made error in the definition of the option field in the TCP packet with scapy. What I m doing wron?

我认为您需要以tuple格式指定可选字段的值,如下所示:

TCP_SYNACK = TCP(sport=Ddport, dport=Ssport, flags="SA", seq=SeqNr, ack=AckNr, options=[('Experiment', (0xf989, 0xcafe, 0x0102, 0x0002)), ('NOP', 0), ('NOP', 0)])

but I had the same problem. You can actually put an integer as the first element of your options tuple. I wanted to put in a hash, so I used the following code in scapy:

pkt = TCP(options=[("NOP", None), (19, "\xff\xff\xff\xff\xff\xff")])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM