Skip to content

Commit 8f7364b

Browse files
committed
feat: Implement UDP packet sending with Scapy for enhanced functionality
1 parent 85215ba commit 8f7364b

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

Jiyu_udp_attack/sender.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import socket
88
from typing import List, Optional, Tuple
99

10+
from scapy.all import send as scapy_send
11+
from scapy.all import IP, UDP, Raw, RandShort # type: ignore
12+
1013
try:
1114
from Jiyu_udp_attack.ip_analyze import ip_analyze
1215
except ImportError:
@@ -145,11 +148,10 @@ def send_packet(
145148
client.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
146149
client.sendto(payload, (dst_ip, dst_port))
147150
else:
148-
client = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
149-
client.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
150-
client.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
151-
packet = create_raw_udp_packet(src_ip, src_port, dst_ip, dst_port, payload, ip_id=ip_id)
152-
client.sendto(packet, (dst_ip, dst_port))
151+
ip_layer = IP(src=src_ip, dst=dst_ip)
152+
udp_layer = UDP(sport=RandShort() if src_port is None else src_port, dport=dst_port)
153+
packet = ip_layer / udp_layer / Raw(load=payload)
154+
scapy_send(packet, verbose=0)
153155

154156

155157
def broadcast_packet(

poetry.lock

Lines changed: 17 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ readme = "README.md"
88

99
[tool.poetry.dependencies]
1010
python = ">=3.8,<4"
11+
scapy = "^2.6.1"
1112

1213

1314
[build-system]

0 commit comments

Comments
 (0)