forked from mrfreddi007/equinor-ctf-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
40 lines (36 loc) · 1.19 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
from flask import Flask, render_template, session, url_for, request, abort, redirect, make_response
import os
from string import ascii_lowercase
from random import seed, randbytes, choice
def generate_random_key():
key = randbytes(1)
key += choice(ascii_lowercase).encode("ascii")
return key
flag = open("flag.txt", "r").read()
app = Flask(__name__)
seed(flag)
app.secret_key = generate_random_key()
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
session.clear()
name = request.form['name']
if name == "admin":
abort(403)
session['name'] = name
return redirect(url_for('index'))
else:
name = session.get('name')
if name and name == "admin":
return make_response(render_template('index.html', name=name, flag=flag))
elif name:
return make_response(render_template('index.html', name=name, flag="*"*12))
else:
return make_response(render_template('register.html'))
@app.route('/unregister', methods=['GET'])
def unregister():
session.clear()
return redirect(url_for('index'))
if __name__ == '__main__':
app.run(debug=True)