This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# 简单的SQL 注入漏洞
## 漏洞攻击
```php
<?php
// 用户输入(未过滤)
$username=$_POST['username'];
$password=$_POST['password'];
// 危险操作:直接拼接 SQL 查询
$sql="SELECT * FROM users WHERE username = '$username' AND password = '$password'";
$result=mysqli_query($conn,$sql);
if(mysqli_num_rows($result)>0){
echo"登录成功!";
}else{
echo"用户名或密码错误!";
}
?>
```
如何绕过密码验证?
攻击者在 username 输入框中输入:
````
admin' --
````
实际执行的 SQL:
```sql
SELECT*FROMusersWHEREusername='admin'-- ' AND password = ''