users = {
'guest': 'guest',
'user': 'user1234',
'admin': FLAG
}
@app.route('/')
def index():
session_id = request.cookies.get('sessionid', None)
try:
# get username from session_storage
username = session_storage[session_id]
except KeyError:
return render_template('index.html')
return render_template('index.html', text=f'Hello {username}, {"flag is " + FLAG if username == "admin" else "you are not admin"}')
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'GET':
return render_template('login.html')
elif request.method == 'POST':
username = request.form.get('username')
password = request.form.get('password')
try:
# you cannot know admin's pw
pw = users[username]
except:
return '<script>alert("not found user");history.go(-1);</script>'
if pw == password:
resp = make_response(redirect(url_for('index')) )
session_id = os.urandom(32).hex()
session_storage[session_id] = username
resp.set_cookie('sessionid', session_id)
return resp
return '<script>alert("wrong password");history.go(-1);</script>'
@app.route('/admin')
def admin():
# what is it? Does this page tell you session?
# It is weird... TODO: the developer should add a routine for checking privilege
return session_storage
⇾ /admin 페이지에 접속하면 admin의 session_id 값을 얻을 수 있습니다.
아직 admin 계정으로 로그인 하지 않아서 FLAG 대신 you are not admin이 출력됩니다.
http://host3.dreamhack.games:16061/admin
admin의 session_id 값이 출력되었습니다.
session_id 값을 변조하고 새로고침을 하면
username이 admin으로 변경되어 FLAG가 출력되었습니다.