Summary
sagredo qmail before 2026.04.07 contains an OS command injection vulnerability in the notlshosts_auto handling within qmail-remote.c, where user-controlled data is passed to popen() without proper sanitization.
A remote attacker who can influence TLS-related parameters (such as those used when tls_quit is triggered) may execute arbitrary commands on the mail server under the privileges of the qmail-remote process.
Affected context
The vulnerability occurs within sagredo qmail's remote delivery component (qmail-remote.c), specifically in the logic around notlshosts_auto and TLS negotiation behavior.
It is exposed when the software constructs shell commands that are executed via popen() and incorporates data that can be influenced by remote input (for example, hostnames or connection parameters evaluated when TLS is disabled or when tls_quit is processed).
Deployments that use sagredo qmail versions prior to 2026.04.07 and rely on TLS-related host handling are more likely to be affected, especially where external, potentially untrusted SMTP peers can control portions of the values fed into notlshosts_auto.
Exploit preconditions
- Attack surface: SMTP service exposed to remote systems (e.g., Internet-facing mail server).
- Required access: Ability to establish an SMTP connection and influence the data processed by
qmail-remoteduring TLS-related decision paths (such as hostnames or parameters that flow intonotlshosts_auto). - Trigger point: Execution of
popen()innotlshosts_autologic when handlingtls_quitor related TLS configuration conditions. - Why exploitation is possible: Data derived directly or indirectly from the remote peer is concatenated or interpolated into a shell command string executed by
popen()without robust validation, escaping, or avoidance of shell interpretation, enabling injection of arbitrary shell metacharacters and commands.
Why this happens
This issue stems from constructing shell commands that include attacker-controlled or attacker-influenceable data and then executing those commands via popen() in qmail-remote.c.
The pattern maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), where the program relies on the shell to interpret a command line and fails to neutralize metacharacters such as ;, |, &, or backticks.
Instead of using safer APIs that pass arguments directly to the OS without invoking a shell, the code delegates parsing to the shell, turning crafted input into executable logic whenever TLS-related functions like notlshosts_auto are invoked.
Potential impact
- Remote execution of arbitrary shell commands with the privileges of the
qmail-remoteprocess. - Full compromise of the affected mail server, including reading or tampering with email in transit as accessible to that component.
- Abuse of the mail server as a platform for further lateral movement within the network.
- Use of the compromised host as a spam relay or part of a botnet, damaging reputation and potentially triggering blacklisting.
- Modification or disruption of outbound mail delivery, resulting in denial of service for legitimate email traffic.
General mitigation guidance
Effective mitigation focuses on eliminating shell-based command construction and reducing trust in remotely influenced input:
- Prefer APIs that do not invoke a shell (e.g., direct
exec-style calls with argument vectors or library calls) instead ofpopen()with a string command. - Avoid embedding hostnames, TLS parameters, or other data derived from remote SMTP peers directly into shell commands; if external tools must be called, pass such data as safely encoded arguments.
- Apply strict validation and canonicalization to any configuration or runtime values used by
notlshosts_auto, limiting them to well-defined character sets (such as alphanumeric, dot, and dash for hostnames). - Run the mail delivery components with the least privileges necessary and segregate them into dedicated OS users or containers to limit blast radius if compromise occurs.
- Prefer secure-by-design configurations that do not depend on external shell commands for TLS or host classification logic where feasible.
How teams detect issues like this
Detection often combines code-centric review with runtime monitoring:
- Static analysis: Configure static analysis or grep-based checks to flag uses of
popen(),system(), or similar functions where arguments are built from variables tied to network input, environment variables, or configuration files. - Code review signals: During manual review, treat any shell command construction in
qmail-remote.cor related TLS/host handling code as high risk, especially where string concatenation or formatting is used to create command lines. - Policy enforcement: Introduce secure coding policies that prohibit shell execution with untrusted input and require justification and peer review for any remaining
popen()usage. - Runtime and log analysis: Monitor SMTP logs and system audit logs for anomalous command invocations originating from qmail processes, unexpected child process trees, or spikes in outbound connections that could signal exploitation attempts.

