zzzphp V1.6.0 的代碼執行漏洞,模版解析功能的問題

zzzphp V1.6.0 的代碼執行漏洞,模版解析功能的問題
0 基礎支撐功能
0.1 路由功能
0.2 模版解析
程序解析模版時,將模版中的部分內容匹配出來直接傳遞給了eval,且沒有經過過濾

    public
    function parserIfLabel($zcontent)
    {
        $pattern = '/\{if:([\s\S]+?)}([\s\S]*?){end\s+if}/';
        if (preg_match_all($pattern, $zcontent, $matches)) {
            $count = count($matches[0]);
            for ($i = 0; $i < $count; $i++) {
                $flag = '';
                $out_html = '';
                $ifstr = $matches[1][$i];
                $ifstr = str_replace('<>', '!=', $ifstr);
                $ifstr = str_replace('mod', '%', $ifstr);
                $ifstr1 = cleft($ifstr, 0, 1);
                switch ($ifstr1) {
                    case '=':
                        $ifstr = '0' . $ifstr;
                        break;
                    case '{':
                    case '[':
                        $ifstr = "'" . str_replace("=", "'=", $ifstr);
                        break;
                }
                $ifstr = str_replace('=', '==', $ifstr);
                $ifstr = str_replace('===', '==', $ifstr);
                @eval('if(' . $ifstr . '){$flag="if";}else{$flag="else";}');
                if (preg_match('/([\s\S]*)?\{else\}([\s\S]*)?/', $matches[2][$i], $matches2)) { // 判斷是否存在else
                    switch ($flag) {
                        case 'if': // 條件爲真
                            if (isset($matches2[1])) {
                                $out_html .= $matches2[1];
                            }
                            break;
                        case 'else': // 條件爲假
                            if (isset($matches2[2])) {
                                $out_html .= $matches2[2];

                            }
                            break;
                    }
                } elseif ($flag == 'if') {
                    $out_html .= $matches[2][$i];
                }

                // 無限極嵌套解析
                $pattern2 = '/\{if([0-9]):/';
                if (preg_match($pattern2, $out_html, $matches3)) {
                    $out_html = str_replace('{if' . $matches3[1], '{if', $out_html);
                    $out_html = str_replace('{else' . $matches3[1] . '}', '{else}', $out_html);
                    $out_html = str_replace('{end if' . $matches3[1] . '}', '{end if}', $out_html);
                    $out_html = $this->parserIfLabel($out_html);
                }

                // 執行替換
                $zcontent = str_replace($matches[0][$i], $out_html, $zcontent);
            }
        }
        return $zcontent;
    }

1 安裝
2 關於我們
3 查看列表
4 查看內容
5 查看品牌列表
6 查看品牌內容
7 留言
8 搜索
9 前臺驗證機制
9.1 註冊
9.2 登陸
9.3 找回密碼
10 會員中心
11 後臺登陸
12 後臺首頁
12.1 顯示統計信息
12.2 顯示系統狀態和cms狀態
12.3 安全提醒
12.4 顯示天氣
12.5 修改創始人資料
12.6 離開一會兒
12.7 安全退出
12.8 刪除全部
12.9 標籤管理
13 後臺關於我們
14 後臺新聞中心
15 後臺產品中心
16 後臺案例展示
17 後臺品牌列表
18 後臺聯繫我們
19 後臺內容管理
20 後臺欄目擴展
21 後臺模版管理
22 後臺靜態緩存
23 後臺文件管理
24 後臺用戶管理
25 後臺插件管理
26 後臺系統管理

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章