Heim  >  Artikel  >  Backend-Entwicklung  >  PHP 小心urldecode引发的SQL注入漏洞_PHP教程

PHP 小心urldecode引发的SQL注入漏洞_PHP教程

WBOY
WBOYOriginal
2016-07-21 15:23:20977Durchsuche

Ihipop 学校的 Discuz X1.5 论坛被黑,在那里吵了一个下午。Google 一下“Discuz! X1-1.5 notify_credit.php Blind SQL injection exploit”,你就知道。

Discuz 是国内很流行的论坛系统,被黑的网站应该会很多吧。不过我对入侵别人的网站不感兴趣,同时也鄙视那些代码都不会写只会使用别人放出的工具攻击的所谓的“黑客”。


粗略看了一下代码,这个 SQL 注入漏洞是 urldecode 函数造成的。在 PHP 手册中,urldecode 函数下面有一个警告:

The superglobals $_GET and $_REQUEST are already decoded. Using urldecode() on an element in $_GET or $_REQUEST could have unexpected and dangerous results.

而 Discuz 的开发人员(估计是新手)画蛇添足,多加了一个 urldecode:

复制代码 代码如下:

foreach($_POST as $k => $v) {
$value = urldecode($v);
$this->setParameter($k, $value);
}

单引号被 urlencode 两次以后是 %2527,然后 POST,PHP 内部在生成全局变量 $_POST 的时候会先 urldecode,得到 %27,然后 PHP 会检查 Magic Quotes 的设置,但是无论是否开启 Magic Quotes,%27 都不会被 addslashes,因为这时根本没有单引号。但是这时如果你在 PHP 代码中画蛇添足的加上 urldecode,%27就变成单引号了,然后……你懂的。

在我初学 PHP 的时候,看的是学校图书馆的一本烂书,里面根本就没写 PHP 在处理表单的时候会自动 urldecode,所以自己用 urldecode 函数来解码(依稀记得书上好像也是这么写的,真是误人子弟啊)。

总结一下,就是:1、选择一本好书非常重要;2、慎用 urldecode 函数。3、注意 PHP 手册中的警告。
原文来自 http://demon.tw/programming/php-urldecode-sql-injection.html

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/324509.htmlTechArticleIhipop 学校的 Discuz X1.5 论坛被黑,在那里吵了一个下午。Google 一下“Discuz! X1-1.5 notify_credit.php Blind SQL injection exploit”,你就知道。 Discuz 是国...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn