0

What's the simplest way to spoof a ping reply with Scapy? I have a compiled script that keep pinging a certain domain and I need to investigate it's behavior when it receive a ping reply. I thought Scapy would be my best option to do so, but I can't figured it out.

So far I've found the class scapy.layers.inet.ICMPEcho_am, but trying to import it from scapy.layers.inet throws an ImportError. Beside, I also need to fake a DNS respond, and I'm even more clueless on that.

Thanks in advance for any hint, solution, etc.

B. Bergeron
  • 90
  • 1
  • 10

2 Answers2

0

A ping (echo) reply is just an ICMP packet with a type and code of 0:

IP(src="FAKE INITIATOR ADDRESS", dst="THE SERVER ADDRESS") / ICMP(type=0, code=0)

or, alternatively:

IP(src="FAKE INITIATOR ADDRESS", dst="THE SERVER ADDRESS") / ICMP(type="echo-reply", code=0)

Obviously, "FAKE INITIATOR ADDRESS" and "THE SERVER ADDRESS" should be replaced by strings that hold the fake client address and the server address that you're spoofing a reply to.

The code=0 isn't actually necessary since 0 is the default, but I figured explicit it nice.

Carcigenicate
  • 43,494
  • 9
  • 68
  • 117
0

I made this program to send spoof IPv6 pings on a given interface. You need to take care of proper sequence number also in the packet

def sniffer(interface):
    #scapy.sniff(iface=interface, filter="icmp6 && ip6[40] == 128", store=False, prn=process_packet)
    scapy.sniff(iface=interface,filter="icmp6", store=False, prn=process_packet)

def process_packet(packet):
    print("DUMP\n")
    print(packet.show())
    print(packet[Ether].src)
    print(Ether().src)
    if packet[Ether].src == Ether().src:
        print("OUTGOING PACKET")
        print(packet[IPv6].dst)
        if packet.haslayer(ICMPv6EchoRequest):
            print("OUTGOING ECHO REQUEST")
            reply_packet = Ether(dst=packet[Ether].src)\
                           /IPv6(dst=packet[IPv6].src,
                            src=packet[IPv6].dst) \
                           / ICMPv6EchoReply(seq=packet[ICMPv6EchoRequest].seq,
                                             id=0x1)
            scapy.sendp(reply_packet, iface="Wi-Fi")
    else:
        print("INCOMING PACKET")


interface = "Wi-Fi"
sniffer(interface)
dev Joshi
  • 305
  • 2
  • 21