Summary
GL.iNet GL-MT3000 devices contain a command injection flaw in the Tor Proxy Service Configuration Handler, specifically in the replace_country function.
A remote attacker who can reach the web configuration interface may inject arbitrary shell commands, leading to full compromise of the affected router.
Affected context
This vulnerability occurs within the Tor Proxy Service Configuration Handler on GL.iNet GL-MT3000 devices running firmware versions up to 4.4.5.
It affects environments where the router's HTTP/RPC interface is reachable over the network (LAN or, in misconfigured cases, from the internet) and user-controlled input is passed to backend scripts.
The issue is present when configuration values, such as the Tor exit country setting, are processed without adequate sanitization before being used in command-line operations.
Exploit preconditions
- Attack surface: The router's HTTP/RPC configuration interface backing the Tor Proxy Service.
- Required access: Network-level access to the management interface (e.g., authenticated web admin session or any exposed API endpoint that reaches
replace_country). - Trigger point: Submission of crafted configuration parameters that are processed by the
replace_countryfunction in/usr/lib/oui-httpd/rpc/tor. - Why exploitation is possible: User-supplied data is concatenated into shell commands or command parameters without robust escaping or validation, enabling attackers to break out of intended arguments and execute arbitrary commands.
Why this happens
The defect is rooted in improper handling of user-controlled input when constructing shell commands.
The replace_country function appears to interpolate configuration values directly into command strings executed by the system shell, or pass them to APIs that implicitly invoke a shell.
This pattern maps to CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection'), and is closely related to CWE-74: Improper Neutralization of Special Elements in Output, because unsanitized input is embedded into an output context (a shell command) where meta-characters are interpreted as control syntax.
Instead of treating configuration fields as opaque data and passing them via safe, argument-based process execution or strict allowlists, the implementation trusts the input format, allowing injection of shell metacharacters.
Potential impact
- Remote execution of arbitrary shell commands on the router's underlying operating system
- Full takeover of the device, including modification of configuration, DNS settings, or routing behavior
- Installation of persistent malware or backdoors on the router
- Interception, redirection, or inspection of network traffic traversing the device
- Use of the compromised router as a pivot point for attacking other systems on the local network
- Participation of the device in botnets or large-scale distributed attacks
General mitigation guidance
Effective mitigation focuses on eliminating direct shell command construction from user input and constraining configuration values to safe, well-defined sets.
Recommended defensive patterns include:
- Replacing shell-based invocations with APIs that accept parameter arrays (e.g., exec-style calls with no shell) and treating all user input as opaque data.
- Enforcing strict allowlists for configuration fields like country codes, validating against known ISO lists instead of accepting arbitrary strings.
- Normalizing and validating all external input early, rejecting values containing shell metacharacters or unexpected patterns for the domain.
- Decomposing complex command logic into internal, parameterized functions that never concatenate strings into commands.
- Running configuration-handling processes with least privilege and separating high-risk operations into isolated components or sandboxes.
These measures reduce the impact of untrusted configuration data and make command injection patterns structurally impossible or significantly harder to introduce.
How teams detect issues like this
Detection typically involves a combination of code-centric and behavior-centric approaches:
- Static analysis rules that flag use of shell invocation functions (e.g., system, popen, backticks) where arguments include user-sourced values or HTTP parameters.
- Pattern-based scanning for string concatenation or formatting that builds command lines from request parameters in RPC or HTTP handler code.
- Code review checklists focusing on configuration handlers, ensuring all user inputs are validated against allowlists and never embedded directly in commands.
- Runtime monitoring of the device for unusual process spawns, unexpected command-line arguments, or network connections originating from router services.
- Incorporating security linting and automated code review tools into CI pipelines to catch command injection signatures before release.
These strategies help identify both this specific issue and similar command-injection risks in related components.

