问题
I'm trying to send a specific packet size (100 bytes) with scapy
but cant seem to get it.
I'm using this to start.
sr(IP(dst="192.168.1.1")/TCP(dport=443))
Looking at the docs / help I cant tell if I can use PacketLenField
to specify the length of the packet. I can do it with NMAP & NSE but would like to do it outside of NMAP.
Any ideas on this one?
Thanks!
回答1:
You can just add on the required number of bytes as a String when crafting the packet e.g.:
payload = 'ZZZZZZZZZZZZZZZZZZZZZ'
pkt = Ether() / IP() / TCP() / payload
will work. You just need to adjust the length of the payload as you require.
回答2:
You may use inet.Padding()
from scapy
library:
packet = IP(dst="192.168.1.1")/TCP(dport=443)
if len(packet)<100"
#"\x00" is a single zero byte
myString = "\x00"*(100 - len(packet))
packet = packet/inet.Padding(myString)
回答3:
Scapy's Raw()
function populates the payload of the packet. If you know your header size, you only need to fill in the remaining bytes with random data.
You can use RandString()
to generate random padding. The following command sends a packet of length 100 (and listens for a response):
sr(IP(dst="192.168.1.1")/TCP(dport=443)/Raw(RandString(size=72))
来源:https://stackoverflow.com/questions/14657193/specifying-packet-length-with-scapy