For a POC, I need to create a MITM setup where I would listen to ICMP traffic on the interface and for all the ping commands received, I would send my own reply. So far with python scapy, I have been able to intercept all ICMP packets. How do I block the actual ping reply packets and send my own packets as reply?
My code looks like this
import scapy.all as scapy
import socket
from scapy.arch import get_if_hwaddr
from scapy.interfaces import get_if_list
from scapy.layers import http
from scapy.layers.inet import TCP, ICMP, IP
from scapy.layers.l2 import Ether
from uuid import getnode as get_mac
def sniffer(interface):
scapy.sniff(iface=interface, store=False, prn=process_packet)
def process_packet(packet):
if packet.haslayer(ICMP):
print("DUMP\n")
print(packet.show(dump=True))
print(packet[Ether].src)
print(Ether().src)
if packet[Ether].src == Ether().src:
print("OUTGOING PACKET")
else:
print("INCOMING PACKET")
interface = "Wi-Fi"
sniffer(interface)