Thinkphp最新版本漏洞分析
环境Thinkphp6.0.12LTS(目前最新版本);
PHP7.3.4 。
安装composer create-project topthink/think tp6
测试代码

文章插图
漏洞分析漏洞起点不是__desturct就是__wakeup全局搜索下,起点在vendortopthinkthink-ormsrcModel.php
只要把this->lazySave设为True,就会调用了save方法 。

文章插图
【一>所有资源关注我,私信回复“资料”获取<一】跟进save方法,漏洞方法是updateData,但需要绕过①且让②为True,①调用isEmpty方法 。
1、网络安全学习路线
2、电子书籍(白帽子)
3、安全大厂内部视频
4、100份src文档
5、常见安全面试题
6、ctf大赛经典题目解析
7、全套工具包
8、应急响应笔记

文章插图
public function save(array $data = https://www.isolves.com/it/cxkf/yy/php/2022-02-28/[], string $sequence = null): bool{// 数据对象赋值$this->setAttrs($data);if ($this->isEmpty() || false === $this->trigger('BeforeWrite')) {return false;}$result = $this->exists ? $this->updateData() : $this->insertData($sequence);
跟进isEmpty方法,只要$this->data不为空就行 。
文章插图
$this->trigger方法默认返回就不是false,跟进updateData方法 。漏洞方法是checkAllowFields默认就会触发 。

文章插图
protected function updateData(): bool{// 事件回调if (false === $this->trigger('BeforeUpdate')) {return false;}$this->checkData();// 获取有更新的数据$data = https://www.isolves.com/it/cxkf/yy/php/2022-02-28/$this->getChangedData();if (empty($data)) {// 关联更新if (!empty($this->relationWrite)) {$this->autoRelationUpdate();}return true;}if ($this->autoWriteTimestamp && $this->updateTime) {// 自动写入更新时间$data[$this->updateTime]= $this->autoWriteTimestamp();$this->data[$this->updateTime] = $data[$this->updateTime];}// 检查允许字段$allowFields = $this->checkAllowFields();
跟进checkAllowFields方法,漏洞方法是db,默认也是会触发该方法,继续跟进 。
文章插图
protected function checkAllowFields(): array{// 检测字段if (empty($this->field)) {if (!empty($this->schema)) {$this->field = array_keys(array_merge($this->schema, $this->jsonType));} else {$query = $this->db();
跟进db方法,存在$this->table . $this->suffix字符串拼接,可以触发__toString魔术方法,把$this->table设为触发__toString类即可 。
文章插图
public function db($scope = []): Query{/** @var Query $query */$query = self::$db->connect($this->connection)->name($this->name . $this->suffix)->pk($this->pk);if (!empty($this->table)) {$query->table($this->table . $this->suffix);}
全局搜索__toString方法,最后选择vendortopthinkthink-ormsrcmodelconcernConversion.php类中的__toString方法 。跟进__toString方法,调用了toJson方法 。

文章插图
跟进toJson方法,调用了toArray方法,然后以JSON格式返回 。

文章插图
跟进toArray方法,漏洞方法是getAtrr默认就会触发,只需把$data设为数组就行 。

文章插图
public function toArray(): array{$item= [];$hasVisible = false;foreach ($this->visible as $key => $val) {if (is_string($val)) {if (strpos($val, '.')) {[$relation, $name]= explode('.', $val);$this->visible[$relation][] = $name;} else {$this->visible[$val] = true;$hasVisible= true;}unset($this->visible[$key]);}}foreach ($this->hidden as $key => $val) {if (is_string($val)) {if (strpos($val, '.')) {[$relation, $name]= explode('.', $val);$this->hidden[$relation][] = $name;} else {$this->hidden[$val] = true;}unset($this->hidden[$key]);}}// 合并关联数据$data = https://www.isolves.com/it/cxkf/yy/php/2022-02-28/array_merge($this->data, $this->relation);foreach ($data as $key => $val) {if ($val instanceof Model || $val instanceof ModelCollection) {// 关联模型对象if (isset($this->visible[$key]) && is_array($this->visible[$key])) {$val->visible($this->visible[$key]);} elseif (isset($this->hidden[$key]) && is_array($this->hidden[$key])) {$val->hidden($this->hidden[$key]);}// 关联模型对象if (!isset($this->hidden[$key]) || true !== $this->hidden[$key]) {$item[$key] = $val->toArray();}} elseif (isset($this->visible[$key])) {$item[$key] = $this->getAttr($key);} elseif (!isset($this->hidden[$key]) && !$hasVisible) {$item[$key] = $this->getAttr($key);
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 发型|五月流行发型推荐,这四种最火爆,剪完美美哒
- 十二生肖养什么植物最旺自己的财运
- 富翁选了胸部最大的那个,为什么?
- 红茶叶越小是最好的嘛,姜枣红糖茶的功效与作用
- 疾病最害怕的颜色竟是它
- 北京|上公厕引发近40人感染 北京最新规定:封控区不能两人以上同时如厕
- 局部肥胖该怎样减肥 科学方法最关键
- 最终幻想|国外推出爱丽丝蒂法等身人偶 1比1细节丰富超逼真
- 最好的圣诞礼物是什么
- 茶泡多久最佳时间泡多久