DASCTF Jul.2023

Web

MyPicDisk

0x00 获取源代码

先随意构造一个 Payload 如下

admin' 1=1#

可以得到回显如下(alert 弹窗)

登录成功!
you are not admin!!!!!

把 JavaScript 禁止后,查看源代码如下

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>MyPicDisk</title>
</head>
<body>
<script>alert('you are not admin!!!!!');</script><script>location.href='/index.php';</script><!-- /y0u_cant_find_1t.zip -->
  <form action="index.php" method="post" enctype="multipart/form-data">
  选择图片:<input type="file" name="file" id="">
  <input type="submit" value="上传"></form>
  </body>
</html>

可以得到文件 ./y0u_cant_find_1t.zip ,文件内 index.php 内容如下

0x01 代码逻辑

  1. 判断 $_SESSION['user'] 是否存在,不存在跳 2,存在跳转 3;

  2. 进行登录操作,登录成功即将 $_POST['username'] 的值赋给 $_SESSION['user'] ,并跳转回 ./index.php 即跳转 1。

  3. 判断 $_SESSION['user'] 是否为 admin ,不是则弹窗 you are not admin!!!!! 并跳转回 ./index.php 即跳转 1。**但因没有 die()exit() 或者其它类似函数,因此函数还会继续往下执行,这也是这题的突破口。**跳转4;

  4. 判断 $_GET['file'] 是否存在,存在则根据 todo 来执行操作,不存在跳转 5;

    • todo=md5 将执行 md5_file() 显示文件的 MD5 哈希值。

    • todo=remove 将执行 FILE::remove() 删除文件操作,并跳转 1。

    • todo=show 将执行 FILE::show() 显示图片信息。

    • 若不等于上述任何一种则返回图片以及两个功能键。

  5. 进行图片上传操作,有白名单,需要上传图片马。

0x02 解题逻辑

  1. 通过表单提交登录,使得 $_SESSION['user'] 存在;

  2. 通过表单上传图片马,上传后由于 unset($_SESSION['user']); 因此执行下次操作前需再次登录;

  3. 再次登录后通过 todo=md5 执行 FILE::__destruct() 来获得 flag。

0x03 构造反序列化

test.phar 上传至靶机

可以得到回显如下

将 PHP 代码中的 $a->filename 修改为

再次上传靶机即可获得 flag 。

Last updated