PHP/5.6.40字符逃逸

    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. session_start();
    14. class message{
    15. public $from;
    16. public $msg;
    17. public $to;
    18. public $token='user';
    19. public function __construct($f,$m,$t){
    20. $this->from = $f;
    21. $this->msg = $m;
    22. $this->to = $t;
    23. }
    24. }
    25. $f = $_GET['f'];
    26. $m = $_GET['m'];
    27. $t = $_GET['t'];
    28. if(isset($f) && isset($m) && isset($t)){
    29. $msg = new message($f,$m,$t);
    30. $umsg = str_replace('fuck', 'loveU', serialize($msg));
    31. $_SESSION['msg']=base64_encode($umsg);
    32. echo 'Your message has been sent';
    33. }
    34. 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. session_start();
    12. highlight_file(__FILE__);
    13. include('flag.php');
    14. class message{
    15. public $from;
    16. public $msg;
    17. public $to;
    18. public $token='user';
    19. public function __construct($f,$m,$t){
    20. $this->from = $f;
    21. $this->msg = $m;
    22. $this->to = $t;
    23. }
    24. }
    25. if(isset($_COOKIE['msg'])){
    26. $msg = unserialize(base64_decode($_SESSION['msg']));
    27. if($msg->token=='admin'){
    28. echo $flag;
    29. }
    30. }

    看注释发现 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. session_start();
    12. highlight_file(__FILE__);
    13. include('flag.php');
    14. class message{
    15. public $from;
    16. public $msg;
    17. public $to;
    18. public $token='user';
    19. public function __construct($f,$m,$t){
    20. $this->from = $f;
    21. $this->msg = $m;
    22. $this->to = $t;
    23. }
    24. }
    25. if(isset($_COOKIE['msg'])){
    26. $msg = unserialize(base64_decode($_SESSION['msg']));
    27. if($msg->token=='admin'){
    28. echo $flag;
    29. }
    30. }

    一开始没看出和 web262 有啥区别,仔细看了一下发现,反序列化时使用了 session 而不是直接通过 Cookie 接收

    做法和 web262中第二种做法一样,虽然不是通过 Cookie 接收,也别忘了了 Cookie 的 msg 字段附加个值,不然不满足

    1. if(isset($_COOKIE['msg'])){

    先请求 index.php (这里 poc 不明白怎么构造看一下 web262 第二种做法)
    image.png
    因为 PHP 的 session 是通过 Cookie 里的 PHPSESSID 获取的(不清除参考 web263 session 伪造),所以要记录下来,然后在 message.php 里带上。

    然后请求一下 message.php , 别忘了 Cookie 部分
    image.png
    flag
    ctfshow{6491abcd-1e5c-489b-b25f-9e941bc5c588}