DreamHack [web] cookie

2023. 8. 27. 14:12Wargame/dreamhack

320x100
320x100

dreamhack webhacking level1 문제입니다.

문제 화면
접속 화면

login을 누르면 username과 password를 입력하게 되어있습니다.

 

문제파일 코드입니다.

#!/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)

username이 admin일 때 flag를 출력하게끔 되어있습니다.

 

guest/guest 입력

guest/guest

 

username의 value를 admin으로 바꾸겠습니다.

admin

admin 입력하고 새로고침했더니 flag가 출력되었습니다.

문제 이름이 cookie라서 추측으로 때려맞추기....^^;;

성공~//

320x100
320x100

'Wargame > dreamhack' 카테고리의 다른 글

DreamHack [crypto] ROT128  (2) 2023.08.31
DreamHack [web] command-injection-1  (0) 2023.08.30
DreamHack [crypto] SingleByteXor  (0) 2023.08.23
DreamHack [pwnable] welcome  (0) 2023.08.19
DreamHack [reversing] rev-basic-3  (0) 2023.08.17