技术标签: php slim 教程
现代cms框架(laraval/symfony/slim)的出现,导致现今的php漏洞出现点、原理、利用方法,发生了一些变化,这个系列希望可以总结一下自己挖掘的此类cms漏洞。
slim是一个设计思路超前的知名的php轻框架,完美结合了psr7来设计,至今用户已超过100w:
在阅读其源码的过程中,我发现其存在一个只有在框架式CMS中才会出现的漏洞。
漏洞详情
这个漏洞存在于最新版(3.0)中。
首先用conposer安装之
composer require slim/slim “^3.0@RC”
很典型的问题,在这篇帖子里也提到过: http://zone.wooyun.org/content/19908
有时候框架会帮开发者一些他可能并不需要的『忙』,比如slimphp这里,常规的POST的content-type为application/x- www-form-urlencoded,但只要我将其修改为application/json,我就可以传入json格式的POST数据,修改为 application/xml,我就可以传入XML格式的数据。
这个特性将会导致两个问题:
WAF绕过
可能存在的XXE漏洞
WAF绕过这个肯定不用说了,常规的WAF一般只检测application/x-www-form-urlencoded的数据,一旦修改数据类型则将通杀各大WAF。
XXE是本漏洞的重点。
我们看到解析body的代码:
Default
public function __construct($method, UriInterface $uri, HeadersInterface $headers, array $cookies, array $serverParams, StreamInterface $body, array $uploadedFiles = [])
{
$this->originalMethod = $this->filterMethod($method);
$this->uri = $uri;
$this->headers = $headers;
$this->cookies = $cookies;
$this->serverParams = $serverParams;
$this->attributes = new Collection();
$this->body = $body;
$this->uploadedFiles = $uploadedFiles;
if (!$this->headers->has('Host') || $this->uri->getHost() !== '') {
$this->headers->set('Host', $this->uri->getHost());
}
$this->registerMediaTypeParser('application/json', function ($input) {
return json_decode($input, true);
});
$this->registerMediaTypeParser('application/xml', function ($input) {
return simplexml_load_string($input);
});
$this->registerMediaTypeParser('text/xml', function ($input) {
return simplexml_load_string($input);
});
$this->registerMediaTypeParser('application/x-www-form-urlencoded', function ($input) {
parse_str($input, $data);
return $data;
});
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
publicfunction__construct($method,UriInterface$uri,HeadersInterface$headers,array$cookies,array$serverParams,StreamInterface$body,array$uploadedFiles=[])
{
$this->originalMethod=$this->filterMethod($method);
$this->uri=$uri;
$this->headers=$headers;
$this->cookies=$cookies;
$this->serverParams=$serverParams;
$this->attributes=newCollection();
$this->body=$body;
$this->uploadedFiles=$uploadedFiles;
if(!$this->headers->has('Host')||$this->uri->getHost()!==''){
$this->headers->set('Host',$this->uri->getHost());
}
$this->registerMediaTypeParser('application/json',function($input){
returnjson_decode($input,true);
});
$this->registerMediaTypeParser('application/xml',function($input){
returnsimplexml_load_string($input);
});
$this->registerMediaTypeParser('text/xml',function($input){
returnsimplexml_load_string($input);
});
$this->registerMediaTypeParser('application/x-www-form-urlencoded',function($input){
parse_str($input,$data);
return$data;
});
}
实际上解析代码是作为回调函数写在Request类的构造方法里了。
可见这里直接调用了simplexml_load_string解析$input,造成XML实体注入漏洞。
所以,用slim framework 3.0开发的CMS,只要获取了POST数据,都将受到此XXE漏洞的影响。
漏洞证明
编写一个最简单的demo页面,只有一个获取POST信息并输出的功能:
Default
require 'vendor/autoload.php';
$app = new \Slim\App();
$app->post("/post", function($request, $response) {
$parsedBody = $request->getParsedBody();
print_r($parsedBody);
});
$app->run();
1
2
3
4
5
6
7
require'vendor/autoload.php';
$app=new\Slim\App();
$app->post("/post",function($request,$response){
$parsedBody=$request->getParsedBody();
print_r($parsedBody);
});
$app->run();
触发XXE漏洞并读取/etc/passwd:
漏洞修复
在slimphp2中,官方是对这块进行一定处理了:
Default
/**
* Parse XML
*
* This method creates a SimpleXMLElement
* based upon the XML input. If the SimpleXML
* extension is not available, the raw input
* will be returned unchanged.
*
* @param string $input
* @return \SimpleXMLElement|string
*/
protected function parseXml($input)
{
if (class_exists('SimpleXMLElement')) {
try {
$backup = libxml_disable_entity_loader(true);
$result = new \SimpleXMLElement($input);
libxml_disable_entity_loader($backup);
return $result;
} catch (\Exception $e) {
// Do nothing
}
}
return $input;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* Parse XML
*
* This method creates a SimpleXMLElement
* based upon the XML input. If the SimpleXML
* extension is not available, the raw input
* will be returned unchanged.
*
* @param string $input
* @return \SimpleXMLElement|string
*/
protectedfunctionparseXml($input)
{
if(class_exists('SimpleXMLElement')){
try{
$backup=libxml_disable_entity_loader(true);
$result=new\SimpleXMLElement($input);
libxml_disable_entity_loader($backup);
return$result;
}catch(\Exception$e){
// Do nothing
}
}
return$input;
}
不知为何在3.0版本中官方就无视这个问题了。
我猜可能有两个原因:
官方注意到了这个问题,但认为3.0版本需求的php版本在5.5以上,而错以为5.5以上的php就已经不存在XXE的隐患了。但实际上XML外部实体的解析,和php版本并无关系,而是和编译时的libxml库版本有关。
官方尚未注意到这个问题。
感觉前者的可能性较大。
所以解决方案也还是按照2中的方案进行。
【via@phith0n】注:文章来自P牛,他博客不错,对审计有兴趣的同学推荐关注。
文章浏览阅读7.8k次,点赞3次,收藏9次。如何配置filezilla服务端和客户端百度‘filezilla server’下载最新版。注意点:下载的版本如果是32位的适用xp和win2003,百度首页的是适用于win7或更高的win系统。32和64内容无异。安装过程也是一样的。一、这里的filezilla包括服务端和客户端。我们先来用filezilla server 架设ftp服务端。看步骤。1选择标准版的就可以了。 _filezilla server for windows (32bit x86)
文章浏览阅读724次,点赞18次,收藏8次。深度学习作为一种强大的机器学习技术,已经成为图像处理领域的核心技术之一。通过模拟人脑处理信息的方式,深度学习能够从图像数据中学习到复杂的模式和特征,从而实现从简单的图像分类到复杂的场景理解等多种功能。要充分发挥深度学习在图像处理中的潜力,我们首先需要理解图像的本质。本文旨在深入探讨深度学习图像处理的基础概念,为初学者铺平通往高级理解的道路。我们将从最基础的问题开始:图像是什么?我们如何通过计算机来理解和处理图像?
文章浏览阅读62次。在收集到初步的样本数据之后,接下来该考虑的问题有:(1)样本数据集的数量和质量是否满足模型构建的要求。(2)是否出现从未设想过的数据状态。(3)是否有明显的规律和趋势。(4)各因素之间有什么样的关联性。解决方案:检验数据集的数据质量、绘制图表、计算某些特征量等,对样本数据集的结构和规律进行分析。从数据质量分析和数据特征分析两个角度出发。_数据分析 规律集
文章浏览阅读8.9k次。关于桌面上图标都不见了这类问题的解决方法1、在桌面空白处右击鼠标-->排列图标-->勾选显示桌面图标。2、如果问题还没解决,那么打开任务管理器(同时按“Ctrl+Alt+Del”即可打开),点击“文件”→“新建任务”,在打开的“创建新任务”对话框中输入“explorer”,单击“确定”按钮后,稍等一下就可以见到桌面图标了。3、问题还没解决,按Windows键+R(或者点开始-->..._上传文件时候怎么找不到桌面图标
文章浏览阅读1.5k次。参考:http://blog.csdn.net/zahuopuboss/article/details/9259283 #include #include #include #include #include #include #include #include #include #include #include #include _怎么设置tun的接收缓冲
文章浏览阅读741次。创建一个inputView继承于UIView- (instancetype)initWithFrame:(CGRect)frame{ self = [superinitWithFrame:frame]; if (self) { self.backgroundColor = [UIColorcolorWithRed:0.13gre
文章浏览阅读594次。字符串面试题(2022)_java字符串相关面试题
文章浏览阅读1.4w次,点赞12次,收藏21次。VSCODE 实现远程GUI,显示plt.plot, 设置x11端口转发问题服务器 linux ubuntu16.04本地 windows 10很多小伙伴发现VSCode不能显示figure,只有用自带的jupyter才能勉强个截图、或者转战远程桌面,这对数据分析极为不方便。在命令行键入xeyes(一个显示图像的命令)会failed,而桌面下会出现:但是Xshell能实现X11转发图像,有交互功能,但只能用Xshell输入命令plot,实在不方便。其实VScode有X11转发插件!!方法_vscode远程ssh连接服务器 python 显示plt
文章浏览阅读529次。网络编程_javase套接字socket
文章浏览阅读3.3k次,点赞2次,收藏2次。element switch开关文字显示element中switch开关把on-text 和 off-text 属性改为 active-text 和 inactive-text 属性.怎么把文字描述显示在开关上?下面就是实现方法: 1 <el-table-column label="状态"> 2 <template slot-scope="scope">..._el-switch 不同状态显示不同字
文章浏览阅读785次。java后台发起请求使用的工具类package com.cennavi.utils;import org.apache.http.Header;import org.apache.http.HttpResponse;import org.apache.http.HttpStatus;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpPost;import org.apach_httprequestutil.httpget
文章浏览阅读137次。在前两节我们部署了App-V Server并且序列化了相应的软件,现在可谓是万事俱备,只欠东风。在这篇博客里面主要介绍一下如何部署客户端并实现应用程序的虚拟化。在这里先简要的说一下应用虚拟化的工作原理吧!App-V Streaming 就是利用templateServer序列化出一个软件运行的虚拟环境,然后上传到app-v Server上,最后客户..._app-v 客户端