Skip to content

Commit 85a4b6a

Browse files
authored
merge into master (#54)
* update to conform with flake8/PEP8 | #47 * Update README.md * Create CODE_OF_CONDUCT.md (#51) * 1. psf/black formatting with travis checks, 2. adjust docs, create CONTRIBUTING.md, 3. helper fns for creating admin pass and secret key by itself on run create admin pass and secret key by itself on run * Update README.md * Update CONTRIBUTING.md * create admin pass and secret key by itself on run * better docs * fix pwd truncation
1 parent f07e323 commit 85a4b6a

File tree

8 files changed

+110
-80
lines changed

8 files changed

+110
-80
lines changed

CONTRIBUTING.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,21 @@
3434

3535
## Style Guide
3636

37-
Keeping to a consistent code style throughout the project makes it easier to contribute and collaborate. Please stick to the guidelines in PEP8, [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) and the Google Style Guide unless there’s a very good reason not to.
37+
Keeping to a consistent code style throughout the project makes it easier to contribute and collaborate. Please stick to the guidelines in [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) and the Google Style Guide unless there’s a very good reason not to.
38+
39+
### Before submitting a Pull Request, please run these 2 commands locally
40+
41+
```bash
42+
$ black .
43+
```
44+
45+
```bash
46+
$ flake8 src/ flake8 . ---max-line-length=88 --show-source --statistics
47+
```
48+
49+
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.
50+
51+
> Guide on squashing commits: [here](https://github.com/wprig/wprig/wiki/How-to-squash-commits)
3852
3953
## Contact
4054

@@ -80,4 +94,4 @@ See: [Issues](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/issues) and th
8094
- [x] Use Flask Blueprints
8195
- [x] Finalize black theme?
8296
- [x] Error messages not appearing in `/submit`
83-
- [x] Implement `machine.html` to server a page where one can download/serve machines
97+
- [x] Implement `machine.html` to server a page where one can download/serve machines

INSTALLATION.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Installation / How To Use
2+
3+
### Requirements
4+
5+
* Tested on `Python 3.8.2`
6+
* Python Packages: [`src/requirements.txt`](src/requirements.txt).
7+
* OS Packages: PostgreSQL version 11 or greater, `libpq-dev`, `python3-dev` packages. Please refer [here](https://tutorials.technology/solved_errors/9-Error-pg_config-executable-not-found.html).
8+
9+
### Build locally and run
10+
11+
1. Git clone the repo and `cd ` into it
12+
13+
```bash
14+
$ git clone https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework
15+
$ cd RTB-CTF-Framework/
16+
```
17+
2. Create `virtual environment` to deal with dependencies and requirements.
18+
19+
```bash
20+
$ virtualenv -p /usr/bin/python3 venv
21+
$ source venv/bin/activate
22+
$ cd src/
23+
```
24+
25+
3. With `virtual environment` activated, install requirements, init db and run !
26+
27+
```bash
28+
[venv]$ pip install -r requirements.txt
29+
[venv]$ python create_db.py # Only required on first run
30+
[venv]$ python run.py
31+
```
32+
33+
> Warning: If you make any change to [`config.py`](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/blob/master/src/FlaskRTBCTF/config.py) logging/config class/score settings. It's highly recommended to create a new DB instance.
34+
35+
### Docker
36+
37+
> Note: The Docker support is not tested for production yet. It's recommended to use Heroku for production.
38+
39+
```bash
40+
$ docker-compose up
41+
```

README.md

Lines changed: 23 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# RootTheBox CTF Framework
22

3-
<p >
3+
<p>
44
<a href="https://inventory.rawsec.ml/" target="_blank">
55
<img height="26px" alt="Rawsec's CyberSecurity Inventory" src="https://inventory.rawsec.ml/img/badges/Rawsec-inventoried-FF5050_for-the-badge.svg">
66
</a>
@@ -26,7 +26,7 @@ The main purpose of this project is to serve as a scoring engine and CTF manager
2626

2727
A live demo of the app is available at: <https://rtblivedemo.herokuapp.com/>.
2828

29-
You can login and mess around as 2 users: `admin:admin` and `test:test` (i.e. username:password combinations)
29+
You can login and mess around as the admin user `admin:admin` (i.e. username:password combinations) or register your own.
3030

3131
## Features
3232

@@ -43,84 +43,41 @@ The main purpose of this project is to serve as a scoring engine and CTF manager
4343
* Flask-blueprints for modularity and clean codebase,
4444
* Flask-admin for Admin views and easy realtime management,
4545
* Flask-SQLAlchemy for SQL models,
46-
* Flask-wtf for forms,
47-
* Flask-mail for mail service.
48-
49-
## Deployment
50-
51-
### Heroku
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,
5250

53-
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
51+
## Build locally
5452

55-
or do it manually,
53+
Please see [INSTALLATION.md](INSTALLATION.md).
5654

57-
1. Create your heroku app using `heroku` cli tool.
58-
59-
Follow the official guide by Heroku: https://devcenter.heroku.com/articles/getting-started-with-python#prepare-the-app
55+
## Host Your Own CTF In 5 minutes with Heroku
6056

61-
2. Provision Database add-on.
62-
63-
Add the following add on to your new app: https://elements.heroku.com/addons/heroku-postgresql
64-
65-
3. Creating database instance. In your heroku app directory,
57+
Using this is as simple as anything.
6658

67-
```bash
68-
$ heroku run bash
69-
[heroku]$ python create_db.py
70-
```
71-
4. Your app should be live now. You can run `heroku open` to open it in browser.
72-
73-
### Docker
59+
1. Fork the `master` branch and clone your fork,
7460

7561
```bash
76-
$ docker-compose up
77-
```
78-
79-
## How To Use
80-
81-
### Requirements
82-
83-
* Tested on `Python 3.8.2`
84-
* Python Packages: [`src/requirements.txt`](src/requirements.txt).
85-
* OS Packages: PostgreSQL version 11 or greater, `libpq-dev`, `python3-dev` packages. Please refer [here](https://tutorials.technology/solved_errors/9-Error-pg_config-executable-not-found.html).
86-
87-
### Installation and first run
88-
89-
1. Git clone the repo and `cd ` into it
90-
91-
```bash
92-
$ git clone https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework
62+
$ git clone https://github.com/<your_github_username>/RTB-CTF-Framework
9363
$ cd RTB-CTF-Framework/
9464
```
95-
2. Create `virtual environment` to deal with dependencies and requirements.
96-
97-
```bash
98-
$ virtualenv -p /usr/bin/python3 venv
99-
$ source venv/bin/activate
100-
$ cd src/
101-
```
102-
103-
3. With `virtual environment` activated, install requirements, init db and run !
104-
105-
```bash
106-
[venv]$ pip install -r requirements.txt
107-
[venv]$ python create_db.py # Only required on first run
108-
[venv]$ python run.py
109-
```
11065

111-
### Configuration For Your CTF
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).
11267

113-
Using this as simple as anything.
68+
3. In the `app.json`, change the `repository` key's value to match your fork's URL.
11469

115-
1. Just configure your CTF settings in [`config.py`](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/blob/master/src/FlaskRTBCTF/config.py).
70+
4. Push these changes to the remote of your fork.
11671

117-
2. When you run [`create_db.py`](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/blob/master/src/create_db.py), a strong and random 16 char password for the **admin** user is created and set in the environment variable `ADMIN_PASS`. On Heroku, you can reveal this password from your application's dashboard settings.
72+
5. Visit your Fork's GitHub URL in the browser and click on the following **Deploy to Heroku** button.
73+
74+
> 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`.
11875
119-
3. See database instance creation steps under How To Use.
76+
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)
12077

121-
Bonus: You can manage the database CRUD operations from admin views GUI as well as issue notifications.
78+
#### Yay! Now you have a customized instance of the RTB-CTF-Framework live on Heroku. 🎉
12279

123-
> Warning: If you make any change to [`config.py`](https://github.com/abs0lut3pwn4g3/RTB-CTF-Framework/blob/master/src/FlaskRTBCTF/config.py) logging/config class/score settings. It's highly recommended to create a new DB instance.
80+
> Bonus: You can manage the database CRUD operations from admin views GUI; change machine settings, issue notifications to users, etc.
12481
12582
## Contributing
12683

@@ -133,7 +90,6 @@ Bonus: You can manage the database CRUD operations from admin views GUI as well
13390
</a>
13491
</p>
13592

136-
13793
##### 👨 Project Owner
13894

13995
- Eshaan Bansal ([github](https://github.com/eshaan7), [linkedin](https://www.linkedin.com/in/eshaan7/))
@@ -150,6 +106,8 @@ For further guidelines, Please refer to [CONTRIBUTING.md](CONTRIBUTING.md)
150106

151107
## Screenshots
152108

109+
> Why look at static pictures, when you can use a demo ? Visit: <https://rtblivedemo.herokuapp.com/>.
110+
153111
<img src="screenshots/home_ss.png" width=400 />
154112
<img src="screenshots/scoreboard_ss.png" width=400 />
155113
<img src="screenshots/machine_ss.png" width=400 />

app.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
"url": "heroku/python"
1313
}
1414
],
15+
"env": {
16+
"SECRET_KEY": {
17+
"description": "Flask app instance's SECRET_KEY",
18+
"generator": "secret"
19+
},
20+
"ADMIN_PASS": {
21+
"description": "Administrator password",
22+
"generator": "secret"
23+
}
24+
},
1525
"scripts": {
1626
"postdeploy": "python3 src/create_db.py"
1727
}

runtime.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-3.8.2

src/FlaskRTBCTF/helpers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
import secrets
55

66

7-
def handle_secret_key():
8-
sk = os.environ.get("SECRET_KEY", None)
7+
def handle_secret_key(default="you-will-never-guess"):
8+
sk = os.environ.get("SECRET_KEY", default)
99
if not sk:
1010
sk = secrets.token_hex(16)
1111
os.environ["SECRET_KEY"] = sk
1212
return sk
1313

1414

15-
def handle_admin_pass():
16-
passwd = os.environ.get("ADMIN_PASS", None)
15+
def handle_admin_pass(default="admin"):
16+
passwd = os.environ.get("ADMIN_PASS", default)
1717
if not passwd:
1818
passwd = secrets.token_hex(16)
1919
os.environ["ADMIN_PASS"] = passwd

src/FlaskRTBCTF/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class Machine(db.Model):
3737

3838
class User(db.Model, UserMixin):
3939
id = db.Column(db.Integer, primary_key=True)
40-
username = db.Column(db.String(40), unique=True, nullable=False)
41-
email = db.Column(db.String(120), unique=True, nullable=False)
42-
password = db.Column(db.String(60), nullable=False)
40+
username = db.Column(db.String(24), unique=True, nullable=False)
41+
email = db.Column(db.String(88), unique=True, nullable=False)
42+
password = db.Column(db.String(64), nullable=False)
4343
isAdmin = db.Column(db.Boolean, default=False)
4444
score = db.relationship("Score", backref="user", lazy=True, uselist=False)
4545
if LOGGING:

src/FlaskRTBCTF/users/forms.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88

99
class RegistrationForm(FlaskForm):
1010
username = StringField(
11-
"Username", validators=[DataRequired(), Length(min=4, max=20)]
11+
"Username", validators=[DataRequired(), Length(min=4, max=24)]
12+
)
13+
email = StringField(
14+
"Email", validators=[DataRequired(), Email(), Length(min=6, max=88)]
15+
)
16+
password = PasswordField(
17+
"Password", validators=[DataRequired(), Length(min=4, max=32)]
1218
)
13-
email = StringField("Email", validators=[DataRequired(), Email()])
14-
password = PasswordField("Password", validators=[DataRequired()])
1519
confirm_password = PasswordField(
1620
"Confirm Password", validators=[DataRequired(), EqualTo("password")]
1721
)
@@ -32,7 +36,7 @@ def validate_email(self, email):
3236

3337
class LoginForm(FlaskForm):
3438
username = StringField(
35-
"Username", validators=[DataRequired(), Length(min=4, max=20)]
39+
"Username", validators=[DataRequired(), Length(min=4, max=24)]
3640
)
3741
password = PasswordField("Password", validators=[DataRequired()])
3842
remember = BooleanField("Remember Me")
@@ -41,7 +45,7 @@ class LoginForm(FlaskForm):
4145

4246
class UpdateAccountForm(FlaskForm):
4347
username = StringField(
44-
"Username", validators=[DataRequired(), Length(min=4, max=20)]
48+
"Username", validators=[DataRequired(), Length(min=4, max=24)]
4549
)
4650
email = StringField("Email", validators=[DataRequired(), Email()])
4751
submit = SubmitField("Update")
@@ -76,7 +80,9 @@ def validate_email(self, email):
7680

7781

7882
class ResetPasswordForm(FlaskForm):
79-
password = PasswordField("Password", validators=[DataRequired()])
83+
password = PasswordField(
84+
"Password", validators=[DataRequired(), Length(min=4, max=48)]
85+
)
8086
confirm_password = PasswordField(
8187
"Confirm Password", validators=[DataRequired(), EqualTo("password")]
8288
)

0 commit comments

Comments
 (0)