Skip to content

Commit 30dc67f

Browse files
authored
Feat(docs): update docs
1 parent 0056c35 commit 30dc67f

9 files changed

Lines changed: 305 additions & 1054 deletions

File tree

README.md

Lines changed: 39 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -1,224 +1,55 @@
11
# CTF Platform
22

3-
A platform powered by **AWS** to host and solve **Capture The Flag (CTF)** challenges. This platform allows users to launch isolated Docker containers for each challenge, providing a secure environment for solving CTF problems.
3+
A secure platform for hosting and solving Capture The Flag (CTF) challenges. Isolated Docker containers are provided for each user instance to ensure a clean solving environment.
44

5-
## Features
5+
## Quick Start (Local Development)
66

7-
- User authentication and authorization (JWT)
8-
- Dynamic Docker container management for CTF challenges
9-
- Flag submission and tracking
10-
- Automatic cleanup of expired instances
11-
- User progress tracking
12-
13-
## Quick Start
14-
15-
### Prerequisites
16-
17-
- Node.js 25.x
18-
- MongoDB 6.0+
19-
- Docker 20.10+
20-
21-
### Backend Setup
22-
23-
1. **Clone the repository**
24-
```bash
25-
git clone https://github.com/sfeedbackx/ctf_platform.git
26-
cd ctf_platform/backend
27-
```
28-
29-
2. **Install dependencies**
30-
```bash
31-
npm install
32-
```
33-
34-
3. **Configure environment**
35-
Create a `.env` file in the `backend/` directory:
36-
```env
37-
PORT=3000
38-
NODE_ENV=development
39-
SERVER_HOST=localhost
40-
DB_URL=mongodb://localhost:27017/ctf_platform
41-
SECRET=your-secret-key-change-this-in-production
42-
MAX_AGE=604800000
43-
```
44-
45-
4. **Start MongoDB and Docker**
46-
```bash
47-
# Start MongoDB (Linux/Mac)
48-
sudo systemctl start mongod
49-
50-
# Verify Docker is running
51-
docker ps
52-
```
53-
54-
5. **Run the server**
55-
```bash
56-
# Development mode (with hot reload)
57-
npm run dev
58-
59-
# Production mode
60-
npm run build
61-
npm start
62-
```
63-
64-
The backend API will be available at `http://localhost:3000`
65-
66-
### Frontend Setup
67-
68-
**Note**: The frontend is a React application. Setup instructions:
69-
70-
1. **Navigate to frontend directory**
71-
```bash
72-
cd frontend
73-
```
74-
75-
2. **Install dependencies**
76-
```bash
77-
npm install
78-
```
79-
80-
3. **Configure environment**
81-
Create a `.env` file:
82-
```env
83-
VITE_API_URL=http://localhost:3000/api/v1
84-
# or REACT_APP_API_URL (depending on your build tool)
85-
```
86-
87-
4. **Start development server**
88-
```bash
89-
npm run dev
90-
```
91-
92-
5. **Configure CORS in backend**
93-
94-
**Important**: CORS is currently not configured. You need to add CORS middleware:
95-
96-
```bash
97-
cd backend
98-
npm install cors @types/cors
99-
```
100-
101-
Then update `backend/src/app.ts`:
102-
```typescript
103-
import cors from 'cors';
104-
105-
app.use(cors({
106-
origin: process.env.FRONTEND_URL || 'http://localhost:5173',
107-
credentials: true
108-
}));
109-
```
110-
111-
## Project Structure
112-
113-
```
114-
ctf_platform/
115-
├── backend/ # Backend API server (Node.js + Express + TypeScript)
116-
│ ├── src/
117-
│ │ ├── config/ # Configuration and database setup
118-
│ │ ├── controller/ # Business logic
119-
│ │ ├── middlewares/ # Express middlewares
120-
│ │ ├── models/ # Mongoose models
121-
│ │ ├── router/ # Route definitions
122-
│ │ ├── types/ # TypeScript types
123-
│ │ ├── utils/ # Utility functions
124-
│ │ ├── app.ts # Express app configuration
125-
│ │ └── server.ts # Server entry point
126-
│ ├── scripts/ # Migration scripts
127-
│ └── package.json
128-
├── frontend/ # Frontend application (to be implemented)
129-
└── docs/ # Documentation
130-
├── architecture.md # System architecture
131-
├── api.md # API documentation
132-
├── setup.md # Detailed setup guide
133-
├── sequences.md # Sequence diagrams
134-
└── security.md # Security considerations
7+
### 1. Build Challenge Images
8+
```bash
9+
git clone https://github.com/sfeedbackx/ssrf-race.git
10+
cd ssrf-race/backend && docker build -t ctf_ssrf_race_backend .
11+
cd ../frontend && docker build -t ctf_ssrf_race_frontend .
12+
docker network create ctf_ssrf_race
13513
```
14+
> [!NOTE]
15+
> You can use the bash script in backend/scripts/ctfImagePrep.sh
13616
137-
## Naming Convention
138-
139-
- Constants: `UPPER_SNAKE_CASE`
140-
- Variables & Functions: `camelCase`
141-
- Classes: `UpperCamelCase`
142-
143-
## Documentation
144-
145-
Comprehensive documentation is available in the `docs/` directory:
146-
147-
- **[Architecture](docs/architecture.md)**: System architecture and design decisions
148-
- **[API Documentation](docs/api.md)**: Complete API reference
149-
- **[Setup Guide](docs/setup.md)**: Detailed setup instructions
150-
- **[Sequence Diagrams](docs/sequences.md)**: Visual flow diagrams
151-
- **[Security](docs/security.md)**: Security considerations and gaps
152-
153-
## Important Security Notes
154-
155-
**Before Production Deployment**:
156-
157-
1. **CORS**: Not configured - must be added for frontend communication
158-
2. **Rate Limiting**: Not implemented - critical for preventing abuse
159-
3. **Database Security**: Database is exposed until AWS migration - use strong credentials and restrict access
160-
161-
See [Security Documentation](docs/security.md) for details.
162-
163-
## API Endpoints
164-
165-
### Authentication
166-
- `POST /api/v1/signup` - Create user account
167-
- `POST /api/v1/login` - Authenticate user
168-
- `POST /api/v1/logout` - Logout user
169-
170-
### CTF Challenges
171-
- `GET /api/v1/ctfs` - List all CTF challenges
172-
- `POST /api/v1/ctfs/:id/instances` - Start CTF instance
173-
- `GET /api/v1/ctfs/instances` - Get active instance
174-
- `PATCH /api/v1/ctfs/instances/:id` - Stop instance
175-
- `PATCH /api/v1/ctfs/:id` - Submit flag
176-
177-
See [API Documentation](docs/api.md) for complete details.
178-
179-
## Development
180-
181-
### Available Scripts
182-
17+
### 2. Prepare Infrastructure
18318
```bash
184-
# Development
185-
npm run dev # Start dev server with hot reload
186-
npm run build # Build TypeScript to JavaScript
187-
npm start # Start production server
188-
189-
# Code Quality
190-
npm run lint # Run ESLint
191-
npm run format # Format code with Prettier
192-
npm run check # Check code formatting
193-
194-
# Utilities
195-
npm run migrate # Run database migrations
196-
npm run docker_test # Test Docker utilities
19+
cd ctf_platform/backend
20+
docker compose up -d mongo docker-socket-proxy
19721
```
19822

199-
## Technology Stack
23+
### 3. Start Backend
24+
```bash
25+
cp env.example .env
26+
npm install
27+
npm run migrate
28+
npm run dev
29+
```
20030

201-
### Backend
202-
- **Runtime**: Node.js 25.x
203-
- **Framework**: Express.js 5.2.1
204-
- **Language**: TypeScript 5.9.3
205-
- **Database**: MongoDB (Mongoose 9.0.2)
206-
- **Authentication**: JWT (jsonwebtoken 9.0.3)
207-
- **Docker**: dockerode 4.0.9
208-
- **Scheduling**: node-cron 4.2.1
31+
### 4. Start Frontend
32+
```bash
33+
cd ../frontend
34+
cp env.example .env
35+
npm install
36+
npm run dev
37+
```
20938

210-
## Contributing
39+
For detailed instructions, see the **[Setup Guide](docs/setup.md)**.
21140

212-
1. Follow the naming conventions
213-
2. Run `npm run lint` before committing
214-
3. Update documentation for new features
215-
4. Add tests for new functionality
41+
## Project Structure
21642

217-
## License
43+
- `backend/`: Node.js Express API.
44+
- `frontend/`: React application.
45+
- `docs/`: Technical documentation and architecture.
21846

219-
See [LICENSE](LICENSE) file for details.
47+
## Documentation Index
22048

221-
## Acknowledgements
49+
- **[Full Setup Guide](docs/setup.md)**
50+
- **[Architecture](docs/architecture.md)**
51+
- **[API Reference](docs/api.md)**
52+
- **[Security Overview](docs/security.md)**
22253

223-
- Backend setup inspired by Aman Mittal's Express + TypeScript guide:
224-
- [Backend setup reference](https://blog.logrocket.com/express-typescript-node/) — Aman Mittal
54+
## Contributing
55+
Please refer to our documentation before submitting pull requests. Ensure all code remains linter-compliant and includes necessary tests.

backend/env.example

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
# Server Configuration
21
PORT=3000
32
NODE_ENV=development
43
SERVER_HOST=localhost
54

65
# Database Configuration
7-
# For development with npm run dev (use localhost)
8-
DB_URL=mongodb://localhost:27017/ctf_platform
9-
# For docker-compose setup (use container name)
6+
# Use localhost:27017 if running backend on your host (most common for dev)
7+
DB_URL=mongodb://root:password@localhost:27017/ctf_platform?authSource=admin
8+
# Use mongodb service name if running backend INSIDE docker
109
# DB_URL=mongodb://root:password@mongodb:27017/ctf_platform?authSource=admin
1110

1211
# JWT Configuration
13-
SECRET=your-secret-key-change-this-in-production-minimum-32-characters
12+
SECRET=change-me-32-characters-minimum
1413
MAX_AGE=604800000
1514

1615
# Docker Configuration
17-
# Leave empty for default Docker socket (when using docker-compose with docker-socket-proxy)
18-
# For development with docker-compose, leave empty or use: http://dockerproxy:2375
19-
# For local development without docker-compose, leave empty
20-
DOCKER_HOST=tcp://dockerproxy:2375
16+
# Leave empty for local Docker socket (default)
17+
# Use tcp://dockerproxy:2375 when using docker-socket-proxy in compose
18+
DOCKER_HOST=
2119

22-
SSRF_FLAG=cll{ss098fud63c2xgXPuVPimY3ZmkDmFsI+RfhCdqccOZwJKBqQI=}
20+
# CTF / SSRF
21+
# Used by migrateScript and challenge frontend container env
22+
SSRF_FLAG=REPLACE_ME_WITH_FLAG
Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ services:
55
image: mongo:8.0
66
container_name: mongodb
77
restart: always
8-
ports:
9-
- "27017:27017"
8+
# Uncomment this to connect to the db (exposed to the host)
9+
#ports:
10+
# - "27017:27017"
1011
environment:
1112
MONGO_INITDB_ROOT_USERNAME: root
1213
MONGO_INITDB_ROOT_PASSWORD: password
@@ -24,8 +25,8 @@ services:
2425
docker-socket-proxy:
2526
container_name: dockerproxy
2627
# Uncomment the following ports section for development
27-
ports:
28-
- "2375:2375"
28+
# ports:
29+
# - "2375:2375"
2930
environment:
3031
- CONTAINERS=1 # create/start/stop/inspect containers
3132
- POST=1 # CRITICAL: allow POST requests
@@ -50,24 +51,43 @@ services:
5051
- ctf-network
5152
app:
5253
build:
53-
context: .
54-
dockerfile: Dockerfile
54+
context: ./backend
55+
dockerfile: dockerfile
5556
target: production
5657
container_name: ctf-backend
5758
restart: unless-stopped
59+
# you don't really need to Uncomment this because you will use npm run dev
5860
# ports:
5961
# - "${PORT:-3000}:3000"
6062
volumes:
61-
- ./src/utils/ca.pem:/app/dist/utils/key.pem:ro
63+
- ./backend/src/utils/ca.pem:/app/dist/utils/key.pem:ro
6264
env_file:
63-
- .env
65+
- ./backend/.env
6466
networks:
6567
- ctf-network
6668
depends_on:
6769
docker-socket-proxy:
6870
condition: service_started
6971
mongo:
7072
condition: service_healthy
73+
app-frontend:
74+
build:
75+
context: ./frontend/
76+
dockerfile: Dockerfile
77+
target: production
78+
container_name: ctf-frontend
79+
restart: unless-stopped
80+
# this need to access to frontend
81+
ports:
82+
- "8080:80"
83+
# to be honest we don't really have env for frontend
84+
#env_file:
85+
#- ..frontend/
86+
networks:
87+
- ctf-network
88+
depends_on:
89+
- app
90+
7191
networks:
7292
ctf-network:
7393
driver: bridge

0 commit comments

Comments
 (0)