๐๏ธ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',
'user': 'user1234',
'admin': FLAG
}
# this is our session storage
session_storage = {
}
@app.route('/')
def index():
session_id = request.cookies.get('sessionid', None)
try:
# get username from session_storage
username = session_storage[session_id]
except KeyError:
return render_template('index.html')
return render_template('index.html', text=f'Hello {username}, {"flag is " + FLAG if username == "admin" else "you are not admin"}')
@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:
# you cannot know admin's pw
pw = users[username]
except:
return '<script>alert("not found user");history.go(-1);</script>'
if pw == password:
resp = make_response(redirect(url_for('index')) )
session_id = os.urandom(32).hex()
session_storage[session_id] = username
resp.set_cookie('sessionid', session_id)
return resp
return '<script>alert("wrong password");history.go(-1);</script>'
@app.route('/admin')
def admin():
# developer's note: review below commented code and uncomment it (TODO)
#session_id = request.cookies.get('sessionid', None)
#username = session_storage[session_id]
#if username != 'admin':
# return render_template('index.html')
return session_storage
if __name__ == '__main__':
import os
# create admin sessionid and save it to our storage
# and also you cannot reveal admin's sesseionid by brute forcing!!! haha
session_storage[os.urandom(32).hex()] = 'admin'
print(session_storage)
app.run(host='0.0.0.0', port=8000)
#1
@app.route('/admin')
def admin():
# developer's note: review below commented code and uncomment it (TODO)
#session_id = request.cookies.get('sessionid', None)
#username = session_storage[session_id]
#if username != 'admin':
# return render_template('index.html')
return session_storage
: '/admin' ํ์ด์ง๊ฐ ์๋ค๋ ๊ฒ์ ํ์ธํ ์ ์๊ณ , admin ๊ณ์ ์ ๊ณ ์ ํ sessionid๋ฅผ ํ์ธํ ์ ์๋ค.
#2
: ์ฌ์ฉ์๋ค ์ค guest๊ณ์ ์ผ๋ก ๋ก๊ทธ์ธํ์ฌ guest์ ๊ณ ์ ํ sessionid๋ฅผ ํ์ธํ ์ ์๋ค.
#3
: #1๊ณผ #2์์ ์ป์ ๊ฒ์ ํตํด guest ๊ณ์ ์ sessionid๋ฅผ admin sessionid๋ก ๋ณ์กฐ ์๋๋ฅผ ํ๋ค.
๐Analysis and results for obtaining the Flag DH{…}
๐Summary
session_storage ์ฝ๋ ๋ถ๋ถ์์ session_id๋ฅผ ํค(key)๋ก ์ฌ์ฉํ์ฌ ์ธ์ ์ ๋ํ ์ ๋ณด๋ฅผ ์กฐํํ๊ณ ์์
์๋ฅผ๋ค์ด์ admin ๊ณ์ ์ผ๋ก ๋ก๊ทธ์ธ์ ํ๊ฒ ๋๋ฉด session_storage์ admin์ ์ธ์ ์ ๋ณด๊ฐ ์กฐํ๊ฐ ๋๋ ๊ฒ
(guest, user๊ณผ ๊ฐ์ ์ฌ์ฉ์๋ ๋ก๊ทธ์ธํ๊ฒ ๋๋ค๋ฉด session_storage์ ํจ๊ป ์กฐํ๊ฐ ๋จ)
๋ฐ๋ผ์, ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด์๋ ์ธ์ ID๋ฅผ ์์ฑํ ๋์๋ ์์ธก์ด ๋ถ๊ฐ๋ฅํ ๋๋ค ๊ฐ์ ์์ฑํ ํ ์ด๋ฅผ ๋์ ๋๋ฆฌ ๋ณ์์ ์ ์ฅํ๋ ๊ฒ์ด ์ข์ ์
์ด๋ฅผ ํตํด ๋ชจ๋ ์ฌ์ฉ์์ ๋ํ ์ธ์ ์ ๋ณด๊ฐ session_storage ๋ณ์์ ์ ์ฅ๋์ด ๋์๋๋ ์ด์๋ฅผ ํด๊ฒฐํ ์ ์์
'[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: cookie (0) | 2023.08.17 |