forked from REVA-Security-Engineering/REVA-CS08-SET-D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
58 lines (46 loc) · 1.44 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import pickle
import base64
from flask import Flask, request
app = Flask(__name__)
app.secret_key = 'secret'
users = {'admin': 'password123'}
@app.route('/login', methods=['POST'])
def login():
username = request.form.get('username')
password = request.form.get('password')
if username in users and users[username] == password:
token = base64.b64encode(os.urandom(5)).decode('utf-8')
return f"Logged in! Your session token is {token}"
else:
return "Invalid credentials!", 401
@app.route('/echo', methods=['POST'])
def echo():
user_input = request.form.get('input')
result = os.popen(user_input).read()
return result
@app.route('/pickle', methods=['POST'])
def load_pickle():
data = base64.b64decode(request.form.get('data'))
obj = pickle.loads(data)
return str(obj)
@app.route('/redirect')
def redirect():
url = request.args.get('url')
return flask.redirect(url)
@app.route('/eval', methods=['POST'])
def evaluate():
code = request.form.get('code')
return str(eval(code))
@app.route('/comment', methods=['GET', 'POST'])
def comment():
comment = request.args.get('comment', '')
return f"<html><body>Last comment: {comment}</body></html>"
@app.route('/readfile')
def read_file():
filename = request.args.get('filename')
with open(filename, 'r') as file:
content = file.read()
return content
if __name__ == '__main__':
app.run(debug=True)