๋ฐ์ํ
https://dreamhack.io/wargame/challenges/6/
๋ฌธ์ ์ ๋ณด
์ฟ ํค์ ์ธ์
์ผ๋ก ์ธ์ฆ ์ํ๋ฅผ ๊ด๋ฆฌํ๋ ๊ฐ๋จํ ๋ก๊ทธ์ธ ์๋น์ค์
๋๋ค.
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',
'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():
# what is it? Does this page tell you session?
# It is weird... TODO: the developer should add a routine for checking privilege
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. ์ธ์ ์ ํตํด Admin์ผ๋ก ๋ก๊ทธ์ธ ํ๊ธฐ ์ํด์๋ admin id์ ์์์ผํ๋ค
but, ์ธ์ ์ ์ฟ ํค์ ๋ค๋ฅด๊ฒ ์๋ฒ์ ์ ์ฅ๋์ด์๋ค
2. URL ์ฃผ์ /path ๋ค์ admin์ ์ ๋ ฅํ์ฌ admin id๋ฅผ ๊ตฌํ๋ค.
@app.route('/admin')
def admin():
# what is it? Does this page tell you session?
# It is weird... TODO: the developer should add a routine for checking privilege
return session_storage
3. ๊ตฌํ admin id๋ฅผ ์ธ์ id์ ์ ๋ ฅํ๋ฉด ํ๋๊ทธ ์์ฑ
๋ฐ์ํ
'๐ Cyber Security > Web Hacking (์นํดํน)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[DreamHack] ๋๋ฆผํต ์นํดํน: command-injection-1 (0) | 2023.07.05 |
---|---|
[DreamHack] ๋๋ฆผํต ์นํดํน: csrf-2 (0) | 2022.11.09 |
[DreamHack] ๋๋ฆผํต ์นํดํน: csrf-1 (0) | 2022.11.08 |
[DreamHack] ๋๋ฆผํต ์นํดํน: simple-sqli (0) | 2022.09.22 |
[DreamHack] ๋๋ฆผํต ์นํดํน: Cookie (0) | 2022.09.21 |