Skip to content

AlphaDevelopmental/cookies-CTF_lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿช Cookie Security Lab

A comprehensive security CTF challenge for learning cookie vulnerabilities through hands-on exploitation

License: MIT Node.js Status

Overview

Cookie Security Lab is an educational platform designed for security professionals and students to practice identifying, exploiting, and mitigating cookie-related vulnerabilities. This lab provides 6 realistic vulnerabilities with hashed CTF flags, step-by-step walkthroughs, and secure pattern examples.

Perfect for:

  • ๐ŸŽ“ Security training programs
  • ๐Ÿ† CTF competitions
  • ๐Ÿ”ฌ Penetration testing practice
  • ๐Ÿ“š OWASP ASVS learning
  • ๐Ÿ›ก๏ธ Web application security courses

๐ŸŽฏ What You'll Learn

  • โœ… Cookie tampering for authorization bypass
  • โœ… XSS and session theft via missing HttpOnly
  • โœ… Over-broad cookie scope exploitation
  • โœ… Session fixation attacks
  • โœ… CSRF (Cross-Site Request Forgery)
  • โœ… Cookie value poisoning
  • โœ… Secure cookie patterns (HttpOnly, Secure, SameSite)
  • โœ… Server-side session management

๐Ÿšฉ CTF Challenges (6 Flags)

# Vulnerability Flag Difficulty
1 Client-Controlled Role Cookie FLAG{CLIENT_CONTROLLED_ROLE_59721BC5} โญ Easy
2 XSS Cookie Theft FLAG{XSS_COOKIE_THEFT_5C6EA866} โญโญ Medium
3 Broad Scope Cookie FLAG{BROAD_SCOPE_COOKIE_0DE7C8AB} โญ Easy
4 Session Fixation FLAG{SESSION_FIXATION_E3C79F1B} โญโญ Medium
5 CSRF Role Change FLAG{CSRF_ROLE_CHANGE_3051E639} โญโญ Medium
6 Cookie Poisoning FLAG{COOKIE_POISONING_252CD918} โญโญ Medium

๐Ÿ“‹ Prerequisites

  • Node.js โ‰ฅ 18 (Install)
  • npm (comes with Node.js)
  • Firefox or Chrome browser (recommended)
  • Burp Suite Community (optional, for advanced exercises)

โšก Quick Start

1. Clone Repository

git clone https://github.com/yourusername/cookie-security-lab.git
cd cookie-security-lab

2. Install Dependencies

npm install

3. Start Server

npm start

4. Open in Browser

Navigate to: http://localhost:3004


๐Ÿ“š Documentation

Document Purpose
CTF-Walkthrough.md Start here! Step-by-step flag collection guide
cookie-lab-guide.md Detailed vulnerability explanations & OWASP mappings
cookie-lab-server.js Well-commented vulnerable server code

๐ŸŽ“ Vulnerabilities Demonstrated

Vulnerability 1: Client-Controlled Role Cookie

  • Risk: Authorization bypass via cookie tampering
  • Method: DevTools or Burp Suite
  • Learning: Never trust client-side authorization

Vulnerability 2: Missing HttpOnly & Secure

  • Risk: JavaScript can steal session cookies; transmission over HTTP
  • Method: XSS simulation & console
  • Learning: HttpOnly is mandatory for session cookies

Vulnerability 3: Overly Broad Cookie Scope

  • Risk: Cookies sent with every request (images, stylesheets, etc.)
  • Method: DevTools Network tab
  • Learning: Use specific paths and domain restrictions

Vulnerability 4: Session Fixation

  • Risk: Attacker forces known session ID on victim
  • Method: URL parameter manipulation
  • Learning: Generate session IDs server-side only

Vulnerability 5: CSRF (Missing SameSite)

  • Risk: Malicious form can change user settings
  • Method: Form submission demo
  • Learning: Implement CSRF tokens and SameSite

Vulnerability 6: Cookie Poisoning

  • Risk: Server accepts arbitrary cookie values
  • Method: Query parameter injection
  • Learning: Never trust cookie inputs

๐Ÿ” Secure Reference Implementation

Each vulnerability includes a comparison with the secure pattern:

  • /secure/login โ€” Server-side session with opaque ID
  • /secure/admin โ€” Authorization via server-side lookup
  • Proper flags: HttpOnly, Secure, SameSite=Strict

๐Ÿ› ๏ธ Technology Stack

  • Backend: Express.js (Node.js)
  • Cookie Parser: cookie-parser
  • Crypto: Node.js built-in crypto module
  • Frontend: HTML/CSS (educational landing page)

๐Ÿ“ฆ Project Structure

cookie-security-lab/
โ”œโ”€โ”€ cookie-lab-server.js          # Main vulnerable server
โ”œโ”€โ”€ cookie-lab-guide.md           # Comprehensive guide
โ”œโ”€โ”€ CTF-Walkthrough.md            # Step-by-step solutions
โ”œโ”€โ”€ package.json                  # Dependencies
โ”œโ”€โ”€ README.md                     # This file
โ”œโ”€โ”€ LICENSE                       # MIT License
โ”œโ”€โ”€ .gitignore                    # Git ignore rules
โ””โ”€โ”€ .github/
    โ””โ”€โ”€ workflows/
        โ””โ”€โ”€ verify.yml            # CI/CD pipeline

๐Ÿš€ Features

โœจ 6 Unique Vulnerabilities - Each teaches distinct security concepts ๐ŸŽฏ Hashed CTF Flags - Anti-guessing, cryptographically verified ๐Ÿ“– Detailed Walkthroughs - Step-by-step exploitation guides ๐Ÿ”’ Secure Patterns - Compare vulnerable vs. secure implementations ๐Ÿท๏ธ OWASP ASVS Mapped - Links to security standards ๐Ÿ’ฌ Code Comments - Educational explanations throughout ๐Ÿงช CI/CD Pipeline - Automated verification


๐ŸŽฎ How to Complete the CTF

  1. Follow the walkthrough: Open CTF-Walkthrough.md
  2. Exploit each vulnerability: Use provided methods (DevTools, Burp, etc.)
  3. Collect flags: Each exploit returns a unique hashed flag
  4. Document learning: Take notes on security lessons
  5. Compare secure patterns: Review /secure/* endpoints

๐ŸŒ Searchable Keywords

This project helps you learn:

  • CTF (Capture The Flag)
  • Cookie Security
  • Web Vulnerabilities
  • OWASP ASVS
  • Session Management
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Penetration Testing
  • Security Training
  • Vulnerable Code Examples

โš ๏ธ Security Disclaimer

This lab intentionally contains security vulnerabilities for educational purposes.

  • โŒ Do NOT deploy in production
  • โŒ Do NOT use code patterns from this lab in real applications
  • โœ… Study the vulnerabilities and security lessons
  • โœ… Always implement secure patterns from /secure/* examples

๐Ÿ“ Lab Report Template

When completing this lab, document:

  1. Vulnerability Name - What was exploited?
  2. Root Cause - Why was it vulnerable?
  3. Exploitation Method - How did you exploit it?
  4. Flag - What did you collect?
  5. Mitigation - How would you fix it?
  6. OWASP ID - Reference standard

๐Ÿ”— Learning Resources


๐Ÿ’ก Tips for Success

  1. Use Developer Tools - F12 in Firefox/Chrome, especially Application tab
  2. Monitor Network Traffic - Watch cookie headers in real-time
  3. Use Burp Suite - Repeater tab is excellent for testing variations
  4. Read Console Logs - Server prints helpful debugging info
  5. Compare Secure Code - /secure/* shows proper patterns
  6. Document Everything - Take screenshots of each flag

๐Ÿค Contributing

Found an issue or have suggestions?

  • Open an issue on GitHub
  • Submit a pull request with improvements
  • Suggest new vulnerabilities to demonstrate

๐Ÿ“„ License

This project is licensed under the MIT License - see LICENSE file for details.


๐Ÿ™ Acknowledgments

  • Built for security education and OWASP awareness
  • Inspired by real-world cookie vulnerabilities
  • References: PortSwigger, OWASP, RFC 6265bis

๐Ÿ“ž Support

  • ๐Ÿ“– Read CTF-Walkthrough.md for step-by-step help
  • ๐Ÿ“š See cookie-lab-guide.md for detailed explanations
  • ๐Ÿ”ง Check server logs for debugging info
  • โ“ Review code comments for implementation details

Happy learning! ๐ŸŽ“ Collect all 6 flags and master cookie security! ๐Ÿšฉ

About

๐Ÿช Cookie Security Lab - A comprehensive CTF challenge demonstrating 6 cookie vulnerabilities with hands-on exploitation exercises, hashed flags, and secure patterns for learning.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors