• <bdo id="i4g44"></bdo>
    <code id="i4g44"><tr id="i4g44"></tr></code>
    <strike id="i4g44"></strike>
    <bdo id="i4g44"></bdo>

    為用戶創造價值的開發公司

    始終追求工匠精神,是您靠譜的H5開發、小程序開發、微信開發供應商

    藍暢首頁 >> 動態

    Thinkphp框架filter參數漏洞解析

    時間:2019-05-24 00:00:00 | 來源:


       

    漏洞介紹

    CNNVD編號:CNNVD-201812-489

    漏洞介紹鏈接

    noneCms github issue

    nonecms的作者通過升級 thinkphp 框架的版本把漏洞修復了

    查看 thinkphp/library/think/App.php 這個文件的修改歷史可以發現

    更新框架前是5.1.0

    const VERSION = '5.1.0';

    更新框架后是5.1.31

    const VERSION = '5.1.31 LTS';

    漏洞修復

    漏洞出現在 NoneCMS/thinkphp/library/think/route/dispatch/Url.php 文件中的parseUrl方法里

    1. // 解析模塊

    2. $module=$this->app->config('app_multi_module') ? array_shift($path) : null;

    3. if($this->param['auto_search']){

    4. $controller=$this->autoFindController($module, $path);

    5. }else{

    6. // 解析控制器

    7. $controller=!empty($path) ? array_shift($path) : null;

    8. }

    9. // 解析操作

    10. $action=!empty($path) ? array_shift($path) : null;

    11. // 解析額外參數

    12. if($path){

    13. if($this->app['config']->get('url_param_type')){

    14. $var+=$path;

    15. }else{

    16. preg_replace_callback('/(w+)|([^|]+)/', function($match)use(&$var){

    17. $var[$match[1]]=strip_tags($match[2]);

    18. }, implode('|', $path));

    19. }

    20. }

    為了修復漏洞,thinkphp官方添加了新的代碼

    1. if($this->param['auto_search']){

    2. $controller=$this->autoFindController($module, $path);

    3. }else{

    4. // 解析控制器

    5. $controller=!empty($path) ? array_shift($path) : null;

    6. }

    7. /**** 加入了這段代碼 ****

    8.        if ($controller && !preg_match('/^[A-Za-z](w|.)*$/', $controller)) {

    9.            throw new HttpException(404, 'controller not exists:' . $controller);

    10.        }

    11.        **** 加入了這段代碼 ****/

    12. // 解析操作

    13. $action=!empty($path) ? array_shift($path) : null;

    具體修改歷史可以在以下鏈接找到

    Url.php 修改歷史

    概括地說,就是把library/think/route/dispatch/Module.php 的代碼移動到 library/think/route/dispatch/Url.php

    $controller變量的校驗代碼經過多次改進之后,變成下面這個樣子

    1. if($controller&&!preg_match('/^[A-Za-z][w|.]*$/', $controller)){

    2. thrownewHttpException(404, 'controller not exists:' . $controller);

    3. }

    [A-Za-z][w|.]* 這個正則表達式的含義是 $controller 的第一個字符是字母A-Za-z。 [w|.] 匹配 a-zA-Z0-9_ 和 .。 例如可以匹配 a.b.abc123.., 所以嚴格來說, 這個正則表達式不是特別準確

    漏洞運行

    如果上面這段 $controller 變量的校驗代碼去掉并訪問下面類似的鏈接,就會復現之前的漏洞。

       http://xxx.com/NoneCms/public/?s=index/thinkRequest/input&filter=phpinfo&data=1

    這時候變量 $controller 等于 thinkRequest

    當執行到文件 NoneCMS/thinkphp/library/think/Request.php 中的代碼的時候, $filter = "phpinfo", $value = 1

    1. privatefunctionfilterValue(&$value, $key, $filters)

    2. {

    3. $default=array_pop($filters);

    4. foreach($filtersas$filter){

    5. if(is_callable($filter)){

    6. // 調用函數或者方法過濾

    7. $value=call_user_func($filter, $value);

    等于執行了以下代碼,這樣php運行環境的敏感信息就泄露了。適當構造URL參數就可以實現更多攻擊和破解操作。

    1. $filter="phpinfo";

    2. $value=1;

    3. call_user_func($filter, $value);

    總結

    1. 調用call_user_func函數時,要進行參數校驗。

    2. 對于 HTTP GET 請求里的參數盡可能使用嚴格的正則表達式進行校驗。


    本文轉自:http://blog.hexccc.com

    原文地址:http://blog.hexccc.com/thinkphp-filter-code-vulnerability/


    本文地址:
    更多內容推薦:
    專欄最新閱讀:
    更多文章閱讀請至:技術專欄
    Tips: 為您提供 微信開發H5開發微信小程序開發微信定制開發網站開發小程序商城開發SEO網站優化視頻后期制作等定制化開發服務
    主站蜘蛛池模板: 时尚| 古丈县| 宜春市| 拜泉县| 海兴县| 宕昌县| 嘉荫县| 沾化县| 尼勒克县| 尤溪县| 巧家县| 岚皋县| 苏尼特左旗| 德州市| 河南省| 嘉鱼县| 响水县| 南涧| 桂阳县| 攀枝花市| 栾城县| 普宁市| 米林县| 长岛县| 宕昌县| 合山市| 灵丘县| 嘉兴市| 惠安县| 商南县| 安吉县| 晋州市| 六安市| 紫阳县| 阳新县| 揭阳市| 广平县| 萨嘎县| 邯郸市| 仙游县| 松阳县|