Centreon <=2.5.3 'exec()' 函数远程命令执行漏洞分析
下面以centreon-2.5.3版本的源代码为例进行这个漏洞的简要分析:
.\centreon-2.5.3\www\index.php
125:
if (isset($_POST["submit"])
133:
$CentreonLog = new CentreonUserLog(-1, $pearDB);
160:
$centreonAuth = new CentreonAuthSSO($useralias, $password, $autologin, $pearDB, $CentreonLog, $encryptType, $token, $generalOptions);
说明:在Centreon首页进行登录的时候,是通过CentreonAuthSSO类进行用户认证的,同时注意是用CentreonUserLog类进行日志存储操作的,所以我们接下来看看CentreonAuthSSO类。
.\centreon-2.5.3\www\class\centreonAuth.SSO.class.php
5:
class CentreonAuthSSO extends CentreonAuth {
说明:CentreonAuthSSO类的父类是CentreonAuth,我们再接着看这个类。
.\centreon-2.5.3\www\class\centreonAuth.class.php
112:
$this->checkUser($username, $password, $token);
272~275:
if ($this->debug) {
$this->CentreonLog->insertLog(1, "No contact found with this login : '$username'");
}
$this->error = "Invalid user";
说明:在112行就是具体的检查用户是否合法的实现函数,当输入了一个不存在的用户同时又打开了调试选项的情况下,这时会把这次登录的具体错误信息通过之前提到的CentreonUserLog类的insertLog方法写入日志文件,因此接着我们就来看看这个insertLog方法是如何实现的。
.\centreon-2.5.3\www\class\centreonLog.class.php
82:
public function insertLog($id, $str, $print = 0, $page = 0, $option = 0)
105:
exec("echo \"".$string."\" >> ".$this->errorType[$id]);
说明:可以看到,漏洞在105行处出现了,这是一个很典型的注入类漏洞,因为$string变量是用户间接可控的,又因为注入到的函数是exec,所以这个注入将导致命令执行的问题。
后记:
其实修复这个漏洞也很简单,可以看看centreon-2.5.4的源代码,其中那行出现漏洞的代码以如下方式修复了:
file_put_contents($this->errorType[$id], $string . "\n", FILE_APPEND);