Summary
ProFTPD's mod_sql module before 1.3.10rc1 is vulnerable to SQL injection when USER commands are logged using expansions like %U and the username is written directly into SQL queries.
In environments where the SQL backend supports command execution (such as COPY TO PROGRAM), a remote attacker can supply a crafted FTP username that leads to arbitrary command execution on the server during logging.
Affected context
The vulnerability manifests in ProFTPD deployments that:
- Use mod_sql for logging or accounting, and
- Log USER requests with dynamic expansions (e.g.,
%Ufor username) into SQL-backed tables, and - Employ a SQL backend or configuration that permits server-side command execution (e.g., SQL dialects/features such as
COPY TO PROGRAMor similar mechanisms).
It is particularly relevant when the SQL statements used for logging are constructed through string concatenation or unparameterized templates that embed user-controlled data.
Exploit preconditions
- Attack surface: Remote, over the FTP control channel (USER command).
- Required access: Ability to connect to the FTP service and send arbitrary USER values (no valid credentials required).
- Trigger point: Processing and logging of the USER command when mod_sql formats an SQL statement using expansions like
%U. - Why exploitation is possible: The username is interpolated directly into SQL log statements without proper parameterization or escaping. If the SQL backend or schema allows statements that can trigger OS-level commands, injected SQL fragments from the username can cause arbitrary command execution during the logging operation.
Why this happens
The root cause is the unsafe construction of SQL statements from untrusted input within the logging path of mod_sql.
Specifically, ProFTPD is configured to log FTP USER commands using expansion variables (such as %U) that are substituted directly into SQL strings. Instead of using prepared statements or parameter binding, the implementation relies on string concatenation, allowing crafted usernames to break out of the intended value context and inject arbitrary SQL.
This behavior maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where user-controlled data is embedded in SQL commands without adequate sanitization or parameterization, and is exacerbated here by SQL dialect features that enable command execution from within SQL queries.
Potential impact
- Remote execution of arbitrary OS commands on the ProFTPD host (when supported by the SQL backend).
- Full compromise of the FTP server process and potentially the underlying operating system account.
- Unauthorized access to or modification of data in the SQL backend (e.g., credential records, audit logs).
- Tampering with or erasure of audit trails and FTP activity logs.
- Use of the compromised FTP server as a foothold for lateral movement within the network.
General mitigation guidance
Effective mitigation focuses on eliminating SQL injection in logging paths and limiting what the SQL backend is allowed to do:
- Use parameterized queries or prepared statements for all mod_sql interactions, including logging and accounting operations, so that username data is always bound as a value, not concatenated into query text.
- Avoid constructing SQL from formatted strings containing expansions like
%Udirectly in query templates; instead, feed such values into bound parameters. - Configure the SQL backend to disable or restrict features that allow command execution from SQL (e.g.,
COPY TO PROGRAM, external procedures, or similar capabilities) where not strictly required. - Apply principle of least privilege to the database user used by ProFTPD, granting only the minimal set of permissions necessary for logging and authentication operations.
- Treat all log-related data paths as untrusted input and subject them to the same security controls as primary application data, including input validation and escaping where parameterization is not possible.
How teams detect issues like this
Organizations can identify and monitor for this class of vulnerability through:
- Static analysis and configuration review of ProFTPD and mod_sql configuration files, looking for logging or SQL templates that interpolate expansions like
%Udirectly into query strings. - Code review of custom modules or patches that interface ProFTPD with SQL backends, ensuring that all variables derived from FTP commands are passed through parameterized queries.
- Database-side policy and monitoring, including:
- Searching for queries that contain dynamic fragments derived from usernames or FTP commands.
- Identifying and alerting on use of high-risk SQL constructs (e.g.,
COPY TO PROGRAM, external command execution functions) from the ProFTPD database account. - Integration of automated security scanners or rule-based linters that flag string-based SQL construction patterns in server configuration and source code repositories.

