Summary
Totolink N300RH firmware 6.1c.1353_B20190305 contains an OS command injection flaw in the setUpgradeUboot function within upgrade.so, where the FileName argument is unsafely passed to the system shell.
A remote attacker who can reach the router's management interface may inject arbitrary shell commands, leading to full compromise of the device.
Affected context
This vulnerability occurs in the web management/upgrade functionality of the Totolink N300RH router (firmware 6.1c.1353_B20190305).
The issue is tied to how the setUpgradeUboot routine in upgrade.so handles the FileName parameter when initiating a bootloader or firmware-related upgrade.
It manifests in deployments where:
- The router's administrative HTTP/HTTPS interface is network-accessible, and
- The upgrade endpoint can be reached and invoked with attacker-controlled parameters, and
- Input is passed into a shell command without strict sanitization, escaping, or whitelisting.
Exploit preconditions
- Attack surface: The router's remote management interface / upgrade endpoint handling
setUpgradeUboot. - Required access: Ability to send crafted HTTP requests to the affected endpoint; in many setups this is limited to LAN access, but could be WAN-exposed if remote management is enabled or misconfigured.
- Trigger point: Submission of a request where the
FileNameparameter contains shell metacharacters or additional commands that the backend passes into an OS shell. - Why exploitation is possible: The implementation appears to concatenate the
FileNameargument into an OS command line without rigorous validation or proper escaping. This aligns with OS command injection conditions described in CWE-78, allowing untrusted data to alter the structure of a system command.
Why this happens
The core bug is the use of untrusted input as part of a system-level command string.
The setUpgradeUboot function takes the FileName argument supplied by the client and likely composes a shell command (for example, to manipulate or verify the upgrade file) using simple string concatenation.
Without strict input validation, context-aware escaping, or a parameterized execution API, shell metacharacters in FileName are interpreted by the shell, not as data but as control characters.
This behavior maps directly to CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), and is closely related to CWE-77: Command Injection, where external input can inject or modify commands executed by the host operating system.
Potential impact
- Execution of arbitrary OS commands on the router with the privileges of the web/upgrade process (often high or root-level on embedded devices).
- Persistent compromise of the router, including installation of custom startup scripts or backdoors.
- Interception, modification, or redirection of network traffic passing through the device.
- Use of the compromised router as part of a botnet for DDoS or other malicious campaigns.
- Lateral movement into internal networks by pivoting from the router to internal hosts.
General mitigation guidance
Effective mitigation focuses on eliminating the unsafe pattern of passing user-controlled data directly to the operating system shell:
- Avoid shell-based command composition: Replace calls that build command strings with APIs that execute binaries directly using argument arrays (e.g., exec-style calls) and do not invoke a shell interpreter.
- Strictly validate
FileNameand related parameters: Apply allowlist-based validation that only permits expected filename patterns (e.g., alphanumeric, fixed extensions, fixed directory), rejecting any input containing spaces, semicolons, pipes, or other shell metacharacters. - Separate data from control: When invoking system utilities, treat all user-supplied data as opaque arguments, never as part of the command template itself.
- Reduce privilege: Run the web/upgrade service with the least privileges required, in a constrained environment (e.g., chroot, containers, or restricted OS accounts) to limit impact if command execution occurs.
- Harden the management interface: Restrict access to the administrative interface to trusted networks, disable remote administration when not necessary, and require strong authentication and encryption to reduce exposure.
How teams detect issues like this
Detection can leverage both code-centric and deployment-centric approaches:
- Static analysis: Configure SAST tools or custom rules to flag:
- Direct or indirect use of
system(),popen(),popen2(),exec*()with"/bin/sh -c"or similar, when arguments are derived from HTTP parameters likeFileName. - String concatenation or formatting operations that mix user input with command templates.
- Manual code review: Focus reviews on:
- Firmware upgrade and configuration management modules.
- Any function that passes web-sourced input into OS commands, shell scripts, or busybox utilities.
- Runtime monitoring: Use logging and intrusion detection on network edges to:
- Identify suspicious requests to upgrade/administrative endpoints containing shell metacharacters (
;,|,&, backticks,$( )). - Monitor the router (where feasible) for unexpected process launches or outbound connections following management requests.
- Policy enforcement in development: Enforce internal coding standards that prohibit shell invocation with untrusted input, backed by automated checks in CI pipelines.

