Skip to content
RCE Write-up Advanced

Popping Root on UniFi OS Server: Unauthenticated RCE Chain Detection & Analysis

Three flaws in UniFi OS Server chain together: an authentication gateway bypass using a mismatch between the raw and normalised request URI, a command injection in the package-update service, and an over-privileged service account with passwordless sudo. An unauthenticated attacker could run commands as root, read every stored secret, and forge admin sessions that survive patching.

bishopfox.com

Published on bishopfox.com

UniFi OS Server is Ubiquiti’s software distribution of UniFi OS, the management platform that fronts the UniFi family of applications (Network, Protect, and the identity and update services that ship with it). It runs as a collection of localhost-bound backend services behind a single Nginx front end that terminates…

The author, on bishopfox.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The authentication handler matched a public-route prefix against the raw, still-encoded request URI while Nginx routed on the normalised URI, so the two disagreed about which request was being handled.

Impact

An unauthenticated attacker could gain root on the management appliance, read all stored secrets including the token signing key, forge owner-level sessions that still work after patching, and potentially unlock doors, view or delete camera footage, and pivot to other sites via cloud tokens.

What the attacker needed

Network access to the admin interface; no credentials needed; no user interaction

The fix

It was fixed in UniFi OS Server 5.0.8, but exposed instances should also have all secrets rotated starting with the JWT signing key, and confirmed compromises should be rebuilt.

How it was found

  1. Send a request whose raw URI starts with the auth-exempt prefix but whose normalised form resolves to an internal proxy route.
  2. Observe that the internal backend answers with its own response instead of the gateway's 401.
  3. Reach the package-update route through the bypass and supply a package name containing shell metacharacters.
  4. Confirm execution with a time-based probe: a delayed 200 on the vulnerable build versus a fast 400 on the patched one.
  5. Use the service account's passwordless sudo on dpkg to install a package whose install script runs as root.
  6. Read a root-only file to confirm the script executed with root privileges.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

The appliance has a front door (a proxy) that checks whether a visitor is logged in before passing requests to the services behind it. The check looked at the address exactly as typed, while the proxy used a cleaned-up version of the same address to decide where to send it, so a crafted address could look public to the check but land on a private service. That private service then ran part of the request as a system command, and the account it ran as could switch to the all-powerful root user without a password.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.