0

I'm new to using scapy and I want to create a little program that sents packets that start with a size of 2 Byte and each next packet increases it's size by 2 byte.

I know that i can define a payload variable and put it as a parameter, but how can I create a payload that starts with exactly 2 bytes and how can I increase this?

Kaiser
  • 15
  • 1
  • 5

1 Answers1

0

Using the / operator you can easily encapsulate any number of bytes you want in your packet. For instance, here I send 10 ICMP requests to 192.168.1.254 and increase the payload by two bytes at each step:

from scapy.all import IP, ICMP, send

payload = '  '
for i in range(10):
    p = IP(dst="192.168.1.254")/ICMP()/payload
    payload += '  '
    send(p)
qouify
  • 3,698
  • 2
  • 15
  • 26
  • Thanks for the answer, but if I check and do `getsizeof()` for the beginning payload variable it says that it is 50 bytes. Any way I can start at exactly 2 bytes? – Kaiser Dec 03 '20 at 11:40
  • `sys.getsizeof(payload)` is the total memory used by python to represent your `payload` variable that is a string object. So besides the 2 bytes python also needs some data to represent that string in memory. But you should not care about that unless you are interested for example by the real memory consumption of your program. The actual number of bytes that will be inserted in your packet is `len(payload)` which is 2. – qouify Dec 03 '20 at 13:37
  • That makes sense. Thank you very much for the explanation and the help! – Kaiser Dec 03 '20 at 13:50