Skip to content

Commit 71b07e1

Browse files
authored
Merge pull request #60 from abs0lut3pwn4g3/gssoc20-dev
**Release v1.0** New features: - [x] Multiple boxes support (closes issue #17) - [x] Challenges page (closes issue #56). Along with tag and category models for organization. - [x] CTF settings and websites are now stored in database and can easily be changed from the new `/setup` view. (Closes issue #55) - [x] WTForm class for Machine for editing/creating new machines. - [x] Implemented thorough and efficient caching with use of "Flask-Caching" and "Redis". - [x] Now uses flask factory app method so the various flask extensions can be well-managed. Changes: - [x] Define redis service in `docker-compose.yml` - [x] Redis add-on has been added to `app.json`. - [x] `ADMIN_EMAIL`, and mail related env variables added in `app.json`. - [x] Flag submission is now in a modal. - [x] DB models are now in their respective folders in `models.py` - [x] Optimized scoreboard's detail fetching - [x] Features such as searching and exporting and new dark theme for `Admin Controls` (closes issues #1, #16, #36 ) - [x] Some utility functions such as `@admin_only` decorator. - [x] macros have been defined in templates for reusability.
2 parents 85a4b6a + cf975e7 commit 71b07e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2070
-790
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ before_install:
1919

2020
install:
2121
- "pip install -r src/requirements.txt"
22-
- "python src/create_db.py"
22+
- "python src/create_db.test.py"
2323

2424
before_script:
2525
- black . --check
2626
script:
27-
- flake8 . --count --max-line-length=88 --show-source --statistics
27+
- flake8 . --count --max-line-length=88 --show-source --statistics

CONTRIBUTING.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424

2525
## This project makes use of the following Flask libraries
2626

27-
* Flask-blueprints for modularity and clean codebase,
27+
* Blueprints for modularity and clean codebase,
2828
* Flask-admin for Admin views and easy realtime management,
29-
* Flask-SQLAlchemy for SQL models,
29+
* Flask-SQLAlchemy for SQL models,
30+
* Flask-Caching with redis for efficient caching,
3031
* Flask-login for session handling,
3132
* Flask-wtf for responsive forms,
3233
* Flask-mail for mail service,
@@ -43,7 +44,7 @@ $ black .
4344
```
4445

4546
```bash
46-
$ flake8 src/ flake8 . ---max-line-length=88 --show-source --statistics
47+
$ flake8 src/ --max-line-length=88 --show-source --statistics
4748
```
4849

4950
if flake8 shows any errors or warnings, please fix the changes in a new commit and squash all the commits into one before submitting the PR.

Dockerfile

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1-
FROM python:3
1+
FROM python:3.8.2-alpine3.11
22

3+
MAINTAINER eshaan7bansal@gmail.com
4+
5+
# Env
6+
RUN export DATABASE_URL="postgres://${DB_USER}:${DB_PASSWORD}@postgres:${DB_PORT}/${DB_NAME}" \
7+
&& export REDIS_URL="redis://redis:6379/0"
8+
9+
# update and install packages
10+
RUN apk update \
11+
&& apk add libpq postgresql-dev \
12+
&& apk add build-base \
13+
&& apk add --no-cache git libssl1.1 g++ make libffi-dev
14+
15+
# Add a new low-privileged user
16+
RUN adduser --shell /sbin/login www-data -DH
17+
18+
# Install RTB-CTF-Framework
319
WORKDIR /usr/src/app
420
COPY src ./
5-
RUN pip install --no-cache-dir -r requirements.txt
6-
EXPOSE 8080
7-
RUN chown -R 1001:1001 .
8-
USER 1001
21+
RUN pip install --no-cache-dir -r requirements.txt \
22+
&& chown -R www-data ./
23+
24+
USER www-data
25+
26+
EXPOSE 8000
927
RUN chmod +x /usr/src/app/docker-entrypoint.sh
1028
ENTRYPOINT [ "/usr/src/app/docker-entrypoint.sh" ]

README.md

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
<a href="https://travis-ci.com/abs0lut3pwn4g3/RTB-CTF-Framework" target="_blank">
1111
<img alt="Build Status" src="https://travis-ci.com/abs0lut3pwn4g3/RTB-CTF-Framework.svg?branch=gssoc20-dev"/>
1212
</a>
13-
<!-- <a href="https://lgtm.com/projects/g/abs0lut3pwn4g3/RTB-CTF-Framework/context:python">
13+
<a href="https://lgtm.com/projects/g/abs0lut3pwn4g3/RTB-CTF-Framework/context:python">
1414
<img alt="Language grade: Python" src="https://img.shields.io/lgtm/grade/python/g/abs0lut3pwn4g3/RTB-CTF-Framework.svg?logo=lgtm&logoWidth=18"/>
15-
</a> -->
15+
</a>
1616
<a href="https://github.com/psf/black" target="_blank">
1717
<img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"/>
1818
</a>
@@ -30,50 +30,34 @@ The main purpose of this project is to serve as a scoring engine and CTF manager
3030

3131
## Features
3232

33-
##### For CTF hosters
34-
* A page to show relevant details about the machine such as name, IP, OS, points and difficulty level.
33+
* Machines listing with fields: name, IP, OS, points and difficulty level.
34+
* Challenges listing with fields: title, description, URL, points.
35+
* Totally configurable settings such running time, organization details, CTF name.
3536
* Automatic strong password for administrator
3637
* Well implemented controls for administrators providing features such as issuing notifications, database CRUD operations, full fledged logging,
3738
* Simple User Registration/login process, account management, Forgot password functionalities,
3839
* Flag submission (currently 2 flags: user and root),
3940
* Real time scoreboard tracking,
40-
* Easily deployable on Heroku.
41-
42-
##### For Developers & Contributors
43-
* Flask-blueprints for modularity and clean codebase,
44-
* Flask-admin for Admin views and easy realtime management,
45-
* Flask-SQLAlchemy for SQL models,
46-
* Flask-login for session handling,
47-
* Flask-wtf for responsive forms,
48-
* Flask-mail for mail service,
49-
* Flask-bcrypt for password hashing and security,
41+
* Efficient caching so it's fast
42+
* Easily deployable on Heroku.
5043

5144
## Build locally
5245

5346
Please see [INSTALLATION.md](INSTALLATION.md).
5447

55-
## Host Your Own CTF In 5 minutes with Heroku
56-
57-
Using this is as simple as anything.
58-
59-
1. Fork the `master` branch and clone your fork,
60-
61-
```bash
62-
$ git clone https://github.com/<your_github_username>/RTB-CTF-Framework
63-
$ cd RTB-CTF-Framework/
64-
```
65-
66-
2. Configure your CTF settings (such as name, running time) in [`config.py`](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/blob/master/src/FlaskRTBCTF/config.py).
48+
## Host Your Own CTF in a minute with Heroku
6749

68-
3. In the `app.json`, change the `repository` key's value to match your fork's URL.
50+
1. Sign up on [Heroku](https://heroku.com), if you haven't already and click on the below "Deploy to Heroku" button.
6951

70-
4. Push these changes to the remote of your fork.
52+
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
7153

72-
5. Visit your Fork's GitHub URL in the browser and click on the following **Deploy to Heroku** button.
54+
2. Give your application an awesome name and _optionally_ specify mail environment variables.
7355

7456
> Note: A psuedo-random password for the **admin** user would be created and set in the config variable `ADMIN_PASS`. On Heroku, you can reveal this password from your application's dashboard settings. Same for the Flask application's `SECRET_KEY`.
7557
76-
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
58+
3. Open your newly deployed application in the browser, you'll be redirected to login as the `admin` user and do so.
59+
60+
4. Finally, you'll want to `/setup` the CTF Settings and,
7761

7862
#### Yay! Now you have a customized instance of the RTB-CTF-Framework live on Heroku. 🎉
7963

@@ -104,11 +88,6 @@ $ cd RTB-CTF-Framework/
10488

10589
For further guidelines, Please refer to [CONTRIBUTING.md](CONTRIBUTING.md)
10690

107-
## Screenshots
108-
109-
> Why look at static pictures, when you can use a demo ? Visit: <https://rtblivedemo.herokuapp.com/>.
110-
111-
<img src="screenshots/home_ss.png" width=400 />
112-
<img src="screenshots/scoreboard_ss.png" width=400 />
113-
<img src="screenshots/machine_ss.png" width=400 />
91+
## Live Demo
11492

93+
**Live Demo:** <https://rtblivedemo.herokuapp.com/> (login with `admin:admin`)

app.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"addons": [
66
{
77
"plan": "heroku-postgresql"
8+
},
9+
{
10+
"plan": "heroku-redis"
811
}
912
],
1013
"buildpacks": [
@@ -20,6 +23,17 @@
2023
"ADMIN_PASS": {
2124
"description": "Administrator password",
2225
"generator": "secret"
26+
},
27+
"ADMIN_EMAIL": {
28+
"description": "Administrator email"
29+
},
30+
"MAIL_USER": {
31+
"description": "Username for mail service",
32+
"required": false
33+
},
34+
"MAIL_PASS": {
35+
"description": "Password for mail service",
36+
"required": false
2337
}
2438
},
2539
"scripts": {

docker-compose.yml

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,53 @@
11
version: "3"
22

33
services:
4-
rtbd:
4+
rtbctf:
55
build: .
6+
container_name: rtb_gunicorn
7+
restart: unless-stopped
8+
expose:
9+
- "8000"
10+
environment:
11+
- DEBUG=False
12+
- SECRET_KEY=changeme
13+
- DB_USER=eshaan
14+
- DB_PASSWORD=eshaan
15+
- DB_NAME=rtbctf
16+
- DB_PORT=5432
17+
- WORKERS=8
18+
- ADMIN_PASS=admin
19+
depends_on:
20+
- postgres
21+
- redis
22+
23+
postgres:
24+
image: library/postgres:12.1-alpine
25+
container_name: rtb_postgres
26+
restart: unless-stopped
27+
expose:
28+
- "5432"
29+
environment:
30+
- POSTGRES_USER=eshaan
31+
- POSTGRES_PASSWORD=eshaan
32+
- POSTGRES_DB=rtbctf
33+
34+
redis:
35+
image: redis:6.0-rc4-alpine
36+
container_name: rtb_redis
37+
restart: unless-stopped
38+
expose:
39+
- "6379"
40+
41+
42+
nginx:
43+
image: library/nginx:1.16.1-alpine
44+
container_name: rtb_nginx
45+
restart: unless-stopped
46+
hostname: nginx
47+
volumes:
48+
- ./rtb_nginx_http:/etc/nginx/conf.d/default.conf
649
ports:
7-
- 80:8080
8-
restart: unless-stopped
50+
- "80:80"
51+
- "443:443"
52+
depends_on:
53+
- rtbctf

rtb_nginx_http

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# the upstream component nginx needs to connect to
2+
upstream flask {
3+
server rtbctf:8000 fail_timeout=60s;
4+
}
5+
6+
7+
server {
8+
listen 80;
9+
10+
server_name rtbctf.com;
11+
12+
location / {
13+
proxy_pass http://flask;
14+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
15+
proxy_set_header Host $host;
16+
proxy_redirect off;
17+
}
18+
19+
}

screenshots/home_ss.png

-134 KB
Binary file not shown.

screenshots/machine_ss.png

-128 KB
Binary file not shown.

screenshots/scoreboard_ss.png

-90.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)