zoukankan      html  css  js  c++  java
  • qibocms /hr/listperson.php File Arbitrarily Include Vul Via Variable Uninitialization && Front Page Upload WEBSHELL

    catalog

    1. 漏洞描述
    2. 漏洞触发条件
    3. 漏洞影响范围
    4. 漏洞代码分析
    5. 防御方法
    6. 攻防思考

    1. 漏洞描述

    Relevant Link:
    2. 漏洞触发条件

    1. 找到前台文件上传点
    http://localhost/qibo/hy/choose_pic.php
    
    2. 上传后直接包含文件
    http://localhost/qibo/hr/listperson.php?FidTpl[list]=../upload_files/homepage/pic/0/xxxx/xxx.jpg
    
    3. Getshell


    3. 漏洞影响范围
    4. 漏洞代码分析

    /hr/listperson.php

    //获取标签内容
    //注意这里的$FidTpl 这里并没有初始化 导致黑客可以通过qibo的"模拟GPC注册机制"覆盖这个变量的值
    $template_file=getTpl("list_$fidDB[mid]",$FidTpl['list']);
    fetch_label_value(array('pagetype'=>'4','file'=>$template_file,'module'=>$webdb['module_id']));
    ..
    //包含文件
    require($template_file);

    继续跟进$template_file=getTpl("list_$fidDB[mid]",$FidTpl['list']);

    function getTpl($html, $tplpath = '')
    { 
        global $STYLE;
    
        //$tplpath是我们外部传入的,黑客可以通过变量覆盖控制
        if($tplpath && file_exists($tplpath))
        { 
            //如果文件存在,那么就直接return 
            return $tplpath;
        }
        elseif($tplpath && file_exists(Mpath.$tplpath))
        { 
            return Mpath.$tplpath; 
        }
        elseif(file_exists(Mpath . "template/$STYLE/$html.htm"))
        { 
            return Mpath."template/$STYLE/$html.htm"; 
        }
        else
        { 
            return Mpath."template/default/$html.htm"; 
        } 
    }

    回到/hr/listperson.php的require($template_file),return后就直接包含了该文件,程序没有对带包含的文件路径进行任何验证、限制,导致了可以直接包含任意格式、任意内容的文件
    Relevant Link:

    http://www.wooyun.org/bugs/wooyun-2014-081470


    5. 防御方法

    0x1: 任意文件包含注入点防御

    /hr/listperson.php

    /* */
    if (!empty($FidTpl['list'])) 
    {
        unset($FidTpl['list']);
    } 
    /**/
    $template_file=getTpl("list_$fidDB[mid]",$FidTpl['list']);
    fetch_label_value(array('pagetype'=>'4','file'=>$template_file,'module'=>$webdb['module_id']));

    0x2: 前台任意文件上传点防御

    /hy/choose_pic.php

    if($action=='upload')
    { 
        if(is_uploaded_file($_FILES[postfile][tmp_name]))
        { 
            $array[name]=is_array($postfile)?$_FILES[postfile][name]:$postfile_name;
            $title=$title?$title:$array[name];
            $myname_str=explode(".",strtolower($array[name]));
            $myname=$myname_str[(count($myname_str)-1)];
            if(!in_array($myname,array('gif','jpg'))) $msg="{$array[name]}图片只能是gif或者jpg的格式";  
        ..

    这个文件是前台提供用户上传图片之用,程序本身对文件扩展名做了限制(gif、jpg),作为防御方来说,对文件内容进行PHP代码检测意义不大,因为本身gif、jpg格式图片是不能被WEB Server执行的,只有存在其他文件inlcude包含漏洞的时候,图片文件中的PHP代码才能被引入执行,因此,我们只要堵住文件include包含漏洞就可以了


    6. 攻防思考

    Copyright (c) 2015 LittleHann All rights reserved

  • 相关阅读:
    ASP.Net MVC的一个开源框架
    MS CRM 2011 RC中的新特性(8)
    在.NET4中用 jQuery 调用 WCF
    Web打印的在线设计
    MVC3.0RTM版本
    手机刷卡二维码
    Jla框架
    微软Windows Azure Platform技术解析
    缓存应用Memcached分布式缓存简介
    领域驱动设计(DDD)的理论知识
  • 原文地址:https://www.cnblogs.com/LittleHann/p/4705280.html
Copyright © 2011-2022 走看看