sql - 如何允许学生在此页面中注入 DROP TABLE?
问题描述
我创建了一个教学资源,让学生可以通过 SQL 注入网页并提取信息。这在一定程度上起作用,因为输入 ' OR '1'='1';-- ' 将允许他们看到返回的第一个结果,并且他们可以使用 OFFSET 来查看其他结果。
当我尝试在查询中包含 DROP TABLE 时,我得到“致命错误:未捕获的 TypeError:mysqli_fetch_assoc():参数 #1 ($result) 必须是 mysqli_result 类型,bool given”
我可以更改下面的代码以使这些额外的注入起作用吗?或者他们可以输入一些文本来使它起作用?
//prepare sql - this is a really bad thing to do
$sql="SELECT * FROM tblUsers WHERE username = '$user' AND password = '$pass' " ;
// leaky log to console
console_log($sql);
$result = mysqli_query($conn, $sql);
//leaky log to console
console_log($result);
//if the query ran successfully
if (mysqli_num_rows($result) > 0) {
//get the row and turn into an array of strings
$row = mysqli_fetch_assoc($result);
}
else{
//if nothing returned, throw them back to the login page
echo "Incorrect username or password";
header("Location: login.html");
exit();
}
解决方案
推荐阅读
- c++ - 在具有不兼容代码的 C++ 代码中使用 C 库
- ios - 如何从另一个视图控制器呈现导航控制器的内部?
- php - 在 CodeIgniter 中使用 DOCXTemplate 类时如何修复 var_dump 中的“找不到文件”
- java - 测试 AWS SNS Util 类
- php - Symfony 3 - FormType 中的 ('required => true') 不起作用
- ansible - 尝试删除文件时出现奇怪的行为
- c++ - 带有 cpp-netlib 的 HTTPS 客户端 - sslv3 警报握手失败
- python - 如何为不属于任何应用程序的 URL 创建视图函数?
- scala - 如何调试和修复发散隐式
- c - 如何完成“字母”功能?(链表)