Vulnerability Title: Command Injection Vulnerability in LightSensorControl Parameter in D-Link DCS700l v1.03.09

Discovered by: tzh00203

Contact Information: [email protected]

Affected Version: DCS700l v1.03.09 (and possibly earlier versions)

Component: Web Form Handler for Day/Night Mode (setDayNightMode)


1. Vulnerability Overview

A Command Injection vulnerability has been discovered in the LightSensorControl parameter of D-Link DCS700l v1.03.09. The vulnerability arises from improper handling of user-controlled input, which is passed directly into a system command without sufficient sanitization. The LightSensorControl parameter is incorporated into a shell command (gpio lightcontrol %s &), and an attacker can manipulate it to inject arbitrary shell commands. This allows remote execution of malicious commands on the device, potentially compromising its integrity, leaking sensitive information, and facilitating further attacks. The lack of input validation and sanitization makes the device susceptible to malicious input exploitation.


2. Detailed Description

The Command Injection Vulnerability in D-Link DCS700l v1.03.09 exists in the LightSensorControl parameter handling, specifically in how user-supplied input is incorporated into system commands without proper sanitization. The issue arises from improper validation of the input passed to the system command (gpio lightcontrol %s &), which allows attackers to inject arbitrary shell commands.

The core issue lies in the sub_4298C0() function and how it processes the LightSensorControl parameter without filtering special characters like ;, &, or |, leading to the execution of malicious commands.

image.png

Although the input parameters are subject to preliminary validation through the CheckDayNightVar() routine, this validation is insufficient to prevent command injection. Specifically, the LightSensorControl parameter is checked using websGetVarCheck() and checklongrange(), which only enforce numeric type and range constraints (e.g., values between 0 and 11). These checks merely verify whether the input can be parsed as a valid integer and fall within an expected range, but they do not sanitize or filter shell metacharacters such as ;, &, |, or backticks.

As a result, even after passing all validation steps, the value of LightSensorControl is still directly concatenated into a shell command string and executed via the system() call in sub_4298C0(). Since no escaping or strict whitelisting is applied during command construction, an attacker can inject additional shell commands, leading to arbitrary command execution on the device.

image.png

The intermediate validation functions, such as CheckDayNightVar(), websGetVarCheck(), and checklongrange(), mainly ensure that input values are of the correct data type and within expected ranges. For example, CheckDayNightVar() verifies the presence and basic validity of parameters like LightSensorControl, while checklongrange() checks if numeric inputs fall within specified limits. However, these functions do not sanitize the input for special characters like ;, &, or |, which are often used in command injection attacks. As a result, while the input is validated for type and range, it is still directly passed into system commands without filtering, leaving the device vulnerable to arbitrary command execution.

image.png

The back-end code lacks proper input validation and sanitization for the LightSensorControl parameter. The value of this parameter is directly incorporated into a shell command (gpio lightcontrol %s &) without checking for malicious characters, making it vulnerable to command injection attacks. An attacker could manipulate the LightSensorControl parameter to inject arbitrary shell commands, potentially leading to remote code execution on the device. Proper input validation and sanitization are needed to prevent such vulnerabilities.

image.png