카테고리 없음

워게임-cookie

미숫가루빙수 2023. 3. 26. 21:52

풀기 전에 문제를 간단하게 읽어본다.

파일을 다운받고 창으로 이동한다.

 

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

(다운받은 파일 코드)

 

코드의 이 부분을 보고 아이디와 비번은

guest,guest / admin인 걸 알 수 있다.

 

우선 guest로 로그인 해본다.

 

admin이 아니라고 뜨며 DH{...}에 대한 정보를 얻을 수 없다.

 

 

하지만 이 부분을 보면

username을 통해 cookies를 얻을 수 있다.

 

guest로 로그인 한 값에 admin을 넣어준다.

 

그럼 바로 정답을 얻을 수 있다.

정답은 DH{7952074b69ee388ab45432737f9b0c56}

 

끝!!