Caption
Recon
HTTP (8080)
GitBucket

Default Creds
Nothing to see as unauthenticated user. Search for defaults:

Creds:
root:root
Login is successful

Leaked Creds
User credentials in commit of frontend application:http://caption.htb:8080/root/Caption-Portal/commit/0e3bafe458d0b821d28dde7d6f43721f479abe4a

Creds:
margo:vFr&cS2#0!
Logservice
There's also Logservice application.

http://caption.htb:8080/root/Logservice/blob/main/server.go
H2 Database
Abusing H2 Database ALIASRemote Code Execution in Three Acts: Chaining Exposed Actuators and H2 Database Aliases in Spring Boot 2


SSH
User.txt
Frontend App Backend Source
Creds:
admin:cFgjE@0%l0
Still doesn't work because HAProxy is restricting any request being made to server.
HTTP (80)

We are able to authenticate as margo

Also admin from source, but we can't do anything. /logs and /download is blocked by HAProxy.
Do port forwarding to bypass the proxy.
Logservice Exploit
/logs is now accessible, but /download fails. The previous application (Logservice) is probably running as privileged user.
log_service.thrift:
Thrift has a guide: https://thrift.apache.org/tutorial/py.html
We can use generated code by thrift to work with the service and inject malicious payload.
Root
Root.txt
Hashes
Past Root
varnish > default.vcl
ruth > bot.py
ruth > varnish_logs.sh
Intended Route
I think on release date everything went wrong and nobody got the intended route 😄
As I kept digging the source code I realized that real chain of attack was
GitBucket
Source Code
Guessy work
XSS via header
Cache poison
admin
HAProxy bypass
LFI
Fuzzing
Service on 9090
On GitBucket we can login with default credentials (root:root) and browse source of 2 applications. For now we only need Caption-Portal. Now the trickiest part is figuring out how to perform anything at all.
If you look in the source you can view something like this:
Now comes the guessy work, considering we don't know how this value is populated there's only plug and play situation...
From the GitBucket we have credentials for margo user and we can fuzz for headers which effect how url works.
So because we can control the contents of script we can also inject and gain XSS, but first let's test it.

If you notice age header increased, this is because Varnish is a caching HTTP reverse proxy service and whatever we send is cached and later used. If I make request to XXX and then you make same request you will get cached page from server and not a new one.

Anyway, check your server listener and what do you know! someone is visiting the website frequently so maybe we can steal their cookies too?
XCGFULLBAN can be used to clear cache, or wait 120sec
Now that we are logged in as other user (presumably higher then margo) we can browse around. If we go to /logs we get denied because of HAProxy
http://caption.htb:8080/root/Caption-Portal/blob/main/config/haproxy/haproxy.cfg
Basically any request to /logs or /download is blocked! BUT the path is only filtering case, so what prevents us from injecting a forward slash at the front? (or similar payload)

Absolutely nothing.
Great, we can view log files like:view-source:http://caption.htb//download?url=http://127.0.0.1:3923/ssh_logs
But why is request made to internal webapp?
Searching for this service we end up on GitHub and exploit:

copyparty 1.8.2 - Directory Traversal
LFI like: http://caption.htb//download?url=http://127.0.0.1:3923/.cpr/../../../../../etc/passwd will not work because we need to urlencode, but it will not work, because we need to urlencode again for the second request.

There's 3 valid users: root, margo and ruth
Automate the file grabbing:
Since we don't know what we are looking for and /proc/self/* doesn't work, fuzz.
I first focused on SSH keys. Had to resort to sockets because // was not accepted in the url by requests
We gained margo ssh key and can login as her. (SSH key is from Arena VPN, so it may not work on public IP)
From this point on the path to root is the same, exploit the service on port 9090 (thrift) and that's it, I guess.
Could be useful: https://github.com/kacperszurek/exploits/blob/master/GitBucket/gitbucket-unauthenticated-rce.md
Intended Route 2 (HAProxy bypass)
After some time machine got patched, root:root was removed and HAProxy was also fixed...

HAProxy is vulnerable to H2 Smuggling Request
Upgrade Header Smugglingh2csmuggler

Now that we can bypass the proxy the steps are relatively the same:
Get private key:
This step can be automated, but at this point we know this file exists...
Last updated