
# CVE-2021-43297 개념 증명 익스플로잇 Hessian-Lite 역직렬화를 통해 Apache Dubbo <= 2.7.13에서 원격 코드 실행을 달성하는 개념 증명 익스플로잇입니다.
Apache Dubbo Hessian-Lite 3.2.11 및 이전 버전에는 잠재적인 RCE 공격 위험이 존재합니다. Hessian-Lite는 직렬화 예외가 발생할 때 관련 정보를 출력하는데, 이로 인해 악의적으로 커스터마이즈된 일부 Bean의 toString 메서드가 트리거되어 RCE 공격이 발생할 수 있습니다.
최초의 POC는 Apache Dubbo<=2.7.8에서만 RCE를 구현할 수 있었으며, 원리에 대한 설명은 선지(先知) 문서(심사 통과 후 돌아와서 수정)를 참조하세요. 투고 후 추가 연구를 통해 Apache Dubbo<=2.7.13에서도 RCE를 구현할 수 있음을 확인했으며, 원리 분석은 제 블로그 게시물을 참조하세요.
효과는 다음과 같습니다.

POC 활용 조건:
wget http://archive.apache.org/dist/zookeeper/zookeeper-3.3.3/zookeeper-3.3.3.tar.gz
tar zxvf zookeeper-3.3.3.tar.gz
cd zookeeper-3.3.3
cp conf/zoo_sample.cfg conf/zoo.cfg
vim conf/zoo.cfg
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
dataDir=/절대경로/zookeeper-3.3.3/data
# the port at which the clients will connect
clientPort=2181
mkdir data
touch data/myid
cd /private/var/tmp/zookeeper-3.3.3/bin
./zkServer.sh start
git clone https://github.com/apache/dubbo-samples.git
cd dubbo-samples/dubbo-samples-api
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>dubbomytest</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
<dubbo.version>2.7.6</dubbo.version>
<junit.version>4.12</junit.version>
<docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
<jib-maven-plugin.version>1.2.0</jib-maven-plugin.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
<maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
<image.name>${project.artifactId}:${dubbo.version}</image.name>
<java-image.name>openjdk:8</java-image.name>
<dubbo.port>20880</dubbo.port>
<zookeeper.port>2181</zookeeper.port>
<main-class>org.apache.dubbo.samples.provider.Application</main-class>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-common</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>2.7.3</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-naming</artifactId>
<version>4.15</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
provider 측과 로컬 모두 설치해야 하며, 의존성은 다음과 같습니다.
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-naming</artifactId>
<version>4.15</version>
</dependency>
IDEA에 dubbo-samples-api를 추가하고, zookeeper와 dubbo의 포트를 수정해야 합니다. 또한 Application.java에서 코드를 수정합니다:
service.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":" + zookeeperPort+"/?timeout=250000"));
높은 버전의 dubbo가 zookeeper에 연결할 때 연결 시간 초과로 실패하는 것을 방지합니다.
idea에서 dubbo-samples-api의 Application.java를 시작합니다.
시작 후 dubbo service started가 출력되면 dubbo가 정상적으로 시작된 것입니다.
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-common</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>2.7.3</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.51</version>
</dependency>
ExecTest.java를 컴파일한 후, HttpServer.java에서 ExecTest.class의 경로를 수정하고 HttpServer.main 메서드를 실행한 다음, 마지막으로 HessianLitePoc.main 메서드를 실행합니다.