[Web] cookie - Dreamhack

2025. 10. 11. 16:02·

Đề 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
'WriteUp/Web' Other posts in category
  • [Web] GameCloud - POC CTF 2025
  • [Web] devtools-sources - Dreamhack
  • [Web] Puzzle - Securinets CTF Quals 2025
  • [Web] Lunar File Invasion (SunshineCTF 2025)
longhd
longhd
Longhd's Blog
  • longhd
    Ha Duy Long - InfosecPTIT
    longhd
  • Total
    Today
    Yesterday
  • About me

    • Hello I'm Duy Long 👋🏻
    • View all categories (117) N
      • Certificates (4)
      • CTF (3)
      • WriteUp (94) N
        • Forensics (44) N
        • Steganography (5)
        • RE (9) N
        • OSINT (8)
        • Web (17)
        • MISC (6)
        • Crypto (3)
        • Pwn (2)
      • Love Story (0)
      • Labs (15)
        • Information Gathering (10)
        • Vulnerability Scanning (2)
        • Introduction to Web Applica.. (1)
        • Common Web Application Atta.. (1)
        • SQL Injection Attacks (1)
  • Blog Menu

    • Home
    • Tag
    • GuestBook
  • Popular Posts

  • Tags

    Dreamhack
    EnigmaXplore3.0
    writeup
    BuckeyeCTF2025
    CSCV2025
    CTF
    PTITCTF2025
    picoCTF
    CHH
    THM
    Steganography
    POCCTF2025
    Forensics
    htb
    Web
    V1tCTF2025
    OSINT
    Re
    SunshineCTF2025
    misc
  • Recent Comments

  • Recent Posts

  • hELLO· Designed ByLong.v4.10.4
longhd
[Web] cookie - Dreamhack
Go to Top

티스토리툴바