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

    為用戶創(chuàng)造價值

    始終追求工匠精神,是您靠譜的H5開發(fā)、小程序開發(fā)、微信開發(fā)供應(yīng)商

    Thinkphp框架filter參數(shù)漏洞解析

    2019-05-24 00:00:00 來源:Infocode藍暢


       

    漏洞介紹

    CNNVD編號:CNNVD-201812-489

    漏洞介紹鏈接

    noneCms github issue

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

    查看 thinkphp/library/think/App.php 這個文件的修改歷史可以發(fā)現(xiàn)

    更新框架前是5.1.0

    const VERSION = '5.1.0';

    更新框架后是5.1.31

    const VERSION = '5.1.31 LTS';

    漏洞修復(fù)

    漏洞出現(xiàn)在 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. // 解析額外參數(shù)

    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. }

    為了修復(fù)漏洞,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變量的校驗代碼經(jīng)過多次改進之后,變成下面這個樣子

    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 變量的校驗代碼去掉并訪問下面類似的鏈接,就會復(fù)現(xiàn)之前的漏洞。

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

    這時候變量 $controller 等于 thinkRequest

    當執(zhí)行到文件 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. // 調(diào)用函數(shù)或者方法過濾

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

    等于執(zhí)行了以下代碼,這樣php運行環(huán)境的敏感信息就泄露了。適當構(gòu)造URL參數(shù)就可以實現(xiàn)更多攻擊和破解操作。

    1. $filter="phpinfo";

    2. $value=1;

    3. call_user_func($filter, $value);

    總結(jié)

    1. 調(diào)用call_user_func函數(shù)時,要進行參數(shù)校驗。

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


    本文轉(zhuǎn)自:http://blog.hexccc.com

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


     
    上一篇:什么是CDN加速?為什么要給客戶做CDN加速
    下一篇:服務(wù)器選Linux還是 Windows?

    相關(guān)閱讀推薦:

    什么是雙機熱備?雙機熱備的解決方案

    什么是負載均衡?負載均衡在什么情況下使用

    教您正確識別百度蜘蛛

    服務(wù)器選Linux還是 Windows?

    什么是CDN加速?為什么要給客戶做CDN加速

    什么是SSL安全證書?為什么要安裝SSL證書?

    Tips: 專業(yè)提供H5開發(fā)、小程序開發(fā)、微信開發(fā)、網(wǎng)站開發(fā)APP開發(fā)、SEO優(yōu)化、以及產(chǎn)品規(guī)劃和安全運維服務(wù)
    主站蜘蛛池模板: 庆元县| 星子县| 沙洋县| 石渠县| 大城县| 尖扎县| 京山县| 澄城县| 图们市| 永福县| 洛扎县| 甘泉县| 汉川市| 宜昌市| 百色市| 汤原县| 金湖县| 敦化市| 越西县| 淮安市| 获嘉县| 维西| 班玛县| 岢岚县| 元阳县| 塘沽区| 沾益县| 黎城县| 阿拉善盟| 大理市| 黄山市| 鄂托克前旗| 淮北市| 德昌县| 北川| 大田县| 金沙县| 威信县| 乌拉特前旗| 万载县| 梓潼县|