我为实验做了一个基本的登录表单,并尝试使用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()左右。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句