【发布时间】:2015-05-06 18:52:30
【问题描述】:
这段代码似乎不安全:
<form method='post'>
<input type='text' name='x' style='width:1000px'>
<input type='submit' value='Send'>
</form>
<?php
if(isset($_POST['x']))
{
require_once("db_connect.php");
$q = mysqli_query($dbc, "SELECT x FROM table where x = '". $_POST['x'] ."'");
while($r = mysqli_fetch_assoc($q))
echo $r['x'];
}
但是当我发送恶意输入时,它不起作用。所以我做了类似的脚本:
<form method='post'>
<input type='text' name='x' style='width:1000px'>
<input type='submit' value='Send'>
</form>
<?php
if(isset($_POST['x']))
echo $_POST['x'];
当我发送'(撇号)时,我收到了\'。所以它自动逃脱了。我的问题是,它发生在哪里?如何发送'clear'撇号?
【问题讨论】:
-
这段代码不可能自动转义撇号。
-
尝试将
' or '3'='3作为您的$_POST['x']发送到真实表格,例如用户名或其他任何内容 -
@MonkeyZeus 收到 \' 或 \'3\'=\'3
-
@ComPiler 你的代码不应该被认为是安全的——你的服务器可能启用了magic_quotes,这是一种已弃用的做法(事实上,它在 PHP 5.4 中已被删除)并且是 PHP 中的一个安全问题因为它在经常不存在时被依赖。为了安全起见,您应该使用
prepare()/bind_param()/execute()方法described in these answers -
@developerwjk 完全有可能他有魔术引号,并且在 POST 数据上它会自动为他转义
标签: php mysql escaping sql-injection