简体   繁体   English

magic_quotes_gpc会救我吗?

[英]Will magic_quotes_gpc save me from this?

There is a (ugly)project I was asked to help with by doing a specific task. 通过执行特定任务,我被要求帮助(丑陋)项目。 The thing is, I don't have any control over the other files in the site much less over the server configuration. 问题是,我对网站中的其他文件没有任何控制,更不用说服务器配置了。 Some data I'm going to use comes from a query like this: 我将要使用的一些数据来自这样的查询:

'SELECT * FROM table where value like "'.$unsafe.'"';

$unsafe is an unescaped value coming from $_POST or $_GET. $ unsafe是来自$ _POST或$ _GET的非转义值。 I checked the server, is PHP5.1.6 and has magic_quotes_gpc On so the data is being auto escaped. 我检查了服务器,是PHP5.1.6并且有magic_quotes_gpc On所以数据正在自动转义。 Is this query breakable? 这个查询是否易碎? Being $unsafe between colons gives me the impression It cant be broken but maybe I'm missing something. 冒号之间不安全给我的印象是它不能被打破,但也许我错过了一些东西。 I know magic_quotes_gpc is deprecated because of its insecurity so I'm concerned about it, not because of the application security which fails every where but for my own knowledge. 我知道magic_quotes_gpc由于其不安全性而被弃用,所以我很关心它,不是因为应用程序安全性因为我自己的知识而失败。

EDIT: I'm aware of the security implications of *magic_quotes_gpc* and I never use it in my own projects. 编辑:我知道* magic_quotes_gpc *的安全含义,我从不在自己的项目中使用它。 I always use parameterized queries to avoid injection but this time I was asked to add a very specific pice of code in a friend/client project, so I cant change what is already done. 总是使用参数化查询来避免注入,但这次我被要求在朋友/客户端项目中添加一个非常具体的代码,所以我不能改变已经完成的工作。 I'd like to know if there is a specific value I can use to create an injection so I can illustrate my friend why he should change it. 我想知道是否有一个特定的值可以用来创建一个注射器,所以我可以说明我的朋友为什么要改变它。

if the DB is mysql use mysqli_real_escape_string() instead, if the PHP version is very old you can use the mysql_real_escape_string (not recommended at the moment). 如果DB是mysql而是使用mysqli_real_escape_string() ,如果PHP版本很旧,你可以使用mysql_real_escape_string(目前不推荐)。

even if the variable is between colons it can be injected, you just need to close the colons inside the value of the variable and then inject whatever you want afterwards. 即使变量在冒号之间也可以注入,你只需要关闭变量值内的冒号然后注入你想要的任何东西。

With regard to your edit: You asked "I'd like to know if there is a specific value I can use to create an injection so I can illustrate my friend why he should change it." 关于你的编辑:你问“我想知道是否有一个特定的值可以用来创建一个注射器,所以我可以说明我的朋友为什么要改变它。”

According to the manual page for mysqli_real_escape_string() , the characters it escapes are as follows: 根据mysqli_real_escape_string()手册页 ,它转义的字符如下:

NUL (ASCII 0), \n, \r, \, ', ", and Control-Z.

The old mysql_real_escape_string() function also escapes the same characters. 旧的mysql_real_escape_string()函数也会转义相同的字符。

This gives you a starting point as to which characters can be used to do injection attacks in MySQL. 这为您提供了一个起点,可以在MySQL中使用哪些字符进行注入攻击。 Magic quotes only escapes the quote characters and the slash character, which clearly leaves several gaping holes that can be exploited. 魔术引号只能逃脱引号字符和斜线字符,这显然会留下几个可以被利用的漏洞。

In an easy world, the above information would be enough for us to fix the escaping by doing a string replace on the remaining unescaped characters. 在一个简单的世界中,上述信息足以让我们通过对剩余的未转义字符进行字符串替换来修复转义。

However, both the real_escape functions also require an active database connection for them to work, and this leads us to a further complication: character sets. 但是, real_escape函数还需要一个活动的数据库连接才能使它们工作,这导致我们进一步复杂化:字符集。

Further attacks are possible if the database has a different character set to PHP, particularly with variable-length character sets such as UTF-8 or UTF-16. 如果数据库具有与PHP不同的字符集,则可能会发生进一步的攻击,特别是对于可变长度字符集(如UTF-8或UTF-16)。

An attacker who knows (or can guess) the character set that PHP and the DB are using can send a crafted injection attack string that contains characters that PHP would not see as needing escaping, but which would still cause succeed in hacking MySQL. 知道(或可以猜测)PHP和数据库正在使用的字符集的攻击者可以发送一个精心设计的注入攻击字符串,其中包含PHP看不到需要转义的字符,但这仍然会导致成功攻击MySQL。 This is why the real_escape functions need to access the DB in order to know how to do the escaping. 这就是为什么real_escape函数需要访问数据库才能知道如何进行转义。

Further resources: 更多资源:

I hope that gives you a few pointers. 我希望能给你一些指示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM