简体   繁体   English

Scapy,IndexError:未找到层 [Dot11]

[英]Scapy, IndexError: Layer [Dot11] not found

I am trying to send a HTTP response using scapy.我正在尝试使用 scapy 发送 HTTP 响应。 I sniff out an request and then attempt to fabricate a response.我嗅出一个请求,然后尝试编造一个响应。 I am basing this off the code in this question.我基于这个问题中的代码。 Here is the code that is causing problems:这是导致问题的代码:

import scapy.all as scapy
from scapy.layers.http import HTTPRequest
from scapy.layers.dot11 import RadioTap
from scapy.layers.dot11 import Dot11
packets = scapy.sniff(count=30)
    for i in range(len(packets)):
        if packets[i].haslayer(HTTPRequest):
            pkt = packets[i]
            dot11_frame = RadioTap()/Dot11(
                type = "Data",
                FCfield = "from-DS",
                addr1 = pkt[scapy.Dot11].addr2,
                addr2 = pkt[scapy.Dot11].addr1,
                addr3 = pkt[scapy.Dot11].addr1,
                )

After I sniff the packet and get all the information required I do what the other guy did, and the problem is that I keep on getting this error with the part defining dot11_frame, IndexError: Layer [Dot11] not found , this happens when the line addr1 = pkt[scapy.Dot11].addr2 is run.在我嗅探数据包并获取所需的所有信息后,我做了其他人所做的事情,问题是我在定义 dot11_frame, IndexError: Layer [Dot11] not found的部分不断收到此错误,这发生在行时addr1 = pkt[scapy.Dot11].addr2运行。 I have not even done a wildcard import like some answers suggested.我什至没有像一些答案建议的那样进行通配符导入。 So how do I fix this error?那么我该如何解决这个错误呢?

First, you probably mean pkt[Dot11] , not [scapy.Dot11] , as you imported the name Dot11 .首先,您可能是指pkt[Dot11] ,而不是[scapy.Dot11] ,因为您导入了名称Dot11

Second, it seems that the packet you are capturing do not contain a Dot11 layer.其次,您捕获的数据包似乎不包含Dot11层。 This will happen, for example, if you capture packets from a non-Wi-Fi interface, or from a Wi-Fi interface that is not configured as a monitor interface.例如,如果您从非 Wi-Fi 接口或未配置为监控接口的 Wi-Fi 接口捕获数据包,就会发生这种情况。

To help you debug your problem, you could add a print(pkt.command()) just after assigning the pkt variable.为了帮助您调试问题,您可以在分配pkt变量后添加一个print(pkt.command())

Also, you probably want to learn a bit of Python before using Scapy seriously.此外,您可能想在认真使用 Scapy 之前学习一点 Python。 For example, rather than:例如,而不是:

for i in range(len(packets)):
    if packets[i].haslayer(HTTPRequest):
        pkt = packets[i]
        [...]

You want to write:你想写:

for pkt in packets:
    if HTTPRequest not in pkt:
        continue
    [...]

Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM