PHP构造pop链1

POP链记录1

<?php
//flag is in flag.php   --> 构造pop链读取flag.php文件
error_reporting(0);
class Read {
    public $var;
    public function file_get($value)
    {
        $text = base64_encode(file_get_contents($value));   // file_get_contents()函数可以读取文件
        return $text;
	}
	// 当把Read类的对象当做函数执行时,就会触发这里的__invoke()魔术方法
	public function __invoke(){
		// 这里的var是形参,实参是value: 
		// $content 从上面的file_get处获得,传入参数var即可控制file_get函数中的file_get_contents()所读取的文件,即把var赋值为flag.php以读取flag
        $content = $this->file_get($this->var);
        echo $content;
    }
}

class Show
{
    public $source;
    public $str;
    public function __construct($file='index.php')
    {
        $this->source = $file;
        echo $this->source.'Welcome'."<br>";
    }
    public function __toString()    // 将当前类的对象当作字符串时,就会调用__toString()函数
    {
        // 这里将寻找当前对象的str数组,并取出str数组中key值为str的元素指向的source
        // 若这个key值不存在,即不可访问,就会触发__get()魔术方法
        return $this->str['str']->source;
    }

    public function _show()
    {
        if(preg_match('/gopher|http|ftp|https|dict|\.\.|flag|file/i',$this->source)) 		 {
            die('hacker');
        } else {
            highlight_file($this->source);    // highlight_file()可以读取文件
        }
    }

    public function __wakeup()    // 反序列化时最先调用的魔术方法
    {
        // 这里进行正则匹配时,会将给定的变量当作字符串,如果这时的变量是某个类的对象,就会调用该类的__toString()函数
        if(preg_match("/gopher|http|file|ftp|https|dict|\.\./i", $this->source)) {
            echo "hacker";
            $this->source = "index.php";
        }
    }
}

class Test
{
    public $p;
    public function __construct()
    {
        $this->p = array();
    }

    // 若Show类中的__toString()函数返回的str数组里key值为str的值指向的source是一个Test类的对象,那么就会触发这里的__get()魔术方法
    public function __get($key)
	{
		// 这里将Test类对象中的p变量取出,赋值给function后通过return function()把function当做函数执行,若这里的p是某个具有__invoke()方法的对象,则会触发该方法 --> Read类 
        $function = $this->p;
        return $function();
    }
}

if(isset($_GET['hello']))
{
    unserialize($_GET['hello']);    // unserialize()执行的同时会先调用__wakeup()函数 --> 在Show类中
}
else
{
    $show = new Show('pop3.php');
    $show->_show();
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

YV_LING

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

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

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

打赏作者

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

抵扣说明:

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

余额充值