Specifying packet length with scapy

耗尽温柔 提交于 2021-02-07 17:09:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!