Using scapy, how do I create a set of packets with incrementing payloads? For example, the first packet's payload (data) must be 1, the second's must be 2, and so on.
I tried this:
>>> pkt=(Ether(dst='00:01:02:03:04:05', src='00:06:07:08:09:0a')/ IP(src='192.168.0.1', dst='192.168.0.2', tos=0)/ TCP(sport=(123), dport=123))/(1,20)
but I get an error.
If I want to create 10 packets with the source port starting at 123, incrementing by 1 for every packet, and ending at 133. I do this:
>>> pkt=(Ether(dst='00:01:02:03:04:05', src='00:06:07:08:09:0a')/ IP(src='192.168.0.1', dst='192.168.0.2', tos=0)/ TCP(sport=(123,133), dport=123))/("x")
>>> pkts=[p for p in pkt]
>>> pkts
Which works fine
Update: I made this script for incrementing ip address:
#!/usr/bin/env python
import sys
from scapy.all import IP,TCP
from scapy.utils import wrpcap
if len(sys.argv) >= 2:
payload = sys.argv[1]
print "generating packets..."
ip = IP(dst="192.168.0.2", tos=0)
ip_str=[]
for i in xrange(1, 256):
temp_ip_str = "192.168.0.%d"%(i)
ip_str.append(temp_ip_str)
ip.src = ip_str
tcp = TCP(sport=443, dport=80)/(payload*6)
pkt=[p for p in ip/tcp]
wrpcap("%s.cap"%payload, pkt)
and it should probably work similar for the payload
If you want your payloads to contain the ASCII strings "1", "2", ... "19", "20", then try this:
pkt=(Ether(dst='00:01:02:03:04:05', src='00:06:07:08:09:0a')/
IP(src='192.168.0.1', dst='192.168.0.2', tos=0)/
TCP(sport=(123), dport=123)/
Raw((1,20)))
If you want your payloads to contain one byte each, with values 1, 2, ... 20, try this:
pkt=(Ether(dst='00:01:02:03:04:05', src='00:06:07:08:09:0a')/
IP(src='192.168.0.1', dst='192.168.0.2', tos=0)/
TCP(sport=(123), dport=123)/
Raw(list(chr(x) for x in range(1,21))))
In either case, you can confirm what you've got via:
wireshark(pkt)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With