可能重复:
我看到了一些他们使用代码的地方
login=' or 1=1 -- & password=' or 1=1 --从前端登录到网站。我想知道这段代码是如何破解登录的。
发布于 2012-01-04 16:43:31
您给出的示例利用了深思熟虑的代码,其中用户输入不会转义并在查询中使用。假设有一个带有用户和密码字段(form.html)的表单,它将输入的值传递给php脚本(test.php)。假设用户在两个字段中写入'‘OR 1 =1--
下面的代码不会转义用户输入。您应该使用mysql_real_escape_string()或参数化查询来实现这一点。
form.html:
<form method="POST" action="test.php">
<input type="text" name="login" value=""><br />
<input type="text" name="password" value=""><br />
<input type="submit"/>
</form> test.php:
$name = $_POST['login'];
$pass = $_POST['password'];
echo $name . "<br />";
$sql= "SELECT * FROM users WHERE login = $name AND password = $pass ";
// $sql now contains this command:
// SELECT * FROM users WHERE login= '' OR 1=1-- AND password = '' OR 1 =1--
// condition OR 1=1 means that any row satisfies the query
// as long as there is at least 1 row in the table users, authorisation will be succcesful
echo $sql . "<br />";
$result=mysql_query($sql);发布于 2012-01-04 14:56:50
您要寻找的是SQL注入。
http://en.wikipedia.org/wiki/SQL_injection
https://stackoverflow.com/questions/8728857
复制相似问题