ctf piapiapia(反序列化逃逸)解题记录
前言
出现漏洞的两个重要因素是:1、敏感函数,2、可控参数。
打开url是一个登录界面,而且只有一个登录按钮。由于看到了登录界面而且没有验证码所以第一个想法是尝试弱口令登录,显然不成功,所以在这里来走了弯路。该题首先是需要通过目录扫描得到源码压缩包、注册账户的地址,得到源码后进行代码审计,发现蛛丝马迹,最终通过构造修改用户名的字符串利用反序列化逃逸得到在config.php中的flag
========================================================================
一、使用dirserch目录扫描工具对目标进行目录扫描
扫描发现了 /config.php、/www.zip、/regester.php。访问/www.zip得到源码。
二、进行php代码审计
1、源代码
index.php
<?php
require_once('class.php');
if($_SESSION['username']) {
header('Location: profile.php');
exit;
}
if($_POST['username'] && $_POST['password']) {
$username = $_POST['username'];
$password = $_POST['password'];
if(strlen($username) < 3 or strlen($username) > 16)
die('Invalid user name');
if(strlen($password) < 3 or strlen($password) > 16)
die('Invalid password');
if($user->login($username, $password)) {
$_SESSION['username'] = $username;
header('Location: profile.php');
exit;
}
else {
die('Invalid user name or password');
}
}
else {
?>
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<link href="static/bootstrap.min.css" rel="stylesheet">
<script src="static/jquery.min.js"></script>
<script src="static/bootstrap.min.js"></script>
</head>
<body>
<div class="container" style="margin-top:100px">
<form action="index.php" method="post" class="well" style="width:220px;margin:0px auto;">
<img src="static/piapiapia.gif" class="img-memeda " style="width:180px;margin:0px auto;">
<h3>Login</h3>
<label>Username:</label>
<input type="text" name="username" style="height:30px"class="span3"/>
<label>Password:</label>
<input type="password" name="password" style="height:30px" class="span3">
<button type="submit" class="btn btn-primary">LOGIN</button>
</form>
</div>
</body>
</html>
<?php
}
?>
class.php
<?php
require('config.php');
class user extends mysql{
private $table = 'users';
public function is_exists($username) {
$username = parent::filter($username);
$where = "username = '$username'&