๐Ÿ”’ Cyber Security/Web Hacking (์›นํ•ดํ‚น)

[DreamHack] ๋“œ๋ฆผํ•ต ์›นํ•ดํ‚น: Cookie

์„ ๋‹ฌ 2022. 9. 21. 02:05
๋ฐ˜์‘ํ˜•

https://dreamhack.io/wargame/challenges/6/

 

cookie

์ฟ ํ‚ค๋กœ ์ธ์ฆ ์ƒํƒœ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๊ฐ„๋‹จํ•œ ๋กœ๊ทธ์ธ ์„œ๋น„์Šค์ž…๋‹ˆ๋‹ค. admin ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธ์— ์„ฑ๊ณตํ•˜๋ฉด ํ”Œ๋ž˜๊ทธ๋ฅผ ํš๋“ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Reference Introduction of Webhacking

dreamhack.io

 

๋ฌธ์ œ์ •๋ณด

์ฟ ํ‚ค๋กœ ์ธ์ฆ ์ƒํƒœ๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ๊ฐ„๋‹จํ•œ ๋กœ๊ทธ์ธ ์„œ๋น„์Šค์ž…๋‹ˆ๋‹ค.
admin ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธ์— ์„ฑ๊ณตํ•˜๋ฉด ํ”Œ๋ž˜๊ทธ๋ฅผ ํš๋“ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

๋ฌธ์ œํŒŒ์ผ

๋”๋ณด๊ธฐ
#!/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)


 

ํ’€์ด

 

1. guest ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธํ•œ๋‹ค

(๋ฌธ์ œํŒŒ์ผ 11๋ฒˆ์งธ ์ค„์— ๋‚˜์™€์žˆ๋Š” user ์ •๋ณด ์ฐธ๊ณ )

users = {
    'guest': 'guest',
    'admin': FLAG
}

 

 

2. ๋กœ๊ทธ์ธ ์‹œ ์ฟ ํ‚ค๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค

(๊ฐœ๋ฐœ์ž ๋„๊ตฌ๋ฅผ ํ†ตํ•ด ํ™•์ธ ๊ฐ€๋Šฅ)

 

 

3. guest๋กœ ๋˜์–ด์žˆ๋Š” value ๊ฐ’์„ admin์œผ๋กœ ๋ฐ”๊พธ๋ฉด ์ •๋‹ต flag๊ฐ€ ๋‚˜ํƒ€๋‚œ๋‹ค

๋ฐ˜์‘ํ˜•