JWT Penetration Test

Analyzing Core JWT Vulnerabilities and Attack Scenarios

JWT (JSON Web Token) is widely used for modern authentication, but its flexibility is a double-edged sword. As a senior mentor, I’ve seen countless implementations fail because developers treated JWT as a “black box” that is inherently secure. In reality, the security of a JWT depends entirely on how the server validates it.

The majority of successful JWT attacks focus on one thing: bypassing the server’s signature verification logic. If we can nullify the signature, we can manipulate the payload at will. Let’s look at the attack vectors you must master.

1. Signature Bypass: The alg:none Attack

This is the most fundamental vulnerability and your mandatory first check.

  • Overview: The attacker modifies the alg (algorithm) claim to none and removes the signature part. If the server-side library accepts this, it trusts the payload implicitly without any verification.
  • Attack Scenario:
    1. Change header to {"alg": "none", "typ": "JWT"}.
    2. Remove the signature (the third part).
    3. Submit as Header.Payload. (note the trailing dot).
  • Pentesting Focus: Use Burp Suite’s JWT Editor to automate this. A 200 OK response often indicates a critical failure in the library configuration.

2. Algorithm Confusion: RS256 to HS256

A fascinating attack that exploits a logic flaw in how public keys are handled.

  • Overview: A server expecting an asymmetric token (RS256) might be tricked into using its public key as a symmetric secret key for an HS256 signature.
  • Attack Scenario:
    1. Obtain the server’s public key (often from /.well-known/jwks.json).
    2. Change alg from RS256 to HS256.
    3. Sign the forged token using the public key as the secret key.
  • Pentesting Focus: Check if the server strictly enforces the algorithm type regardless of what is sent in the header.

3. Weak Secret Key Guessing (HS256)

If the server uses a weak secret for symmetric signing, the entire security model collapses.

  • Overview: Developers often use simple strings like “secret” or “password123” for testing and forget to change them.
  • Attack Scenario: Use an offline brute-force attack with a wordlist.
  • Key Command:
    1
    2
    
    # Cracking a JWT secret key with Hashcat (Mode 16500)
    hashcat -m 16500 -a 0 <jwt_token> <wordlist>
    

4. Header Parameter Injection: jku and kid

  • jku (JWK Set URL): If the server trusts an arbitrary URL in this header, we can point it to our own server hosting a malicious public key.
  • kid (Key ID): If the kid is used to build a file path, we can use Path Traversal (e.g., ../../../../dev/null) to force the server to use a predictable key.

Defense Strategies: Hardening JWT Implementation

Defending against these attacks requires a proactive “trust but verify” approach on the server side.

1. Use Trusted Libraries and Enforce Allowlists

Never implement JWT logic from scratch. Use well-vetted libraries and, most importantly, enforce a strict algorithm allowlist (e.g., only allow RS256). This single step negates most algorithm confusion and alg:none attacks.

2. Strong Key Management

For HS256, use cryptographically strong, long random secrets. For asymmetric algorithms, keep the private key in a secure vault (KMS, Vault) and rotate it periodically.

3. Sanitize Header Inputs

If your implementation uses jku or kid, validate them against a strict whitelist of domains or formats (like UUIDs). Filter out special characters to prevent directory traversal.

4. Short-Lived Tokens and Revocation

Always set a short exp (expiration) time. Since JWTs are stateless, you need a server-side “black-list” or revocation mechanism to invalidate tokens when a user logs out or a compromise is detected.

Useful Tools for JWT Pentesting


JWT 핵심 취약점 분석 및 공격 시나리오

JWT(JSON Web Token)는 현대적인 인증 방식에서 널리 사용되지만, 그 유연함은 양날의 검과 같습니다. 선배로서 제가 본 많은 사례에서 개발자들은 JWT를 그 자체로 안전한 “블랙박스”처럼 다루는 실수를 범하곤 합니다. 하지만 실상은 서버가 이를 어떻게 검증하느냐에 따라 보안성이 결정됩니다.

성공적인 JWT 공격의 대부분은 서버의 서명 검증 로직을 우회하는 데서 시작합니다. 서명만 무력화할 수 있다면, 페이로드의 내용을 원하는 대로 조작하여 서버를 기만할 수 있습니다. 여러분이 반드시 마스터해야 할 공격 벡터들을 살펴보겠습니다.

1. 서명 검증 우회: alg:none 공격

