MOHAMED
MOHAMED

Reputation: 43558

add option in tcp with scapy

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

enter image description here

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

enter image description here

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?

Upvotes: 2

Views: 11912

Answers (2)

Sidharth
Sidharth

Reputation: 1

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")])

Upvotes: 0

Yoel
Yoel

Reputation: 9614

I think you need to specify the optional field's value in a tuple format, as follows:

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

Upvotes: 0

Related Questions