Skip to content

Yash09042004/YashzCTF_Backend_Frontend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CTF Backend

A high-performance, concurrent Go backend for Capture The Flag (CTF) competitions.

Features

  • Real-time leaderboard with intelligent caching
  • Atomic flag validation preventing race conditions
  • User progress tracking across multiple challenge levels
  • Optimized performance with prefetching and in-memory caching
  • Graceful shutdown and signal handling

Tech Stack

  • Go - Backend server
  • MongoDB - Database
  • CORS-enabled REST API

Prerequisites

  • Go 1.16+
  • MongoDB instance

Setup

  1. Install dependencies

    go mod download
  2. Set environment variables

    export MONGODB_URI="your_mongodb_connection_string"
    export PORT=10000  # Optional, defaults to 10000
  3. Run the server

    go run main.go

API Endpoints

Method Endpoint Description
GET /api/test Health check
GET /getLevel?userId={id} Get user's current level
POST /checkFlag Submit a flag
POST /resetUser Reset user progress
POST /deleteUser Delete a user
GET /api/leaderboard Get top 100 players
GET /api/challenges List all challenges

Request Examples

Check Flag

curl -X POST http://localhost:10000/checkFlag \
  -H "Content-Type: application/json" \
  -d '{"userId": "player1", "flag": "CTF{...}"}'

Get Leaderboard

curl http://localhost:10000/api/leaderboard

Performance Features

  • O(1) challenge lookups via hash maps
  • User data prefetching for reduced latency
  • Leaderboard caching with background refresh
  • Database indexes for optimized queries
  • Atomic operations for thread-safety

Development

Run with race detector:

go run -race main.go

Build for production:

go build -o ctf-server main.go

License

MIT

About

Backend and frontend of the ctf

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages