Severity:

HIGH RISK

(7.3)

OS Command Injection in Totolink N300RH CGI Wi-Fi WPS

CVE-2026-3696

Analyzed

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-77, CWE-78

Impact:

Remote Code Execution on Network Router

Severity:

HIGH RISK

(7.3)

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 setWiFiWpsConfig function of the /cgi-bin/cstecgi.cgi CGI handler.

A remote attacker can send crafted HTTP requests to inject and execute arbitrary system commands with the router's privileges when Wi-Fi WPS configuration parameters are processed.

Affected context

This vulnerability arises in the web-based management interface of the Totolink N300RH router when processing Wi-Fi WPS configuration changes through the CGI handler.

It is relevant in deployments where:

  • The administrative web interface is reachable over the network (LAN, and especially if exposed to WAN).
  • The /cgi-bin/cstecgi.cgi endpoint is accessible and processes WPS-related parameters.
  • User-supplied values are passed to underlying system utilities without robust sanitization or escaping.

The risk increases significantly if the router's management interface is accessible from untrusted networks.

Exploit preconditions

  • Attack surface: HTTP-based management interface (/cgi-bin/cstecgi.cgi) on the Totolink N300RH router.
  • Required access: Ability to reach the router's web interface over the network; depending on configuration, this may or may not require authentication.
  • Trigger point: Submission of a specially crafted request invoking the setWiFiWpsConfig action with malicious parameter values.
  • Why exploitation is possible: The CGI handler appears to concatenate user-controlled input into a shell command or pass it to a system call without proper validation and escaping, enabling injection of additional shell metacharacters and commands.

Why this happens

The underlying issue aligns with CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

The setWiFiWpsConfig function in the CGI handler likely takes HTTP parameters (e.g., WPS-related configuration values), and passes them directly to system-level utilities (such as shell scripts or binaries) via shell-based invocation (e.g., system(), popen(), or equivalent).

Because these values are not adequately sanitized, filtered, or parameterized, shell metacharacters (like ;, &&, |, etc.) within user input are interpreted as part of the command line, allowing attackers to append or replace commands.

This reflects a broader insecure pattern where web management code on embedded devices trusts input from the network and constructs shell commands by string concatenation instead of using safer APIs or strict validation.

Potential impact

  • Execution of arbitrary system commands on the router with the privileges of the web/CGI process (often root on embedded devices).
  • Complete compromise of router configuration, including DNS, routing, and firewall rules.
  • Interception, modification, or redirection of users' network traffic (e.g., man-in-the-middle attacks).
  • Use of the router as a foothold for further attacks inside the local network.
  • Enrollment of the device into botnets for distributed denial-of-service (DDoS) or other malicious activities.
  • Persistent installation of malware or backdoors on the router firmware or filesystem.

General mitigation guidance

Effective mitigation focuses on eliminating direct command construction with user input and applying strong input handling around configuration endpoints:

  • Replace shell-based command construction with calls to dedicated APIs or system libraries that do not invoke a shell, passing parameters as typed arguments instead of concatenated strings.
  • Apply strict allow-list validation to configuration parameters: accept only expected characters, lengths, and formats for WPS-related fields, rejecting or normalizing anything else.
  • Ensure any remaining interaction with the shell uses robust escaping and quoting mechanisms, and avoid passing composite strings that mix static and dynamic content.
  • Reduce the privileges of CGI or web management processes so that, if compromised, the impact is constrained (least-privilege execution).
  • Restrict exposure of the management interface, limiting access to trusted networks and disabling remote (WAN) administration when not strictly required.
  • Design web management handlers to be idempotent and simple, avoiding unnecessary complexity or indirect shell pipelines for configuration changes.

How teams detect issues like this

Detection efforts can combine code-centric review with runtime monitoring:

  • Static analysis: Configure SAST rules to flag uses of functions such as system, popen, exec*, or equivalent where arguments contain data derived from HTTP parameters or other untrusted sources, especially in CGI or router management code.
  • Code review: Inspect CGI handlers for patterns of string concatenation used to build shell commands, particularly in configuration functions like setWiFiWpsConfig. Look for missing input validation, lack of allow-lists, and absent escaping routines.
  • Configuration and policy checks: Enforce development policies that prohibit direct shell invocation from web handlers, or require explicit security review for any such usage.
  • Runtime monitoring: Analyze router logs (if available) for anomalous command execution patterns or unexpected processes spawned by the web server or CGI engine.
  • Fuzzing and dynamic testing: Use HTTP fuzzers to send malformed or command-like payloads to configuration endpoints and observe responses or side effects in a controlled environment.

Sources

SourceLink
github.comgithub.com/JXBbozaihuang/vuln-research/issues/2
vuldb.comvuldb.com/?ctiid.349642
vuldb.comvuldb.com/?id.349642
vuldb.comvuldb.com/?submit.765681
totolink.nettotolink.net/

Frequently asked

questions

Yes. As long as an attacker can reach the router's web management interface and interact with the vulnerable CGI endpoint, they can attempt exploitation over the network. The actual exposure depends on whether the interface is limited to the local network or exposed over the internet.

It depends on how the device is configured and how the vulnerable handler enforces access control. In many embedded web interfaces, some configuration endpoints may be insufficiently protected or share credentials that are left at defaults, lowering the effective barrier to exploitation.

The most robust fix is to remove all shell-based command construction from CGI handlers and instead call lower-level system APIs with strictly validated parameters. Combine this with strong input allow-lists for each configuration field and apply least-privilege principles to the web process.

Adopt secure coding standards that forbid passing untrusted input to shells, use automated static analysis during development, and perform security-focused code reviews on all web management components. Architect router management functions around safe, parameterized APIs rather than shell scripts, and limit external exposure of administrative interfaces by default.

Find out what's already
exploitable in your codebase.