Summary
Ruijie EG105G-P 2.340 contains a command injection vulnerability in the JSON-RPC diagnose endpoint, specifically within the nslookup function.
By manipulating the params.target argument, a remote attacker can inject system commands through the web interface and execute them with the router's backend privileges.
Affected context
The vulnerability exists in the web-based management interface of the Ruijie EG105G-P 2.340 firmware, within the /cgi-bin/luci/api/diagnose JSON-RPC endpoint that exposes diagnostic functionality such as nslookup.
It becomes relevant when the device's management interface is reachable over the network (typically LAN, but sometimes WAN if exposed) and the endpoint processes user-supplied parameters without adequate sanitization or command separation.
This issue is tied to the way user input is incorporated into shell commands, not to any specific deployment topology, though exposure is higher when the interface is accessible from untrusted networks.
Exploit preconditions
- Attack surface: HTTP/HTTPS access to the router's web management API at
/cgi-bin/luci/api/diagnose. - Required access: Network reachability to the management interface; depending on configuration, this may require local network access or, if exposed, be reachable from the internet.
- Trigger point: Invocation of the
nslookupJSON-RPC method with a craftedparams.targetvalue that introduces shell metacharacters or injected command segments. - Why exploitation is possible: User-controlled data is inserted into a shell command line without proper validation, encoding, or argument separation, allowing the attacker to break out of the intended command and execute arbitrary system commands under the router's backend context.
Why this happens
The flaw stems from constructing shell commands by concatenating user-controlled input into a command string and delegating execution to the system shell.
Instead of treating params.target as a strict, validated hostname or IP address, the implementation likely passes it directly to an underlying command such as nslookup via a shell, enabling interpretation of metacharacters (;, &&, |, etc.).
This behavior maps to CWE-77: Improper Neutralization of Special Elements used in a Command, and also relates to CWE-74, where special characters are insufficiently neutralized in the generated command-line context.
At an abstract level, the pattern is: user input → string concatenation into a shell command → execution with elevated privileges and no robust input normalization or confinement.
Potential impact
- Remote attackers may execute arbitrary system commands on the router.
- Attackers could modify or exfiltrate router configuration and sensitive network information.
- The device could be converted into a foothold for further attacks on internal network hosts.
- Malicious actors can install persistent malware or participate in botnets and DDoS campaigns.
- Network traffic routing, DNS, or firewall rules may be altered, impacting availability and integrity.
General mitigation guidance
Effective mitigation focuses on removing the dependency on shell interpretation for user-supplied parameters and constraining diagnostic features.
Recommended defensive patterns include:
- Avoid building shell command strings from user input; instead, call diagnostic utilities via safe APIs or libraries that pass arguments as arrays without invoking a shell.
- Apply strict allow-list validation to target parameters, accepting only valid hostnames or IP addresses and rejecting any unexpected characters or formats.
- Normalize and encode input before use in any system interaction, ensuring special shell metacharacters are never interpreted.
- Run web and diagnostic components with least-privilege accounts and restrict system capabilities so that, even if command execution occurs, the impact is narrowed.
- Minimize exposure of management endpoints by placing them behind VPNs or management networks and disabling unnecessary diagnostic APIs when not needed.
How teams detect issues like this
Detection involves a combination of code-centric and operational approaches:
- Static analysis: Flag any occurrence where HTTP/JSON-RPC parameters are concatenated into strings passed to
system(),popen(), backticks, or similar shell-executing primitives, especially around diagnostic utilities likenslookup,ping, andtraceroute. - Code review: During manual review, pay special attention to diagnose or "test connectivity" endpoints, checking that all user inputs are strictly validated and passed as safe arguments rather than raw shell fragments.
- Runtime monitoring: Implement logging and anomaly detection for unusual command-line invocations originating from web processes, including commands containing unexpected separators, redirections, or chained utilities.
- Security testing: Use automated web security scanners and fuzzers to probe diagnostic endpoints for signs of command injection, supported by internal CI pipelines that include these tests on each firmware or software build.

