finecms 最新版v2.3.3前台getshell

没穿底裤 2020年1月1日05:14:29评论436 views字数 2190阅读7分18秒阅读模式
摘要

还是头像上传的地方,官方认为自己已经修复的很干净了,在我看来还是一点用处都没有。


漏洞作者: phith0n

还是头像上传的地方,官方认为自己已经修复的很干净了,在我看来还是一点用处都没有。

不过demo站直接把头像上传的功能给阉割了,正常头像都没法上传了,所以我就不在demo上测试了,下载最新的v2.3.3,本地测试。

版本号:

finecms 最新版v2.3.3前台getshell

 

 

看到头像上传的代码:

[php]
public function upload() {

 

if (!isset($GLOBALS['HTTP_RAW_POST_DATA'])) {

exit('环境不支持');

}

 

// 创建图片存储文件夹

$dir = FCPATH.'member/uploadfile/member/'.$this->uid.'/';

if (!file_exists($dir)) {

mkdir($dir, 0777, true);

}

 

// 创建图片存储的临时文件夹

$temp = FCPATH.'cache/attach/'.md5(uniqid().rand(0, 9999)).'/';

if (!file_exists($temp)) {

mkdir($temp, 0777);

}

$filename = $temp.'avatar.zip'; // 存储flashpost图片

file_put_contents($filename, $GLOBALS['HTTP_RAW_POST_DATA']);

 

// 解压缩文件

$this->load->library('Pclzip');

$this->pclzip->PclFile($filename);

if ($this->pclzip->extract(PCLZIP_OPT_PATH, $temp, PCLZIP_OPT_REPLACE_NEWER) == 0) {

@dr_dir_delete($temp);

exit($this->pclzip->zip(true));

}

@unlink($filename);

 

// 限制文件名称

$avatararr = array('45x45.jpg', '90x90.jpg', '180x180.jpg');

 

// 删除多余目录

$files = glob($temp.'*');

foreach($files as $_files) {

if (is_dir($_files)) {

dr_dir_delete($_files);

}

if (!in_array(basename($_files), $avatararr)) {

@unlink($_files);

}

}

 

// 判断文件安全,删除压缩包和非jpg图片

if($handle = opendir($temp)) {

while (false !== ($file = readdir($handle))) {

if ($file !== '.' && $file !== '..') {

if (!in_array($file, $avatararr)) {

@unlink($temp.$file);

} else {

$info = @getimagesize($temp.$file);

if (!$info || $info[2] !=2) {

@unlink($temp.$file);

} else {

copy($temp.$file, $dir.$file);

@unlink($temp.$file);

}

}

}

}

closedir($handle);

}

@rmdir($temp);
[/php]

 

我曾经用的一个方法是,构造一个部分出错的压缩包,在解压时出现错误,导致exit,但已有部分文件已解压成功,这样就能不被后面的unlink删除。另一个方法是竞争型,再php没来得及删除我们解压出来的文件时,先访问它,让它生成一个shell。

我们看finecms里是怎么修复的:

1.用一个随机目录来保存图片,这样就算我成功解压出来,猜不到目录名也访问不了,也无法产生竞争:

[php]

$temp = FCPATH.'cache/attach/'.md5(uniqid().rand(0, 9999)).'/';

[/php]

 

2.删除以后再exit出去,这样就算出错,也会删除残留的文件后再退出:

[php]

if ($this->pclzip->extract(PCLZIP_OPT_PATH, $temp, PCLZIP_OPT_REPLACE_NEWER) == 0) {

@dr_dir_delete($temp);

exit($this->pclzip->zip(true));

}

[/php]
看似已经万无一失。

但finecms没想到的是,我们可以构造一个“特别”的压缩包,这个压缩包里我的shell的文件名是“../../../shell.php”,这时我们就能够把shell直接解压到根目录下,我不用猜测目录名,不用惧怕被删除,直接拿下shell。

那么,请看我怎么构造这个压缩包。

漏洞证明:

先把自己的shell改名字成aaaaaaaaaaaaaaaaaaaa.php

之所以起这个名字,就是预留一些空间,方便我之后将文件名改成../../../aaaaaaaaaaa.php而不用怕字符串长度不对。

把文件直接打包成zip,用notepad++打开:

finecms 最新版v2.3.3前台getshell

 

 

将我画框的俩文件名的前9个字符改成../../../

finecms 最新版v2.3.3前台getshell

 

 

然后就大功告成。

注册用户,来到头像上传处,上传头像:

 

finecms 最新版v2.3.3前台getshell

 

 

抓包将刚才构造的压缩包贴进去:

 

finecms 最新版v2.3.3前台getshell

 

 

然后,网站根目录下就会有你的shell了:aaaaaaaaaaa.php

 

finecms 最新版v2.3.3前台getshell

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
没穿底裤
  • 本文由 发表于 2020年1月1日05:14:29
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   finecms 最新版v2.3.3前台getshellhttps://cn-sec.com/archives/75667.html

发表评论

匿名网友 填写信息