๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
[Dreamhack]WebHacking/๋กœ๋“œ๋งต_Basic

[Dreamhack] Level1: cookie

by Yun2๐Ÿ‘ 2023. 8. 17.
๋ฐ˜์‘ํ˜•

๐Ÿ›Ž๏ธAccess

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

 

 

๐Ÿ‘พExploit Algorithm & Payload

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


: users์— guest์™€ admin์ด ์žˆ๋Š” ๊ฒƒ์„ ์ฝ”๋“œ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

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

 

 

#2


: guest ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธ ์„ฑ๊ณตํ•˜์˜€๋‹ค.

:๋ฌธ์ œ์—์„œ ์ œ์‹œํ•œ ๊ฒƒ์ฒ˜๋Ÿผ admin ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธ ๋˜์–ด์•ผ ํ”Œ๋ž˜๊ทธ๋ฅผ ํš๋“ํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ํ˜„์žฌ guest ์‚ฌ์šฉ์ž์˜ ์ฟ ํ‚ค ๊ฐ’์„ ํ™•์ธํ•˜์˜€๋‹ค.

:๊ฐ’์€ guest๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. ์ฆ‰, ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ๊ทธ๋Œ€๋กœ ์ฟ ํ‚ค์— ๋‹ด๊ฒจ ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

 

 

#3


: ์ฟ ํ‚ค๊ฐ’์„ admin์œผ๋กœ ๋ณ€์กฐํ•˜์˜€๋”๋‹ˆ ํ”Œ๋ž˜๊ทธ๋ฅผ ํš๋“ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

 

 

๐Ÿ”‘Analysis and results for obtaining the Flag DH{…}


 

 

๐Ÿ“ŒSummary


|์ฟ ํ‚ค๋Š” ํด๋ผ์ด์–ธํŠธ์— ์ €์žฅ| ์„œ๋ฒ„์˜ ๊ฒ€์ฆ ์—†์ด ์ฟ ํ‚ค๋ฅผ ์‹ ๋ขฐํ•˜๊ณ  ์ธ์ฆ ์ •๋ณด๋ฅผ ์‹๋ณ„ํ•  ๋•Œ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ์Œ

๋”ฐ๋ผ์„œ ์ฟ ํ‚ค๊ฐ’์„ ๋ณ€์กฐํ•˜์—ฌ ๊ณ„์ •์˜ ๊ถŒํ•œ์„ ์–ป์„ ์ˆ˜ ์žˆ์Œ

 

|์„ธ์…˜์€ ์„œ๋ฒ„์— ์ €์žฅ|

์œ„์™€ ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” ์„ธ์…˜์„ ์ด์šฉํ•˜์—ฌ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Œ

์ฟ ํ‚ค์™€๋Š” ๋‹ฌ๋ฆฌ ์ธ์ฆ ์ •๋ณด๋ฅผ ์„œ๋ฒ„์— ์ €์žฅํ•˜๊ณ , ๋žœ๋ค ํ‚ค๋ฅผ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ฐœ๊ธ‰

 

ํ•˜์ง€๋งŒ, ๋ฌด์กฐ๊ฑด ํ•ด๊ฒฐ์€ ์•„๋‹˜

์„œ๋ฒ„์— ์š”์ฒญ์„ ๋ณด๋‚ด๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ๋งŽ์„ ๊ฒฝ์šฐ ์„ธ์…˜์€ ๋ถ€ํ•˜๊ฐ€ ์‹ฌํ•˜๊ฒŒ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์–ด ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๊ธฐ๋„ ํ•˜๊ณ , ์›น ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์„œ๋ฒ„์— ์ ‘์†ํ•ด ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์ข…๋ฃŒํ•  ๋•Œ๊นŒ์ง€ ์„ธ์…˜์„ ์œ ์ง€ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์„ธ์…˜ํ•˜์ด์žฌํ‚น(session hijacking attack)์ด ๋ฐœ์ƒํ•  ์ˆ˜๋„ ์žˆ์Œ

 

์ฟ ํ‚ค์™€ ์„ธ์…˜์˜ ์‚ฌ์šฉ ์—ฌ๋ถ€์— ๋งž๋Š” ๋ชฉ์ , ๋ฐ์ดํ„ฐ๋Ÿ‰, ๋ณด์•ˆ ์š”๊ตฌ์‚ฌํ•ญ ๋“ฑ์„ ๋‹ค์–‘ํ•œ ์š”๊ตฌ์‚ฌํ•ญ์— ๋งž๊ฒŒ ๊ณ ๋ คํ•˜์—ฌ ๊ฒฐ์ •ํ•˜๊ณ  ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ•์„ ์ฐพ์•„์„œ ์ด๋ฅผ ํ•ด๊ฒฐํ•ด์•ผ ํ•จ

 

๋ฐ˜์‘ํ˜•

'[Dreamhack]WebHacking > ๋กœ๋“œ๋งต_Basic' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Dreamhack] Level1: csrf-2  (0) 2023.08.21
[Dreamhack] Level1: csrf-1  (0) 2023.08.21
[Dreamhack] Level1: xss-2  (0) 2023.08.19
[Dreamhack] Level1: xss-1  (0) 2023.08.19
[Dreamhack] Level1: Session-basic  (0) 2023.08.17