Search code examples
pythonhexscapy

Sending specific hex data using scapy


I want to send specific hex sequences e.g FF FF FF FF FF FF on wire using scapy without using the Raw option. Will finding the string equivalent of these hex sequences and using them as packet payload have the same effect since scapy will convert them to hex and send ?


Solution

  • In python 2.x you can create the binary data from a hex string using the binascii module. I've used this to correctly set the duid in DHCPv6 request, just passing it to the option of the packet type.

    For example

    >>> import binascii
    >>> binascii.unhexlify('FFFFFFFFFFFF')
    '\xff\xff\xff\xff\xff\xff'
    

    Passing that string to the payload should be all you need. Of course you can just type the string with \x escapes as above, but it's easier to represent it as a nice hex string and call unhexlify when you need the correct binary data.