Overview
Systemd manages services on modern Linux. If you can modify a.service file, its binary, or exploit relative paths, you get code execution as the user running the service (often root).
Find Writable Service Files
Check Drop-in Directories
/etc/systemd/system/<unit>.d/*.conf) override service settings.
Exploit Writable .service File
Modify ExecStart
Reverse Shell via Service
Exploit via Drop-in Override
If/etc/systemd/system/<unit>.d/ is writable:
Empty
ExecStart= line is required before the new one — systemd appends otherwise.Writable Service Binary
If the binary a service executes is writable:Systemd PATH Hijacking
systemd does not use the environment$PATH (from systemctl show-environment) to resolve a relative ExecStart binary. It uses a fixed compile-time search path — typically /usr/local/sbin, /usr/local/bin, /usr/sbin, /usr/bin. The hijack only works if one of those standard directories is writable.
Writable Timer Files
malicious.service:
Writable Socket Files
ExecStartPre to execute before socket activation:
Create Missing Service for Socket
If a.socket exists but the .service it activates is missing: