public function Display()
{
global $gtmpfile;
extract($GLOBALS, EXTR_SKIP);
$this->WriteCache();
include $this->cacheFile;
}
进入 Display() 函数后,又要进入 WriteCache() 函数,继续跳转跟踪 WriteCache() 函数。
public function WriteCache($ctype = 'all')
{
if (!file_exists($this->cacheFile) || $this->isCache == false
|| (file_exists($this->templateFile) && (filemtime($this->templateFile) > filemtime($this->cacheFile)))
) {
if (!$this->isParse) {
//...
}
$fp = fopen($this->cacheFile, 'w') or dir("Write Cache File Error! ");
flock($fp, 3);
// E
$result = trim($this->GetResult());
$errmsg = '';
// F
if (!$this->CheckDisabledFunctions($result, $errmsg)) {
fclose($fp);
@unlink($this->cacheFile);
die($errmsg);
}
fwrite($fp, $result);
fclose($fp);
//...
}
WriteCache() 函数负责解析模板并写缓存文件,所以sourceString会在 WriteCache() 函数中的E处得到解析结果,GetResult() 函数会调用返回值sourceString来设置 $result 变量,然后$result变量会在F处被CheckDisabledFunctions()函数调用,跳转跟踪CheckDisabledFunctions() 函数
public function CheckDisabledFunctions($str, &$errmsg = '')
{
global $cfg_disable_funs;
// G
$cfg_disable_funs = isset($cfg_disable_funs) ? $cfg_disable_funs : 'phpinfo,eval,exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source,file_put_contents,fsockopen,fopen,fwrite';
// 模板引擎增加disable_functions
if (!defined('DEDEDISFUN')) {
$tokens = token_get_all_nl($str);
$disabled_functions = explode(',', $cfg_disable_funs);
foreach ($tokens as $token) {
if (is_array($token)) {
if ($token[0] = '306' && in_array($token[1], $disabled_functions)) {
$errmsg = 'DedeCMS Error:function disabled "' . $token[1] . '" <a target="_blank">more...</a>';
return false;
}
}
}
}
return true;
}
可以看到G处检查了是否存在禁止的函数,但是这里可以进行绕过,最后会回到A处拼接起来。