-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
executable file
·63 lines (46 loc) · 1.64 KB
/
server.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
from flask import Flask,request,abort
import gnupg, secrets, json
app = Flask(__name__)
gpg = gnupg.GPG(gnupghome="/tmp/gpg")
def encrypt_data(password, data):
return str(gpg.encrypt(
data,
recipients = None,
symmetric = True,
passphrase = password
))
# random root password! very secure!
rootPassword = secrets.token_hex(32);
# encrypted database, also very secure! you need to know the password
# to decrypt and use the user information
encryptedDatabase = {
"root" : encrypt_data(rootPassword, '{ "uid" : 0 }'),
"harmless_user" : encrypt_data("password123", '{ "uid" : 1000 }')
}
# demonstrates descrypt vulnerability
@app.route("/login", methods=['POST'])
def login():
(username, password) = (request.form['username'], request.form['password'])
if not username in encryptedDatabase:
return "You are not in the database, sorry."
decrypted = gpg.decrypt(
encryptedDatabase[username],
passphrase = password
);
if not decrypted:
return "Oh sorry, wrong decryption password!"
decryptedData = json.loads(str(decrypted))
if decryptedData["uid"] == 0:
return "**** Hello root! In case you forgot your password, it's: %s ****" % rootPassword
else:
return "Hi normal user!"
# demonstrates encrypt vulnerability
@app.route("/encryption_as_a_service", methods=['POST'])
def encryption_as_a_service():
plaintext = "This cannot be changed!"
(password) = (request.form['password'])
encrypted = encrypt_data(password, plaintext);
return str(encrypted)
if __name__ == "__main__":
app.run(host='0.0.0.0')