![](/img/trans.png)
[英]I am Unable to access my admin panel with my password and email. This is PHP and SQL related
[英]Why I am getting access to the admin panel without sending username and password by using php cURL
我為實驗做了一個基本的登錄表單,並嘗試使用cURL登錄。 我正在使用php。 我確保沒有登錄(身份驗證)的人無法進入index.php主頁。 但是現在,當我嘗試使用cURL進行訪問時,我明白了。 我認為登錄和會話處理代碼中可能存在問題。 我已盡力而為,但沒有任何解決方案。 請幫助解決此問題。
提前致謝。
1.這是會話處理代碼,駐留在session.php中
<?php
class session{
public static function init(){
session_start();
}
public static function set($key,$value){
$_SESSION[$key] = $value;
}
public static function get($key){
if (isset($_SESSION[$key])) {
return $_SESSION[$key];
}
else{
return false;
}
}
public static function cheaksession(){
self::init();
if(self::get("login") == false){
self::destroy();
header("Location: login.php");
}
}
public static function destroy(){
session_destroy();
}
}
?>
2.這是登錄表單代碼,駐留在login.php中
<?php
include "lib/session.php";
session::init();
?>
<?php include "lib/Database.php"; ?>
<?php include "helpers/format.php"; ?>
<?php
$db = new Database();
$fm = new format();
?>
<?php
$err = 0;
if ($_SERVER['REQUEST_METHOD'] == 'POST' ) {
$username = $fm->validation($_POST['username']);
$password = $fm->validation($_POST['password']);
$username = mysqli_real_escape_string($db->link,$username);
$password = mysqli_real_escape_string($db->link,$password);
if($username == 'fahad' && $password == '1234') {
session::set("login",true);
session::set("username",$username);
session::set("userId",1);
header("Location: index.php");
}
else{
$err = 1;
}
}
?>
3.這是用於會話檢查的主頁代碼,駐留在index.php中
<?php
include "lib/session.php";
session::cheaksession();
?>
4.這是攻擊的cURL代碼
<?php
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'http://localhost/Hackalgo/DummySite/index.php');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>
通過執行此腳本,我正在檢索上面(3)中提到的index.php的html頁面。 但是在index.php (3)中有一個會話檢查器方法,應該迫使我進入(2)中提到的登錄頁面login.php 。 但是它不起作用,並且在登錄頁面(2)中沒有任何身份驗證的情況下對index.php (3)進行了爬網。
發送Location標頭后,調用exit()左右。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.