Summary
Pi-hole's FTL engine versions 6.0 to before 6.6 contain a command injection vulnerability in the dhcp.hosts configuration parameter exposed via the interactive API.
An authenticated attacker who can control this parameter can inject arbitrary dnsmasq configuration directives using newline characters, which can be leveraged to execute operating system commands on the underlying host.
Affected context
The vulnerability occurs in Pi-hole deployments using the FTL engine where the interactive API is exposed and the DHCP hosts configuration (dhcp.hosts) can be modified by authenticated users or services.
It is relevant in environments where:
- Pi-hole FTL versions 6.0 to before 6.6 are in use
- The FTL API or management interface is available over the network
- DHCP host entries are dynamically managed through the API or integrated automation
The flaw is tied to how user-supplied values are translated into dnsmasq configuration without robust validation or sanitization of control characters and directive boundaries.
Exploit preconditions
- Attack surface: Pi-hole FTL interactive API / management interface that exposes the
dhcp.hostsconfiguration parameter. - Required access: Authenticated access with permission to configure or update DHCP hosts; often panel/API credentials, API tokens, or access to a trusted integration.
- Trigger point: Submission or update of
dhcp.hostsvalues containing newline characters and crafted payloads that are written into the generateddnsmasqconfiguration and subsequently loaded or reloaded by the service. - Why exploitation is possible: The FTL engine treats the
dhcp.hostsparameter as opaque text and embeds it directly intodnsmasqconfiguration files or equivalent input, without stripping newline characters or enforcing a strict schema. This enables injection of additionaldnsmasqdirectives, some of which can be abused to reach OS command execution in the runtime environment.
Why this happens
The underlying issue is a combination of improper input validation and command injection through configuration channels, primarily aligning with CWE-78: Improper Neutralization of Special Elements used in an OS Command and CWE-93: Improper Neutralization of CRLF Sequences in HTTP Headers-like newline handling patterns.
Instead of treating dhcp.hosts inputs as structured data with a strict format, the FTL engine accepts arbitrary strings that may include newline characters. These newline sequences prematurely terminate the intended configuration line and start new dnsmasq configuration directives. Because dnsmasq can be configured in ways that ultimately influence command execution or system behavior, this uncontrolled directive injection escalates into remote code execution. The bug class is thus the failure to sanitize metacharacters and separators (such as \n) before passing user-controlled data into a configuration context that ultimately drives system-level commands.
Potential impact
- Execution of arbitrary OS commands under the privileges of the Pi-hole / FTL process
- Full compromise of the Pi-hole host, including reading or modifying local files accessible to the service account
- Alteration or poisoning of DNS/DHCP behavior, enabling network-wide traffic redirection or denial-of-service
- Use of the compromised Pi-hole instance as a pivot point to move laterally within the network
- Persistent backdoor installation or deployment of additional malware on the host system
General mitigation guidance
Robust mitigation focuses on sanitizing configuration inputs and constraining how user data reaches lower-level services:
- Strict input validation and encoding: Treat
dhcp.hostsand similar parameters as structured data with a well-defined grammar. Reject or escape newline characters, carriage returns, and other control characters that can break out of the intended configuration line. - Configuration templating with strong typing: Generate
dnsmasqconfiguration from typed data structures rather than raw string concatenation. Use templates or libraries that handle escaping and avoid direct injection of user-controlled segments. - Whitelist-based schema enforcement: Limit DHCP host configuration fields to safe character sets (e.g., alphanumerics, hyphens, and dots) and apply length checks and pattern constraints before persisting values.
- Privilege minimization: Run Pi-hole / FTL and
dnsmasqwith the least privileges necessary, and restrict file system and OS capabilities so that even if configuration is abused, the impact is reduced. - Separation of control and data channels: Avoid configuration designs where a user-controlled field can directly influence control directives; separate user data from administrative directives wherever possible.
How teams detect issues like this
Detection can be approached at both code and operational levels:
- Static analysis and code review:
- Flag any paths where user-controlled configuration fields are concatenated into
dnsmasqor other service configuration files without explicit sanitization. - Look for acceptance of raw newline characters (
\n,\r\n) in API parameters that are later written to configuration files. - Review configuration rendering logic for absence of schema validation, escaping, or character whitelisting.
- Configuration and runtime monitoring:
- Monitor generated
dnsmasqconfiguration files for unexpected or non-standard directives, especially those including shell commands or external program hooks. - Alert on suspicious changes to configuration files outside expected workflows (e.g., unusual directives inserted shortly after API calls).
- Policy and CI/CD checks:
- Introduce security-focused unit tests or integration tests that attempt to inject newline characters and control sequences into configuration-related parameters and verify they are rejected or safely encoded.
- Use automated security scanners or SAST tools configured with rules for newline/CRLF injection and configuration injection patterns.

