Summary
GL-iNet GL-AR300M16 routers running firmware v4.3.11 contain multiple OS command injection flaws in the set_upgrade function, where several upgrade-related parameters are used in shell commands without proper sanitization.
An attacker who can reach the upgrade interface and supply crafted values for fields such as modem_url, target_version, or firmware_upload may be able to execute arbitrary system commands on the device with high privileges.
Affected context
This vulnerability occurs in the firmware upgrade logic of GL-iNet GL-AR300M16 devices running version 4.3.11.
The set_upgrade function processes parameters including modem_url, target_version, current_version, firmware_upload, hash_type, hash_value, and upgrade_type and appears to integrate them into shell commands or scripts.
Where these parameters are influenced by HTTP requests, web forms, or APIs, and are passed to the shell without robust validation or escaping, the router becomes susceptible to command injection when handling upgrade operations.
Exploit preconditions
- Attack surface: Network-facing management or upgrade interface exposed by the router (web UI, RPC endpoint, or similar).
- Required access: Ability to submit or intercept and modify requests that invoke the
set_upgradefunction; this may involve authenticated administrative access, compromised credentials, or exploitation of a separate flaw that grants access to the upgrade endpoint. - Trigger point: Any action that triggers firmware or modem upgrade workflows using attacker-controlled values for
modem_url,target_version,current_version,firmware_upload,hash_type,hash_value, orupgrade_type. - Why exploitation is possible: The parameters are incorporated into shell commands or passed to command execution APIs without strict validation, canonicalization, or contextual escaping, allowing injected shell metacharacters to alter the intended command and introduce attacker-specified commands.
Why this happens
The underlying issue maps to CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection').
The set_upgrade function treats user-supplied fields associated with firmware updates as trusted and passes them to the operating system shell in a concatenated or template-based manner.
Without consistently applying input validation, character whitelisting, and safe command-construction APIs, shell metacharacters (such as separators, redirection operators, or command substitution syntax) embedded in these parameters can break out of the expected command context.
This pattern represents a classic OS command injection bug: user-controllable strings are allowed to directly influence the structure of shell commands instead of being constrained to data-only arguments.
Potential impact
- Execution of arbitrary OS commands on the router with the privileges of the upgrade process (often root).
- Installation of persistent malware or backdoors on the device.
- Full compromise of router configuration, including credentials, VPN settings, and Wi-Fi keys.
- Use of the compromised router as a pivot point into internal networks or for traffic interception.
- Enrollment of devices into botnets or use for distributed denial-of-service (DDoS) attacks.
- Tampering with firmware upgrade behavior, preventing security updates or forcing malicious firmware.
General mitigation guidance
Effective mitigation focuses on eliminating direct shell construction from user-controlled input and enforcing strict trust boundaries around upgrade parameters.
Recommended patterns include:
- Avoid shell concatenation: Use system APIs that pass arguments as structured arrays rather than building command strings. For example, invoke upgrade tools via exec-style calls where each parameter is a separate, non-interpreted argument.
- Strict input validation: Constrain parameters such as URLs, versions, hash types, and upgrade types to well-defined formats (e.g., URL parsers, version regexes, enumerated hash algorithms) and reject any unexpected characters or patterns.
- Contextual encoding/escaping: Where shell invocation cannot be avoided, apply rigorous escaping and quoting aligned with the specific shell semantics, and ensure that no metacharacters or command separators can be introduced.
- Least-privilege execution: Run upgrade-related processes with the minimum privileges necessary and isolate them from the rest of the system through sandboxing or compartmentalization where feasible.
- Defensive configuration design: Treat all web-facing or remotely supplied upgrade parameters as untrusted by default and design interfaces so that administrators select from predefined options rather than entering free-form values wherever possible.
How teams detect issues like this
Detecting this kind of vulnerability typically involves a mix of code-centric and behavior-centric approaches:
- Static code analysis: Configure rules to flag direct use of user-controllable variables in shell commands, system calls, or command execution wrappers. Patterns include string concatenation around
system(), backticks, shell pipelines, or calls to shell interpreters. - Manual code review: During review of firmware upgrade and management interfaces, look for:
- Command construction that includes request parameters or configuration fields.
- Absence of centralized validation utilities or sanitization routines for upgrade-related inputs.
- Free-form text inputs that influence low-level operations such as downloads, hashing, and flashing.
- Security testing and fuzzing: Apply black-box or gray-box testing against management endpoints responsible for upgrades, varying parameters with shell metacharacters and monitoring for anomalous behavior or unexpected responses.
- Policy-driven checks in CI/CD: Incorporate security gates that enforce coding standards around command execution, disallowing new code that introduces shell invocations with interpolated user data without documented justification and safeguards.

