Summary
Totolink A7100RU routers contain an OS command injection vulnerability in the UploadOpenVpnCert CGI handler, where the FileName parameter is not safely handled.
A remote attacker can inject arbitrary shell commands via crafted requests to /cgi-bin/cstecgi.cgi, potentially achieving full system compromise of the device.
Affected context
This vulnerability occurs in the web management interface of Totolink A7100RU firmware version 7.4cu.2313_b20191024.
It affects deployments where:
- The router's HTTP/HTTPS management interface is network-accessible (from LAN or WAN, depending on configuration).
- The /cgi-bin/cstecgi.cgi endpoint is reachable and processes the UploadOpenVpnCert action.
- User-supplied FileName parameters are passed through to underlying shell or system utilities without strict sanitization or safe API usage.
Exploit preconditions
- Attack surface: HTTP(S) interface on the Totolink A7100RU router.
- Required access: Ability to reach the management port; depending on configuration, this might require LAN access or, if remote management is enabled or exposed, Internet access.
- Trigger point: A crafted request invoking the UploadOpenVpnCert function via /cgi-bin/cstecgi.cgi with a malicious FileName parameter.
- Why exploitation is possible: The CGI handler constructs or forwards shell commands that directly interpolate the FileName argument, allowing attackers to break out of expected input and execute arbitrary commands in the router's OS context.
Why this happens
The underlying issue is improper construction of shell commands using untrusted input within the CGI handler.
Instead of passing the FileName parameter through a safe API (such as fixed-argument exec/execve calls or file-handling functions), the code likely concatenates it into a shell command string or passes it through a command interpreter.
This aligns with CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), where meta-characters (such as ;, &, |) and other shell syntax are not neutralized.
It is closely related to CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection'), reflecting the broader pattern of treating user input as part of executable command text.
Potential impact
- Execution of arbitrary system commands on the router.
- Complete takeover of the device, including configuration changes and persistent backdoors.
- Interception, modification, or redirection of network traffic routed through the device.
- Use of the router as a platform for further attacks within the local network or against external targets.
- Disruption of network connectivity by altering firewall, routing, or DNS settings.
General mitigation guidance
Effective mitigation focuses on eliminating direct command interpretation of user input and minimizing the router's attack surface:
- Replace shell-based command construction with parameterized system calls or native library functions that do not invoke a shell.
- Strictly validate the FileName parameter using a positive (allowlist) pattern, limiting it to expected characters (e.g., alphanumerics, dots, and underscores) and known file extensions.
- Enforce canonicalization and path constraints to prevent directory traversal or unintended file paths.
- Run web and CGI components with least-privilege accounts and, where possible, with restricted access to system utilities.
- Disable or limit remote management and restrict access to the management interface to trusted networks only, reducing exposure even if a bug exists.
How teams detect issues like this
Detection typically involves both code-centric and environment-centric approaches:
- Static analysis: Look for CGI handlers or web modules that build shell command strings via string concatenation involving user-controlled parameters (e.g., FileName, filename, path, cmd).
- Code review: Flag any use of system(), popen(), exec* with shell strings, or equivalent wrappers, especially where arguments come from HTTP parameters without strict validation and encoding.
- Configuration review: Identify routers or appliances with exposed management interfaces accessible from untrusted networks (e.g., WAN exposure, UPnP misconfigurations).
- Runtime monitoring: Use network intrusion detection or web application firewalls to spot suspicious patterns in FileName or related parameters, such as shell metacharacters or chained commands.
- Automated security scanning tools can be configured with rules to detect OS command injection patterns in CGI handlers during firmware or source code assessment.

