CIDY
[Web_Hacking] stage3_문제풀이(cookie) 본문
#!/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)
이렇게 생겼다. 역시 admin계정으로 로그인해야 플래그를 내어주는 구조이다.
/페이지는 이전과 다를 바 없고, 로그인 페이지도 이전과 똑같다.
코드를 보면 메소드가 GET이냐 POST냐에 따라 행동이 약간 달라진다. GET의 경우 로그인 템플릿을 제공하고, POST의 경우 username과 password변수를 users변수와 비교해서 로그인 할 수 있다.
users변수는 위에서 볼 수 있다.
근데 얘는 진짜 뭐지 싶은게 쿠키이름이 'username'이고 쿠키값이 username으로 만들어진다.
ㅋㅋㅋ
'Hack > DreamHack(로드맵)' 카테고리의 다른 글
[Web_Hacking] stage4_Cross-Site-Scripting(XSS) (0) | 2022.07.27 |
---|---|
[Web_Hacking] stage3_Same Origin Policy(SOP) (0) | 2022.07.27 |
[Web_Hacking] stage3_문제풀이(session-basic) (0) | 2022.07.27 |
[Web_Hacking] stage3_Cookie & Session (0) | 2022.07.27 |
[Web_Hacking] stage2_문제풀이(devtools-sources) (0) | 2022.07.27 |