Summary
Pi-hole's root-executed systemd hook scripts use a path read from configuration (files.pid) in privileged file operations without validation, allowing controlled deletion and recreation of arbitrary files outside certain protected directories.
An attacker who already has Pi-hole service privileges can point this path at sensitive locations (such as SSH authorized_keys) to gain full root access on the host.
Affected context
This vulnerability occurs in Pi-hole Core (6.0 to < 6.4.2) and FTL (6.0 to < 6.6.1) when deployed with the default systemd service configuration.
Two scripts, pihole-FTL-prestart.sh and pihole-FTL-poststop.sh, run as root and consume the files.pid path from Pi-hole's configuration.
When an attacker-controlled or attacker-modifiable configuration can influence this path, the scripts perform privileged file deletion and creation on arbitrary locations, outside systemd's ProtectSystem=full-restricted paths.
Exploit preconditions
- Attack surface: Local, on a host running a vulnerable Pi-hole deployment.
- Required access: Ability to authenticate as a user or service account with "pihole" privileges (or equivalent rights to modify Pi-hole configuration controlling
files.pid). - Configuration control: Attacker can write an arbitrary filesystem path into the
files.pidconfiguration value. - Trigger point: Starting, stopping, or restarting the
pihole-FTLsystemd service so that: pihole-FTL-prestart.shruns before service start, and/orpihole-FTL-poststop.shruns after service stop.- Why exploitation is possible: The scripts trust the configured path without validation, performing
rm -fand file creation logic as root on whatever file the configuration points to, thereby crossing privilege boundaries.
Why this happens
The core issue is that privileged shell scripts executed by systemd as root implicitly trust a configuration-supplied file path and use it in dangerous file operations.
This behavior aligns with:
- CWE-269: Improper Privilege Management – root-level scripts perform operations on attacker-controlled paths, allowing lower-privileged actors to escalate to root.
- CWE-15: External Control of System or Configuration Setting – the
files.pidsetting, controlled by a less-privileged context, directly influences which file is deleted and recreated. - CWE-732: Incorrect Permission Assignment for Critical Resource – the recreated file is written with root's authority in a way that can grant unauthorized write/control to the attacker (for example, manipulating SSH authorized_keys).
In abstract terms, an untrusted configuration value is treated as a safe, absolute filesystem target for sensitive operations in a high-privilege context, without path validation, confinement, or policy checks.
Potential impact
- Local privilege escalation from Pi-hole-level access to full root access on the host.
- Overwriting or creating SSH
authorized_keysfiles to obtain persistent root login. - Deletion and recreation of critical configuration files outside protected directories.
- Potential denial of service by corrupting or removing key system or application files.
- Broad system compromise if rewritten files control services, authentication, or security policies.
General mitigation guidance
Effective mitigation focuses on reducing trust in configuration-controlled paths and tightening privilege boundaries around root-executed scripts:
- Constrain configurable paths: Restrict
files.pidand similar settings to a fixed, root-owned directory (e.g., under/run,/var/run, or another dedicated runtime path), and reject absolute or parent-relative paths. - Validate and sanitize file paths: Introduce path canonicalization and checks to ensure the target remains within an allowed directory tree before performing any file operation.
- Drop unnecessary privileges: Where possible, perform file handling as a less-privileged user and only escalate for narrow, controlled operations that cannot be avoided.
- Harden script logic: Replace ad-hoc
rm -fandinstallcalls on user-controlled paths with safer patterns, such as temporary directories, fixed filenames, or explicit whitelisting. - Enforce ownership and permissions: Ensure configuration files that influence privileged behavior are writable only by trusted, root-level principals, and not by service or application users.
- Leverage sandboxing: Use systemd hardening (e.g., stricter
ProtectSystem,ReadOnlyPaths,InaccessiblePaths) and dedicated service users to restrict the blast radius of any path misuse.
How teams detect issues like this
Detection generally involves inspecting both configuration and the behavior of privileged scripts:
- Static analysis and code review:
- Look for shell scripts or service units executed as root that read paths from configuration or environment and pass them directly to commands like
rm,install,cp,mv, or redirection operators (>/>>). - Flag any use of configuration-controlled variables in file operations without path validation or restriction to a known safe directory.
- Configuration audits:
- Periodically scan Pi-hole configuration (and similar components) for unexpected absolute paths or references to sensitive locations such as
/root/.ssh/authorized_keys,/etc/, or other critical directories. - File integrity and monitoring:
- Use file integrity monitoring tools to alert on changes to high-value targets (e.g.,
authorized_keys, system service files) correlated with service restarts. - Policy enforcement in CI/CD:
- Introduce automated checks that block changes adding or modifying root-executed scripts which consume untrusted configuration values without validation or confinement.
- Runtime logging and alerts:
- Enable verbose logging for systemd services and consider rules that flag suspicious patterns like repeated deletion and recreation of sensitive files during service lifecycle events.

