#!/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 두 명으로 정의 되어 있다.
admin으로 로그인 시 flag를 리턴하고 있기 때문에 admin으로 로그인 하면 된다.
그러나 guest의 비밀번호 밖에 모르기 때문에 guest로 로그인 후 쿠키 값을 변조해야한다.
해당 사이트의 쿠키값을 보면 username에 vaule가 guest로 되어 있다. 이를 admin으로 변조하자.
'Web Hacking > Dreamhack' 카테고리의 다른 글
[Dreamhack] csrf-2 write up - 티스토리 (0) | 2024.01.12 |
---|---|
[Dreamhack] csrf-1 write up - 티스토리 (0) | 2024.01.12 |
[Dreamhack] XSS-2 write up - 티스토리 (0) | 2024.01.12 |
[Dreamhack] XSS-1 write up - 티스토리 (0) | 2024.01.12 |
[Dreamhack] session-basic write - 티스토리 (0) | 2024.01.09 |