Answer the question
In order to leave comments, you need to log in
Hacked, how to protect the site?
Hello! The site has a function with which the admin panel is protected. (Redirecting the user if the rights are less than required)
function rights($rights){
global $http;
global $user;
if($user['rights'] < $rights) {
header('Location: '.$http.$_SERVER['SERVER_NAME']); exit;
}}
$user_id = isset($_COOKIE['uid']) ? fl($_COOKIE['uid']) : '';
$password = isset($_COOKIE['password']) ? fl($_COOKIE['password']) : '';
if($user_id && $password) {
$user = $base -> query('SELECT * FROM `users` WHERE `id` = "'.$user_id.'" AND `password` = "'.$password.'"') -> fetch_assoc();
} else {$user = false;}
Answer the question
In order to leave comments, you need to log in
You have sql injection in your code.
Instructions on how to avoid them: habr php.net
The option with SQL injection looks romantic, of course, but I would assume that in this shit code it is still simpler - $rights is not defined, and therefore the check does not work if $user is set to a value.
if ($user['rights'] < $rights)
How should this work if $user = false ?
Most likely, due to an error, this condition is simply accepted as false, and your check passes.
UPD: Still returns true, but I would not recommend relying on implicit type conversions, especially since PHP 7.4 this generates a Notice, and in future versions it may one day be removed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question