请您告诉我为什么我的SQL注入不能工作,以及如何修复它。我尝试使用Here中的示例,但是值‘);DROP表;-或者密码1=1不工作。我很抱歉在这些简单的事情上浪费了你的时间,但是我试了很多次,但我没有让它运行,而另一个帖子对我没有帮助。
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: #cc0000;}
</style>
</head>
<body>
<h2>Einlogen</h2>
<form action="EasyExploit.php" method="post">
Vorname: <input type="text" name="vorname"><br>
<input type="submit">
<h2>Registrieren</h2>
<form action="EasyExploit.php" method="post">
Vorname: <input type="text" name="vorname"><br>
<input type="submit">
<?php
$connection = mysqli_connect('localhost', 'root','' ,'DB') or die(mysqli_error());
mysqli_select_db($connection ,'DB')or die(mysqli_error());
@$unsafe_variable = $_POST['vorname'];
mysqli_query($connection, "INSERT INTO `Persons` (`Vorname`) VALUES ('$unsafe_variable')");
?>
</body>
</html>
预先感谢
发布于 2017-12-30 14:32:30
使sql注入易受攻击的代码(用于测试目的):
为了用代码测试SQL注入,我们需要做一些更改:
<?php
$connection = mysqli_connect('localhost', 'root','' ,'DB') or
die(mysqli_error($connection)); //1
mysqli_select_db($connection ,'DB') or die(mysqli_error($connection)); //2
$unsafe_variable = $_POST['vorname'];
mysqli_multi_query($connection, //3
"INSERT INTO `Persons` (`Vorname`) VALUES ('$unsafe_variable')");
?>mysqli_error需要$connection参数。mysqli_multi_query能够一次执行多个句子。出于安全原因。mysqli_query只是执行一个以防止sql注入。测试:
是测试sql注入的时候了。我们创建一个简单的表t来检查是否可以通过sql注入删除它:
create table t ( i int );攻击时间到了,注入sql的杀手字符串是:
( pepe');放置表t;--

注入代码的SQL: “插入Person (Vorname)值('pepe');删除表t;--‘”
解释:
"INSERT INTO Persons (Vorname) VALUES ('$unsafe_variable')"$unsafe_variable:"INSERT INTO Persons (Vorname) VALUES ('pepe'); DROP TABLE t;--')"在发布此值后形成:
mysql> select * from t;
ERROR 1146 (42S02): Table 's.t' doesn't exist如何避免SQL注入?
伙计,这是互联网,他们有很多关于它的文件。使用参数化查询开始搜索。
https://stackoverflow.com/questions/48033975
复制相似问题