内容简介:PHP知名开发框架Laravel,前几天在官方博客通报了一个高危SQL注入漏洞,这里简单分析下。首先,这个漏洞属于网站coding写法不规范,官方给了提示:
PHP知名开发框架Laravel,前几天在官方博客通报了一个高危 SQL 注入漏洞,这里简单分析下。
首先,这个漏洞属于网站coding写法不规范,官方给了提示:
但官方还是做了修补,升级 最新版本V5.8.7 可修复。
我们先定位下这里:
Illuminate\Validation\Rule
官方推荐的写法是:
Rule::unique('users')->ignore($id),
如果网站coding没有预先对$id的值做处理时,用户可以直接传递恶意数据给ignore函数,就会导致SQL注入。
我们来跟一下函数:
\Illuminate\Validation\Rules\Unique.php
class Unique
{
...
public function ignore($id, $idColumn = null)
{
if ($id instanceof Model) {
return $this->ignoreModel($id, $idColumn);
}
$this->ignore = $id;
$this->idColumn = $idColumn ?? 'id';
return $this;
}
这里我们不考虑把$id写成实例的情况,$id是用户可控的话,$idColumn直接写为空即可,最后赋值情况如下:
$this->ignore = $id; $this->idColumn = 'id';
如果网站代码类似这样构造的话,黑客输入的值就属于可控状态:
$id = $request->input('id');
最后我们会走到这儿:
Illuminate\Validation\Rules\Unique.php
public function __toString()
{
...
...
}
我们看下关键的代码变更:
Illuminate\Validation\Rules\Unique.php
V5.8.7【最新版】
public function __toString()
{
$this->ignore ? '"'.addslashes($this->ignore).'"' : 'NULL',
}
Illuminate\Validation\Rules\Unique.php
V5.8.4
public function __toString()
{
$this->ignore ? '"'.$this->ignore.'"' : 'NULL',
}
这里最新的代码v5.8.7,把$this->ignore直接给addslashes了,以前这里是没有防护的。
有趣的是,笔者对比了下diff,期间官方还试图对其他引用的地方进行过滤。最后还是在__toString处,进行了统一的过滤。
最后提一句,后面的代码会进入DatabaseRule,进行后续SQL规则匹配。
Illuminate\Validation\Rules\DatabaseRule.php
这之后就没有再进一步处理,接着形成了SQL注入。
阅读链接如下:
说明文档
*本文作者:dawner,转载请注明来自FreeBuf.COM
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Domain-Driven Design
Eric Evans / Addison-Wesley Professional / 2003-8-30 / USD 74.99
"Eric Evans has written a fantastic book on how you can make the design of your software match your mental model of the problem domain you are addressing. "His book is very compatible with XP. It is n......一起来看看 《Domain-Driven Design》 这本书的介绍吧!