影响版本:
V1.0.0.20180911_beta - V1.0.0.20200506_beta
目前看官方4天了,还没有修复
漏洞代码位置:
https:
/
/github.com/karsonzhang
/fastadmin/blob
/master/application
/index/controller
/User.php
漏洞披露信息:https://github.com/karsonzhang/fastadmin/issues/73?spm=a2c4g.11174386.n2.3.428c1051tmy0pT
============================================
官方发布信息了:https://www.fastadmin.net/news/83.html
==========================
漏洞利用条件:
usercenter
=>
true
漏洞分析:
存在漏洞文件位置:
application/index/controller/User.php
/**
* 空的请求
*
@param
$name
*
@return
mixed
*/
public
function
_empty
($name)
{
$data = Hook::listen(
"user_request_empty"
, $name);
foreach
($data
as
$index => $datum) {
$this
->view->assign($datum);
}
return
$this
->view->fetch(
'user/'
. $name);
}
_empty函数接收$name遍历,直接将$name返回视图中:
return
$this
->view->fetch($name);
攻击者可通过上传文件,例如图片,传入$name,fetch模板进行php模板解析,导致getshell。
渲染fetch实际使用的是thinkphp的解析模板函数,内容如下:
public
function
fetch
($template, $data = [], $config = [])
{
if
(
''
== pathinfo($template, PATHINFO_EXTENSION)) {
// 获取模板文件名
$template =
$this
->parseTemplate($template);
}
// 模板不存在 抛出异常
if
(!is_file($template)) {
throw
new
TemplateNotFoundException(
'template not exists:'
. $template, $template);
}
// 记录视图信息
App::$debug && Log::record(
'[ VIEW ] '
. $template .
' [ '
. var_export(array_keys($data),
true
) .
' ]'
,
'info'
);
$this
->template->fetch($template, $data, $config);
}
在验证是否为模板文件,可以看到if (!is_file($template)) ,来判断是否存在,如果存在就将文件进行php解析。
这里有一个小问题:
关于操作系统解析文件路径的时候,linux和windwos is_file()函数实现不一样。
1、linux判断is_file() /demo/../../../../test 如果demo目录不存在,就会返回false;
windows下无论这个目录是否存在,均会返回true;
2、在linux下,is_file()函数判可用于判断符号链接
3、在linux下,is_file函数会受到权限的影响,当前用户权限不足或父目录没有设置+x权限时,is_file()会返回false
4、windows系统里面/和 都可以使用,但是在linux下只能使用/ 来分隔路径,因此这会导致is_file()在不同系统下的返回结果不一致
5、is_file()判断文件时,如果文件大小超过2^32时,会判断失败(PHP 的整数类型是有符号整型而且很多平台使用 32 位整型,对 2GB 以上的文件,一些文件系统函数可能返回无法预期的结果)
可以参考https://www.php.net/manual/zh/function.is-file.php
实验如下:
漏洞验证:
用户登录,进入个人页面,修改上传图片
brup:
获取到的地址:
payload:
http:
//www.demo.com/index.php/index/user/_empty?name=../../public/uploads/xxxxx/xxxxx.jpg
因is_file()在linux下/user目录不存在,所以无法利用,除非可以创建或存在,可以手工创建public下创建user目录
windows下通杀。
修复方案:
打开application/index/controller/User.php,找到大概第58行的_empty方法,有以下两种修复方法:
一种修复方法是直接移除_empty方法,
另一种是将_empty方法改为
public
function
_empty
($name)
{
if
(!preg_match(
"/^([a-z0-9_]+)$/i"
, $name)) {
$this
->error(__(
'Invalid parameters'
));
}
$data = Hook::listen(
"user_request_empty"
, $name);
foreach
($data
as
$index => $datum) {
$this
->view->assign($datum);
}
return
$this
->view->fetch(
'user/'
. $name);
}
这个方法设计的用途主要是用于插件系统,便于插件开发者在处理前台用户相关信息时可以直接使用index/user/custommethod
的URL方式访问到自定义的视图,便于共用布局和JS。
原文地址:
https:
/
/www.cnblogs.com/sevck
/p/
13723094
.html
声明:⽂中所涉及的技术、思路和⼯具仅供以安全为⽬的的学习交流使⽤,任何⼈不得将其⽤于⾮法⽤途以及盈利等⽬的,否则后果⾃⾏承担。所有渗透都需获取授权!
原文始发于微信公众号(白帽子左一):fastadmin前台getshell漏洞
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论