Summary
GL.iNet GL-MT3000 firmware 4.4.5 contains a command injection vulnerability in the FTP Protocol Handler's /cgi-bin/glc endpoint, where the media_dir argument is unsafely embedded into a shell command.
A remote attacker who can reach this interface may inject arbitrary commands via crafted media_dir values, leading to unauthorized command execution on the router under affected configurations.
Affected context
This vulnerability occurs in GL.iNet GL-MT3000 devices running firmware version 4.4.5, specifically within the FTP Protocol Handler exposed by /cgi-bin/glc.
The issue arises when user-supplied media_dir parameters are passed into command construction logic and written into FTP-related configuration without adequate shell-escaping.
It is relevant in deployments where:
- The web/administration interface is reachable (locally or remotely, depending on network setup)
- The FTP configuration functionality is enabled or accessible
- Requests to
/cgi-bin/glcor related protocol configuration endpoints are processed with insufficient validation of themedia_dirfield
Exploit preconditions
- Attack surface: HTTP/CGI interface on the GL-MT3000 (e.g.,
/cgi-bin/glcFTP Protocol Handler). - Required access: Network access to the device's management/API interface; depending on configuration, this may be from the LAN side or, if exposed, from the WAN/remote side. Authentication requirements depend on how the interface is deployed and protected.
- Trigger point: Submission of a crafted request where the
media_dirparameter is populated with shell metacharacters and additional commands; the vulnerability is triggered when the backend constructs and executes or passes a command line containing this value. - Why exploitation is possible: The server-side code previously interpolated the
media_dirargument into a command or configuration string without robust quoting or escaping, enabling attackers to break out of the intended argument context and inject additional shell commands (CWE-77/CWE-74).
Why this happens
The root cause is the use of untrusted input inside a shell command or configuration directive without proper neutralization of special characters.
In affected firmware, the media_dir parameter is processed by the FTP Protocol Handler (/cgi-bin/glc) and incorporated into command strings, likely surrounded by single quotes but not consistently escaped before use.
This pattern corresponds to CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection'), as the input can close existing quoting, append ;-separated commands, and comment out the remainder.
It is also related to CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component, because attacker-controlled data is written into a configuration or command channel that another component (shell/FTP server) interprets.
The vendor's fix for later firmware versions—escaping single quotes via escape_single_quote() before embedding media_dir—illustrates that the prior behavior failed to enforce a strict separation between data and executable command syntax.
Potential impact
- Remote execution of arbitrary shell commands with the privileges of the web/FTP configuration process on the router
- Unauthorized modification of router configuration, including network, firewall, or FTP settings
- Extraction or tampering of files stored on attached storage or within the device filesystem
- Use of the router as a foothold for lateral movement into the internal network
- Deployment of malware, backdoors, or persistent implants on the device
General mitigation guidance
Effective mitigation focuses on preventing untrusted input from influencing command interpretation and reducing the privileges of any processes that must handle such input.
Recommended defensive patterns include:
- Avoid invoking shell interpreters with concatenated strings; prefer direct API calls or library functions to configure services (e.g., editing configuration files via structured I/O rather than command-line wrappers).
- When a shell must be used, pass user-controlled values as arguments to system calls that avoid shell parsing (e.g., exec-style APIs with argument arrays) rather than constructing single command strings.
- Apply strict input validation for parameters like
media_dir, limiting to expected character sets (e.g., alphanumeric, allowed path separators) and rejecting or encoding shell metacharacters (',;,#,&,|,$, etc.). - Use robust escaping/quoting helpers that are specific to the interpreter being used (POSIX shell, configuration syntax, etc.) and ensure these are applied consistently on every code path.
- Run web/CGI and configuration-handling components with least privilege, isolating them via OS-level sandboxing or containers when possible, to limit impact if a command injection occurs.
- Minimize exposure of management interfaces: restrict access to trusted networks, segment administration ports, and disable protocol handlers that are not required.
How teams detect issues like this
Detection should aim to identify both the insecure code patterns and any active exploitation attempts.
Code-level detection:
- Use static analysis or linters to flag direct use of shell-invoking functions (e.g.,
system,popen,exec*with/bin/sh -c) where untrusted parameters are concatenated into the command string. - Review CGI or router management code paths that construct configuration or control commands from HTTP parameters such as
media_dir, focusing on missing or inconsistent escaping routines. - Enforce secure coding guidelines via CI pipelines that block merges when command construction patterns appear without explicit sanitization or validation.
Runtime and log-based detection:
- Monitor HTTP logs for suspicious
media_dirvalues containing shell metacharacters, unusual quoting, or sequences like;,&&,|,#, and backticks. - Collect and inspect system logs for anomalous command executions originating from the web/CGI processes, especially commands that are not part of the normal FTP configuration workflow.
- Employ network intrusion detection systems (NIDS) with signatures for command injection payloads targeting router management endpoints.
Automated security testing tools (e.g., SAST for firmware source, DAST for web interfaces, and fuzzers that mutate parameters like media_dir) can complement manual review and help surface vulnerable endpoints before deployment.

