Specifying packet length with scapy

I am trying to send a specific packet size (100 bytes) using scapy , but it does not seem to have received it.

I use this to start.

 sr(IP(dst="192.168.1.1")/TCP(dport=443)) 

Looking at the docs / help, I can't tell if I can use PacketLenField to indicate the length of the packet. I can do this with NMAP and NSE, but would like to do it outside of NMAP.

Any ideas on this?

Thanks!

+4
source share
3 answers

You can simply add the required number of bytes as a string when creating the package, for example:

 payload = 'ZZZZZZZZZZZZZZZZZZZZZ' pkt = Ether() / IP() / TCP() / payload 

will work. You just need to adjust the payload length as needed.

+3
source

The Scapy Raw() function fills the packet payload. 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 the response):

sr(IP(dst="192.168.1.1")/TCP(dport=443)/Raw(RandString(size=72))

+1
source

You can use inet.Padding() from the 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) 
0
source

All Articles