【发布时间】:2013-12-13 18:54:10
【问题描述】:
普通用户可以正常使用管理面板!它需要密码才能访问,但是当我使用 acunetix 的 http 编辑器访问它时,它会打开管理面板而无需验证。 我正在使用一个功能来检查管理员是否已登录。如果没有,则重定向到登录页面! 这是函数代码,请帮助我!谢谢。
--> full() 函数是mysqli_real_escape_string(htmlspecialchar());
--> acunetix 是很好的应用漏洞测试者。
function admin_check() {
global $users, $mysqli;
if(isset($_COOKIE['username'])){
$username = full($_COOKIE['username']);
$password = full($_COOKIE['password']);
$id = full($_COOKIE['id']);
if(is_numeric($id)){
$id = $id;
if($id < 0){
$id = (-1)*$id;
}
}
else {
$id = 10;
}
$query = "SELECT * FROM $users WHERE username = '{$username}' and password = '{$password}' and id = $id ";
$query_process = mysqli_query($mysqli, $query);
if(!$query_process){
die_message("There was some error checking admin login");
}
$check_rows = mysqli_num_rows($query_process);
if($check_rows != 1){
header("location: login.php");
}
while($rows = mysqli_fetch_assoc($query_process)){
$admin_role = $rows['admin_role'];
}
if($admin_role != 1){
header("location: logout.php");
}
}//end of first if
else {
header("location: login.php");
}
}// end of function
【问题讨论】:
-
您将登录条件存储在在 cookie 中。捂脸!
-
您是否进行了任何调试以缩小问题范围? acunetix 工具是否以某种方式导致页面在标头调用之前生成输出,从而使其不再工作?您可能会考虑不使用函数控制标头,而是让函数仅返回布尔值,以判断用户是否为管理员并让主应用程序逻辑处理重定向。
-
基于 Cookie 的用户名和密码?一点都不好。您最好将您的网站“暂停”,直到您解决此问题并使用不同的方法。
-
这就是我从网站管理面板中删除登录页面的原因。 asimishaq.com/admin