|
1 | 1 | # CTF Platform |
2 | 2 |
|
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. |
4 | 4 |
|
5 | | -## Features |
| 5 | +## Quick Start (Local Development) |
6 | 6 |
|
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 |
135 | 13 | ``` |
| 14 | +> [!NOTE] |
| 15 | +> You can use the bash script in backend/scripts/ctfImagePrep.sh |
136 | 16 |
|
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 |
183 | 18 | ```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 |
197 | 21 | ``` |
198 | 22 |
|
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 | +``` |
200 | 30 |
|
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 | +``` |
209 | 38 |
|
210 | | -## Contributing |
| 39 | +For detailed instructions, see the **[Setup Guide](docs/setup.md)**. |
211 | 40 |
|
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 |
216 | 42 |
|
217 | | -## License |
| 43 | +- `backend/`: Node.js Express API. |
| 44 | +- `frontend/`: React application. |
| 45 | +- `docs/`: Technical documentation and architecture. |
218 | 46 |
|
219 | | -See [LICENSE](LICENSE) file for details. |
| 47 | +## Documentation Index |
220 | 48 |
|
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)** |
222 | 53 |
|
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. |
0 commit comments