Web Hacking/DreamHack
[ Dreamhack ] cookie
호IT
2021. 3. 28. 04:07
- 문제 정보
쿠키로 인증 상태를 관리하는 간단한 로그인 서비스입니다.
admin 계정으로 로그인에 성공하면 플래그를 획득할 수 있습니다.
#!/usr/bin/python3
from flask import Flask, request, render_template, make_response, redirect, url_for
app = Flask(__name__)
try:
FLAG = open('./flag.txt', 'r').read()
except:
FLAG = '[**FLAG**]'
users = {
'guest': 'guest',
'admin': FLAG
}
@app.route('/')
def index():
username = request.cookies.get('username', None)
if username:
return render_template('index.html', text=f'Hello {username}, {"flag is " + FLAG if username == "admin" else "you are not admin"}')
return render_template('index.html')
@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:
pw = users[username]
except:
return '<script>alert("not found user");history.go(-1);</script>'
if pw == password:
resp = make_response(redirect(url_for('index')) )
resp.set_cookie('username', username)
return resp
return '<script>alert("wrong password");history.go(-1);</script>'
app.run(host='0.0.0.0', port=8000)
users 딕셔너리에 guest와 admin 값이 있다.
if문으로 쿠키 값이 만약 guest면 you are not admin을 출력시키고 admin으로 로그인하면 플래그를 얻을 수 있는 것 같다.
로그인 창에서 guest로 로그인을 시도하면 아래와 같이 로그인이 되고 "you are not admin"이라는 문구가 출력된다.
guest로 로그인된 상태에서 username의 쿠키 value를 admin으로 변경해주면 아래와 같이 플래그가 출력된다.