[Python] add option in tcp with scapy

Discussão em 'Python' iniciado por Stack, Maio 12, 2025.

  1. Stack

    Stack Membro Participativo

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

    [​IMG]

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

    [​IMG]

    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?

    Continue reading...

Compartilhe esta Página