Đề bài

Phân tích
Mình được cung cấp file source code - app.py như sau
#!/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)
Mình sẽ thấy một đoạn kiểm tra Cookie như sau:
return render_template('index.html', text=f'Hello {username}, {"flag is " + FLAG if username == "admin" else "you are not admin"}')
Vậy thì chúng ta chỉ cần thay Cookie thành admin là được
Exploit

Flag
Flag: DH{7952074b69ee388ab45432737f9b0c56}
'WriteUp > Web' 카테고리의 다른 글
| [Web] GameCloud - POC CTF 2025 (0) | 2025.10.13 |
|---|---|
| [Web] devtools-sources - Dreamhack (0) | 2025.10.11 |
| [Web] Puzzle - Securinets CTF Quals 2025 (0) | 2025.10.06 |
| [Web] Lunar File Invasion (SunshineCTF 2025) (0) | 2025.10.01 |
| [Web] Web Forge (SunshineCTF 2025) (0) | 2025.10.01 |
