gpt4 book ai didi

php - PHP 中的 SQL 注入(inject),如何将非转义引号发送到服务器?

转载 作者:行者123 更新时间:2023-12-01 00:41:55 25 4
gpt4 key购买 nike

这段代码似乎不安全:

<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'];

当我发送 ' (撇号)时,我收到了 \' 。于是就变成了自动转义。我的问题是,它发生在哪里?如何发送“清晰”的撇号?

最佳答案

你可以有 Magic Quotes在。你运行的是什么版本的 PHP? Magic Quotes 在 5.3 中被弃用并在 5.4 中被移除,但它们在存在时默认为 ON。

Magic Quotes 会自动转义引号,但您真的不应该依赖它。您应该将其关闭并使用不同的转义方法,或者更好地查看使用 prepared statements .

运行 get_magic_quotes_gpc() 看看你是否有它们。如果是这样,请通过对 php.ini 文件进行以下更改来关闭它们:

; Magic quotes
;

; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off

; Magic quotes for runtime-generated data, e.g. data from SQL, from exec(), etc.
magic_quotes_runtime = Off

; Use Sybase-style magic quotes (escape ' with '' instead of \').
magic_quotes_sybase = Off

关于php - PHP 中的 SQL 注入(inject),如何将非转义引号发送到服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30085236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com