【发布时间】:2017-11-28 10:36:52
【问题描述】:
首先,我是 PHP 和一般编码的新手。
我目前正在创建一个 Web 应用程序,该应用程序故意容易受到攻击,以向学生介绍基于 Web 的漏洞。 Web 应用程序由多个级别组成,每个级别都包含不同的漏洞。
在当前关卡中,当用户成功登录关卡时,我尝试将 cookie 名称设置为“Authenticated”,值为“0”。当他们到达该页面时,他们会收到一个未通过身份验证的 PHP 错误。我希望他们能够拦截页面请求,将值更改为“1”,然后作为更改值的结果,接收包含下一级密码的 PHP 回显。
这是我的主页(level6.php):
<?php
session_start();
if(!isset($_SESSION['user'])){
header("Location:../level5/login6.php");
}
include("authentication.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../css/wargames.css">
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script src="js/script.js"></script>
<title>Generic Web App Title</title>
<div id="logodiv"><img src="../images/test.png" width="50%"></div>
<div id='cssmenu'>
<ul>
<li><a href='#'>Cryptography</a></li>
<li><a href='#'>Directory Traversal</a></li>
<li><a href='#'>SQL Injection</a></li>
<li><a href='#'>Malicious Redirects</a></li>
<li><a href='#'>Burp Suite</a></li>
<li><a href='#'>nmap</a></li>
<li><a href='#'>John the Ripper</a></li>
<li><a href='#'>Information Gathering</a></li>
<li><a href='#'>Reporting</a></li>
</ul>
</div>
</head>
<body background="../images/background.jpg">
<br />
<div id='announcements' style="margin: 0 auto;"><h3 align='center'>Welcome
to Level 6!</h3></b>
<hr>
<span><?php echo $error; ?></span>
</div>
<br />
<div id="pagefoot">
<div id='footer' align='center'>####
<br />
####
</div>
</div>
</body>
</script>
</html>`
这是后台运行的 PHP (authentication.php):
<?php
$error=''; //
$cookie_name="Authenticated";
$cookie_value="0";
setcookie($cookie_name, $cookie_value);
if($cookie_value = "0") {
$error = "You are not authorized to view this page!";
}
else {
if($cookie_value = "1") {
$error = "Success! The password for the next level is...";
}
}
?>
感谢您的帮助。
编辑:这是我的登录代码。用户将进入登录页面。登录页面是基本的,包含此代码...
<?php
session_start();
$error=''; //
if(isset($_POST['submit'])){
if(empty($_POST['user']) || empty($_POST['pass'])){
$error = "Username or Password is Invalid";
}
else
{
//Define $user and $pass
$user=$_POST['user'];
$pass=$_POST['pass'];
//Establish Connection with server by passing server_name, user_id
and pass as a parameter
$sqli = mysqli_connect("localhost", "", "");
//Select Database
$db = mysqli_select_db($sqli, "");
//sql query to fetech information of registered user and finds user
match.
$query = mysqli_query($sqli, "SELECT * FROM members WHERE id=6 AND
password='$pass' AND username='$user'");
$rows = mysqli_num_rows($query);
if($rows == 1){
$_SESSION['user'] = md5($pass);
header("Location: ../level6/level6.php"); //Redirect to
protected page
}
else
{
$error = "Username or Password is Invalid";
}
mysqli_close($sqli); //Close Conenction
}
}
?>
然后登录代码将对用户进行身份验证并将他们带到上面的页面。
【问题讨论】:
-
if($cookie_value == "0") {使用这个 -
设置 cookie 值后,您在 if 条件下检查 cookie 的值,然后我认为它总是显示您无权查看此页面!因为你将 cookie_value 的值设置为 0 ,所以它覆盖它。
标签: php session cookies web-applications session-cookies