Search code examples
pythonscapyicmp

unable to receive the answer of a fragmented ICMP Echo Request


I am trying to send manually a big ICMP Echo Request, therefore I wrote following scapy code:

frags = fragment(IP(dst=dst)/ICMP()/Raw(load=('x')*50000))


s = conf.L3socket(iface=iface)      #improve Sending performance (https://byt3bl33d3r.github.io/mad-max-scapy-improving-scapys-packet-sending-performance.html)

count = len(frags)                  #Count fragments
i = 0
maximum = count - 1                 
print "maximum: " + str(maximum)

#Send all Frags but the last
while i < maximum:
    print "i: " + str(i)
    s.send(frags[i]) 
    i = i + 1
answer = s.sr(frags[i]) # using sr(), to receive an answer
print(ans[0])

It doesn't work to receive an ICMP Echo response. The Answer I get is always something like

Received 9 packets, got 0 answers, remaining 1 packets

Does someone know, what's wrong with my code?


Solution

  • There are a lot of reasons why this won’t work:

    • sr() stands for « send receive ». This function already sends the packet, so you don’t need to send it previously
    • sr() returns multiple answers, meaning that it won’t stop if you don’t ^C it or if it timeout. You are looking for sr1() which returns on the first answer
    • scapy cannot (yet) defragment packets « on the flow ». When you are calling sr/sr1, it checks each packet for a possible answer, but there won’t be any as it does not defragment on the flow. For this answer, you need to implement all the « answer checking » yourself, or find another way.

    Anyway, I don’t know if a lot of servers will answer such a ICMP