首页 > 解决方案 > 如何允许学生在此页面中注入 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();   
}

标签: sqlsql-injection

解决方案


推荐阅读