Skip to content

nixbro/Kasada-Solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Image Alt

Understanding Kasada Bot Protection: A High-Level Overview

A conceptual look at modern web protection systems* contact @Nixnode on telegram for more info.

What is Kasada?

Kasada is an enterprise-grade bot protection system used by major websites (PlayStation, Sony, Ticketmaster, etc.) to prevent automated access. Unlike simple rate limiting, Kasada uses sophisticated client-side challenges to distinguish humans from bots.

When you try to access a Kasada-protected API:

import requests
response = requests.post('https://protected-site.com/api/endpoint')
print(response.status_code)  # 429/403 Forbidden

You get blocked. Not because of your IP or user agent, but because you're missing cryptographic proof that you're a legitimate client.

Core Concepts

The Special Headers

Kasada-protected requests include custom headers that prove the client is legitimate:

x-kpsdk-ct: Client Token (CT)
x-kpsdk-cd: Client Data (CD) - contains proof-of-work answers
x-kpsdk-h: signature validating CT and CD match
x-kpsdk-v: Version identifier
x-kpsdk-r: Request identifier

The Three-Layer Defense

Layer 1: The p.js Script

  • Kasada injects a JavaScript file (p.js) into protected pages
  • This script is heavily obfuscated using VM bytecode
  • Contains a complete virtual machine that runs encrypted bytecode
  • Reverse engineering this is extremely difficult

Layer 2: Proof-of-Work Challenges

  • The script fetches cryptographic puzzles from Kasada servers
  • Client must solve these challenges (similar to crypto mining)
  • Solutions are included in the CD token
  • Server validates that answers are correct

Layer 3: Token Properties

  • CT Token: Expensive to generate, valid for 30 minutes, reusable
  • CD Token: Cheaper to generate, SINGLE-USE ONLY, must be fresh
  • HMAC Signature: Links CT and CD together, prevents token mixing/tampering

Why Simple Approaches Fail

Copying Headers Doesn't Work

The tokens contain:

  • Timestamps that must be recent
  • Challenge solutions that must match server-issued puzzles
  • HMAC signatures that validate token authenticity
  • Unique IDs tracked server-side to prevent reuse

TLS Fingerprinting Alone Isn't Enough

While Kasada does check TLS fingerprints, even with a perfect Chrome fingerprint, you still need:

  • Valid CT and CD tokens
  • Proof-of-work solutions
  • Correct HMAC signatures

The CD Reuse Problem

This is the critical insight:

Normal flow:
1. Browser makes request
2. KPSDK adds CT + CD headers
3. Request sent to server
4. Server validates and marks CD as "used"
5. CD token is now consumed

If you capture tokens from a completed request, the CD is already consumed. You can't reuse it.

Key Insights

The Token Lifecycle

CT Token Generation:

  • Generated when page first loads
  • Contains client fingerprint data
  • Expensive to compute
  • Valid for ~30 minutes
  • Same CT used across multiple requests

CD Token Generation:

  • Generated fresh for each request
  • Contains timestamp and challenge answers
  • Cheaper to compute
  • SINGLE-USE only
  • Must be recent (typically < 5 seconds old)

** Validation:**

This signature proves:

  • CT and CD come from the same session
  • Tokens haven't been tampered with
  • Request is authentic

The Request Interception Concept

The breakthrough insight:

Standard approach (doesn't work):
1. Make request → KPSDK adds tokens → Request completes
2. Capture tokens from completed request
3. CD is already consumed ❌

Caching Strategy

Since CT is expensive but reusable, and CD is cheap but single-use.

Technical Deep Dive

How p.js Protection Works

The Kasada script uses multiple obfuscation layers:

  1. VM Obfuscation: Core logic compiled to bytecode executed by embedded VM
  2. String Encryption: All strings encrypted and decrypted at runtime
  3. Control Flow Flattening: Code flow made non-linear and hard to trace
  4. Dead Code Injection: Fake code paths that never execute
  5. Variable Name Mangling: All variables renamed to meaningless names

This makes static analysis extremely difficult.

Proof-of-Work System

The CD token contains solutions to cryptographic challenges:

Challenge Structure:

  • Server provides puzzle parameters (difficulty, prefix, etc.)
  • Client must find solutions (like crypto mining)
  • Solutions are included in CD token
  • Server validates solutions match the challenge.

The "answers" array in CD contains these solutions.

Validation Checks

Server-side validates multiple aspects:

Timestamp Validation:

  • CD must be recent (typically < 5 seconds old)
  • Prevents replay attacks with old tokens

Uniqueness Validation:

  • Each CD has unique ID tracked server-side
  • Once used, marked as consumed
  • Prevents reuse of same CD

Challenge Validation:

  • Solutions must match server-issued challenges
  • Can't fake answers without solving

Signature Validation:

  • Signature binds CT and CD together
  • Prevents mixing tokens from different sessions
  • Ensures tokens haven't been modified

Get in Touch

Found this interesting? Have questions? Want to collaborate?

  • ⭐ Star the repo if you learned something
  • 💬 Start a discussion to share insights
  • 🤝 Contribute improvements

But most importantly: Use this knowledge ethically and responsibly. contact @Nixnode on telegram for more.

About

Kasada Bot Protection: A High-Level Overview

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published