Summary
GL-iNet GL-AR300M16 firmware v4.3.11 contains an OS command injection flaw in the enable_echo_server function, where the string port parameter is used unsafely in shell commands.
An attacker who can supply crafted input to this parameter may execute arbitrary system commands on the device with the privileges of the underlying service, leading to full compromise of the router.
Affected context
The vulnerability occurs in the router firmware of the GL-iNet GL-AR300M16 (version 4.3.11), specifically in logic that enables or configures an echo server.
The issue is present when user-controllable data (the port parameter) is passed to command-line utilities or shell execution routines without strict validation or escaping.
It is most relevant in deployments where management interfaces or APIs exposing the echo server functionality are reachable from untrusted networks, or where untrusted users can invoke the relevant configuration endpoint.
Exploit preconditions
- Attack surface: Network-accessible management interface, web UI, or API that invokes enable_echo_server.
- Required access: Ability to submit or influence the string port parameter (e.g., via HTTP request, RPC call, or configuration field).
- Trigger point: Invocation of enable_echo_server that builds and executes a shell command using the untrusted port input.
- Why exploitation is possible: The port parameter is treated as a trusted string and concatenated into a shell command without adequate sanitization, quoting, or use of safe command execution APIs, enabling injection of additional shell metacharacters and commands.
Why this happens
This issue is a classic OS Command Injection vulnerability as described by CWE-77.
The firmware code behind enable_echo_server appears to construct shell commands by directly concatenating the port parameter into a command string, which is then executed by a shell interpreter.
Because the input is not constrained to numeric port values and is not safely encoded or validated, an attacker can inject shell metacharacters (such as separators or redirection operators) that the shell interprets as additional commands.
The abstract insecure pattern is: untrusted input → interpolated into command string → executed by shell, rather than using strict parameterization or non-shell APIs.
Potential impact
- Execution of arbitrary system commands on the GL-AR300M16 device
- Installation of persistent malware or backdoors on the router
- Full compromise of router configuration, including network credentials and keys
- Interception, modification, or redirection of user traffic passing through the device
- Use of the device as a pivot point for attacks against internal networks
- Enrollment of the router into botnets or participation in distributed attacks
General mitigation guidance
Effective mitigation focuses on removing the dependency on shell-based command construction and constraining input to safe, expected formats:
- Replace shell command construction with direct API calls or system libraries that configure services without invoking a shell.
- Treat the port parameter as strictly numeric: enforce type checks, range checks, and reject any non-digit input before use.
- Where invoking external programs is unavoidable, use system calls that separate command and arguments into arrays (no shell) and avoid passing composite strings to a shell interpreter.
- Apply least-privilege principles so that services handling user input run with minimal permissions and limited access to the broader system.
- Harden management interfaces by restricting exposure to trusted networks, using strong authentication, and optionally isolating administrative functions from general user traffic.
How teams detect issues like this
Detection can combine code-centric and runtime approaches:
- Static analysis: Configure rules that flag calls to system(), popen(), exec*, or similar APIs where arguments contain user-controllable variables such as port, query, or parameter fields.
- Code review: Look for patterns where string concatenation or formatting is used to build shell commands, especially in request-handling or configuration code paths.
- Firmware and configuration audits: Regularly review router firmware code and scripts for shell invocations that rely on unvalidated input.
- Runtime monitoring: Enable logging for management interfaces and watch for anomalous port values or suspicious characters in parameters; network IDS/IPS signatures can help identify common command injection patterns.
- Automated SAST and firmware analysis platforms can be integrated into build pipelines to highlight command injection patterns early in development.

