Local Spoofing UDP Batch Error

AttributeError: 'bytearray' object has no attribute '__rdiv__'

I get this for the following code:

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)

Found an example to trick a package into stackoverflow, but it didn't use bytearray, I suppose I need to convert bytearray to string?

Also does my scapy continue to open powershell in any way around this?

I fixed this error by setting bytearray to a string. Now I get the following error:

    os.write(1,b".")
    OSError: [Errno 9] Bad file descriptor
+4
source share
3 answers

Bytearray objects cannot be converted to Packet objects (and therefore Scapy cannot send them, this explains the error 'bytearray' object has no attribute '__rdiv__'). You need to convert busing str()(if you are using Scapy prior to version 2.4.0 with Python 2) or raw()(with Scapy 2.4.0 or later with Python 2 or 3).

Scapy 2.4.0. Bad file descriptor Powershell.

, raw() ( str(), Scapy < 2.4.0):

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)

bytearray, bytes/str:

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)
+1

, Python, ?

, __rdiv__, , python3?

. SO:

` __rdiv __() `` __idiv__` Python 3.x?

0

You can use the code below

from scapy.all import IP, UDP, L3RawSocket, conf
from scapy.all import send as scapy_send


def send(dest_ip, port, src_ip, payload, count=1):
    if dest_ip in ("127.0.0.1", "localhost"):
        conf.L3socket = L3RawSocket
    ip = IP(dst=dest_ip, src=src_ip)
    udp = UDP(dport=port)
    scapy_send(ip/udp/str(payload), count=count)


send("192.168.1.100", 9090, "192.168.33.100", "Tarun here", 2)

Sending UDP packets

0
source

Source: https://habr.com/ru/post/1695675/


All Articles