Python Scapy欺骗UDP数据包错误

Python Scapy欺骗UDP数据包错误,python,Python,我通过以下代码获得此信息: AttributeError: 'bytearray' object has no attribute '__rdiv__' 找到在stackoverflow上欺骗数据包的示例,但它没有使用bytearray,我想我需要将bytearray转换为字符串 还有我的scapy一直在打开powershell,有什么办法吗 我通过将bytearray转换为字符串修复了该错误,现在我得到以下错误: b = bytearray([0xff, 0xff]) def spoof(

我通过以下代码获得此信息:

AttributeError: 'bytearray' object has no attribute '__rdiv__'
找到在stackoverflow上欺骗数据包的示例,但它没有使用bytearray,我想我需要将bytearray转换为字符串

还有我的scapy一直在打开powershell,有什么办法吗

我通过将bytearray转换为字符串修复了该错误,现在我得到以下错误:

b = bytearray([0xff, 0xff])

def spoof(src_ip, src_port, dest_ip, dest_port):
    global b
    spoofed_packet = IP(src=src_ip, dst=dest_ip) / TCP(sport=src_port, dport=dest_port) / b
    send(spoofed_packet)

可能是您正在使用的Python版本

看起来在python3中,
\uu rdiv\uu
运算符可能已被折旧

见以下问题:


您可以使用以下代码

    os.write(1,b".")
    OSError: [Errno 9] Bad file descriptor

Bytearray对象无法转换为数据包对象(因此,Scapy无法发送它们,这解释了
'Bytearray'对象没有属性'\u rdiv'
错误)。您需要使用
str()
(如果您使用的是2.4.0之前的Scapy,Python 2)或
raw()
(Scapy 2.4.0及更高版本,Python 2或3)转换
b

我强烈建议您升级到Scapy 2.4.0。这将修复
错误的文件描述符和Powershell窗口。

例如,您的代码使用
raw()
(如果您使用的是Scapy<2.4.0,则替换为
str()
):

如果您没有使用bytearray对象,也可以直接使用
字节
/
str
对象:

b = bytearray([0xff, 0xff])

def spoof(src_ip, src_port, dest_ip, dest_port):
    global b
    spoofed_packet = IP(src=src_ip, dst=dest_ip) / TCP(sport=src_port, dport=dest_port) / raw(b)
    send(spoofed_packet)

我正在使用python 2.7作为
bytearray
看看这个线程,我仍然得到了操作系统。write(1,b“.”)OSError:[Errno 9]该函数的文件描述符不正确:/它是哪个操作系统?Windows 10,它在原始函数上给出了相同的错误。你能确保设置正常吗?使用本文中列出的步骤,并确保您使用管理员权限运行程序。我认为这更多的是安装问题,而不是编码问题。当然,如果问题发生变化。。。无论如何,你必须转换bytearray对象来发送它们,我想这个bug可以通过升级来修复……我已经在问题更新后更新了我的答案。
b = bytearray([0xff, 0xff])

def spoof(src_ip, src_port, dest_ip, dest_port):
    global b
    spoofed_packet = IP(src=src_ip, dst=dest_ip) / TCP(sport=src_port, dport=dest_port) / raw(b)
    send(spoofed_packet)
b = b"\xff\xff"

def spoof(src_ip, src_port, dest_ip, dest_port):
    global b
    spoofed_packet = IP(src=src_ip, dst=dest_ip) / TCP(sport=src_port, dport=dest_port) / b
    send(spoofed_packet)