가장 기본적이면서도 펜테스팅 시 가장 먼저 확인해야 하는 취약점입니다.

  • 개요: 공격자는 헤더의 alg 클레임을 none으로 설정하고 서명 부분을 제거합니다. 서버 측 라이브러리가 이를 허용하면, 아무런 검증 없이 페이로드의 내용을 신뢰하게 됩니다.
  • 공격 시나리오:
    1. 헤더를 {"alg": "none", "typ": "JWT"}로 변경합니다.
    2. 서명(세 번째 부분)을 제거합니다.
    3. Header.Payload. (마지막 점 포함) 형식으로 전송합니다.
  • 펜테스팅 핵심: Burp Suite의 JWT Editor를 사용해 자동화할 수 있습니다. 200 OK 응답이 온다면 라이브러리 설정에 치명적인 결함이 있음을 의미합니다.

2. 알고리즘 혼동 공격: RS256에서 HS256으로

비대칭키의 특성을 악용하는 매우 흥미로운 로직 공격입니다.

  • 개요: RS256(비대칭키)을 기대하는 서버를 속여, 서버의 공개키(Public Key)를 HS256(대칭키)의 비밀키처럼 사용하게 만드는 방식입니다.
  • 공격 시나리오:
    1. 서버의 공개키를 획득합니다 (보통 /.well-known/jwks.json에서 확인 가능).
    2. algRS256에서 HS256으로 변경합니다.
    3. 획득한 공개키를 비밀키로 사용하여 조작된 토큰에 서명합니다.
  • 펜테스팅 핵심: 서버가 헤더에 명시된 알고리즘을 맹목적으로 따르지 않고, 서버에 설정된 알고리즘 타입을 엄격히 강제하는지 확인해야 합니다.

3. 취약한 비밀키 추측 공격 (HS256)

대칭키 방식에서 비밀키 자체가 약하면 전체 보안 모델이 무너집니다.

  • 개요: 개발자가 테스트를 위해 “secret”이나 “123456” 같은 단순한 문자열을 사용하고 운영 환경에서도 이를 방치하는 경우입니다.
  • 공격 시나리오: 오프라인 무차별 대입 공격 도구를 사용합니다.
  • 핵심 명령어:
    1
    2
    
    # Hashcat을 이용한 JWT 비밀 키 크래킹 (Mode 16500)
    hashcat -m 16500 -a 0 <jwt_token> <wordlist>
    

4. 헤더 파라미터 인젝션: jkukid

  • jku (JWK Set URL): 서버가 이 헤더에 포함된 URL을 검증 없이 신뢰한다면, 공격자의 서버에 호스팅된 악의적인 공개키를 참조하게 만들 수 있습니다.
  • kid (Key ID): kid 값이 파일 경로를 구성하는 데 사용된다면, 경로 조작(Path Traversal) 공격을 통해 서버가 예측 가능한 파일(예: /dev/null)을 키로 사용하도록 강제할 수 있습니다.

JWT 취약점 대응 및 완화 방안

이러한 공격을 막기 위해서는 서버 측에서 “신뢰하되 검증하는” 철저한 방어 전략이 필요합니다.

1. 라이브러리 최신화 및 화이트리스트 적용

보안 로직을 직접 구현하지 말고 검증된 라이브러리를 사용하세요. 가장 중요한 것은 허용할 알고리즘 화이트리스트(예: RS256만 허용)를 서버에 명시적으로 설정하는 것입니다. 이 조치만으로도 대부분의 알고리즘 혼동 및 alg:none 공격을 원천 차단할 수 있습니다.

2. 강력한 키 관리

HS256을 사용한다면 충분히 길고 무작위한 비밀키를 사용하세요. 비대칭 알고리즘의 경우 개인키는 KMS나 Vault 같은 안전한 저장소에 보관하고 주기적으로 갱신해야 합니다.

3. 헤더 입력값 검증

jkukid를 사용해야 한다면, 허용된 도메인이나 특정 형식(UUID 등)인지 화이트리스트 기반으로 검증하세요. 특히 파일 경로 조작에 쓰일 수 있는 특수문자를 엄격히 필터링해야 합니다.

4. 짧은 만료 시간과 토큰 폐기 메커니즘

exp 클레임을 통해 토큰의 수명을 짧게 유지하세요. JWT는 상태가 없으므로(Stateless), 사용자가 로그아웃하거나 침해 사고가 의심될 때 즉시 토큰을 무효화할 수 있는 서버 측 폐기 목록(Black-list)을 구현하는 것이 좋습니다.

JWT 펜테스팅 추천 도구