Severity:

CRITICAL RISK

(9.8)

OS Command Injection in Totolink N300RH Web Management

CVE-2026-3301

Analyzed

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-77, CWE-78

Impact:

Remote Code Execution on Network Router

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Totolink N300RH firmware 6.1c.1353_B20190305 contains an OS command injection vulnerability in the setWebWlanIdx function exposed via /cgi-bin/cstecgi.cgi in the web management interface.

By supplying crafted input to the webWlanIdx parameter, a remote attacker can inject and execute arbitrary system commands on the router, enabling full compromise of the device.

Affected context

This vulnerability exists in the HTTP-based web management interface of Totolink N300RH routers running firmware 6.1c.1353_B20190305.

It is triggered when the setWebWlanIdx handler in /cgi-bin/cstecgi.cgi processes the webWlanIdx parameter and passes it into system-level command execution without robust sanitization or strict parameter handling.

The issue is most relevant when the web interface is reachable from untrusted networks (e.g., WAN exposure, poorly segmented LANs, or compromised local clients).

Exploit preconditions

  • Attack surface: HTTP(S) endpoint /cgi-bin/cstecgi.cgi on the router's web management interface.
  • Required access: Network-level access to the management interface; authentication requirements depend on the router's configuration (e.g., default or weak credentials, or misconfigured access control could lower the bar).
  • Trigger point: An HTTP request invoking the setWebWlanIdx functionality with a malicious webWlanIdx parameter value.
  • Why exploitation is possible: The parameter value is incorporated into an OS command or shell call without proper neutralization of command metacharacters, allowing attacker-controlled text to alter the command structure and execute arbitrary instructions.

Why this happens

The underlying bug is a classic OS command injection pattern mapped to CWE-78: Improper Neutralization of Special Elements used in an OS Command.

Application logic in the setWebWlanIdx handler appears to build or pass shell commands using user-controlled data from the webWlanIdx parameter.

Instead of treating the parameter as data with strict validation and escaping, the implementation likely concatenates or directly embeds it into a command line or passes it to a shell interpreter.

This insecure pattern allows special characters (such as command separators, redirection operators, or subshell syntax) to be interpreted by the OS, resulting in execution of attacker-specified commands under the router's process privileges.

Potential impact

  • Remote execution of arbitrary system commands on the router.
  • Complete compromise of the device configuration and firmware integrity.
  • Interception, modification, or redirection of network traffic traversing the router.
  • Use of the router as a foothold for lateral movement within the local network.
  • Enrollment of the device into botnets for DDoS or other coordinated attacks.
  • Persistent installation of backdoors or spyware on the network gateway.

General mitigation guidance

Effective mitigation focuses on eliminating direct shell command construction from user input and narrowing the trust boundary around management parameters:

  • Replace shell-based invocation with safe, parameterized system APIs or library calls that do not invoke a command interpreter.
  • Enforce strict allowlist validation for webWlanIdx and similar parameters, limiting values to expected formats (e.g., integer indices or predefined identifiers).
  • Apply robust input normalization and neutralization for any data that must eventually reach OS-level operations, ensuring command metacharacters are rejected early.
  • Run web management components with least-privilege accounts and minimal OS capabilities to reduce impact if command execution occurs.
  • Restrict external exposure of the web management interface (e.g., disable WAN management, segment admin networks, require VPN or out-of-band access).
  • Design firmware and configuration flows so that management interfaces are secure-by-default with hardened authentication and access control.

How teams detect issues like this

Detection typically combines code-centric review with runtime monitoring:

  • Static analysis: Scan firmware and CGI code for patterns where HTTP parameters (such as webWlanIdx) flow into APIs like system, popen, exec*, or shell utilities, especially when concatenated into strings.
  • Code review signals: Look for ad-hoc command building, string-based shell calls, and absence of explicit validation or allowlists on management parameters.
  • Policy enforcement: Adopt secure coding standards for embedded web interfaces that forbid direct shell invocation using user-controlled data and require peer review of any OS interaction code.
  • Dynamic analysis: Use web application scanners or fuzzing frameworks targeting router management endpoints to identify input fields that alter command behavior or generate anomalous responses.
  • Runtime monitoring: Where feasible, monitor router logs and network traffic for unusual outbound connections, repeated access to /cgi-bin/cstecgi.cgi, or payloads containing shell metacharacters.

Sources

SourceLink
github.comgithub.com/xyh4ck/iot_poc/blob/main/TOTOLINK/N300RHv4/01_setWebWlanIdx_RCE/README.md
vuldb.comvuldb.com/?ctiid.348052
vuldb.comvuldb.com/?id.348052
vuldb.comvuldb.com/?submit.761297
totolink.nettotolink.net/

Frequently asked

questions

Yes. An attacker with network access to the router's web management interface can remotely trigger the vulnerable setWebWlanIdx endpoint. If the interface is exposed to the internet or reachable from compromised internal hosts, remote exploitation is feasible.

The attacker needs the ability to send HTTP requests to /cgi-bin/cstecgi.cgi. Depending on configuration, they may also need valid credentials, but weak, default, or reused passwords can effectively reduce this requirement.

Remove any reliance on shell command construction using user input. Replace such logic with parameterized, non-shell system calls, enforce strict allowlists on management parameters, and ensure all OS-level operations are performed with minimal privileges.

Adopt secure coding practices for embedded web interfaces: prohibit direct shell calls with untrusted data, standardize input validation and canonicalization, conduct security-focused code reviews, and integrate static analysis and security testing into the firmware development lifecycle.

Find out what's already
exploitable in your codebase.