PHPCMS v9.1.13 任意文件读取漏洞分析
触发漏洞的 URL:
/index.php?m=search&c=index&a=public_get_suggest_keyword&url=test&q=../../phpsso_server/caches/configs/database.php
我将 public_get_suggest_keyword 作为关键字在源码中查找:
grep -H -n -R "public_get_suggest_keyword" *
在 modules/search/index.php 的第 198 行找到该函数的定义了:
public function public_get_suggest_keyword() {
$url = $_GET['url'].'&q='.$_GET['q'];
$res = @file_get_contents($url);
if(CHARSET != 'gbk') {
$res = iconv('gbk', CHARSET, $res);
}
echo $res;
}
漏洞出现在传递给 file_get_contents 函数的 $url 变量上,该函数可以获得指定文件的内容,因为 $url 是个受控变量,且未做过滤,因此可以直接读取指定文件内容。
在新版本中该函数已经修复:
public function public_get_suggest_keyword() {
$url = $_GET['url'].'&q='.$_GET['q'];
$trust_url = array('c8430fcf851e85818b546addf5bc4dd3');
$urm_md5 = md5($url);
// 做了白名单判断
if (!in_array($urm_md5, $trust_url)) exit;
$res = @file_get_contents($url);
if(CHARSET != 'gbk') {
$res = iconv('gbk', CHARSET, $res);
}
echo $res;
}