반응형
문제 설명
https://dreamhack.io/wargame/challenges/409/
session-basic
Description 쿠키와 세션으로 인증 상태를 관리하는 간단한 로그인 서비스입니다. admin 계정으로 로그인에 성공하면 플래그를 획득할 수 있습니다. Reference Background: Cookie & Session
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',
'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)
해당 웹 사이트에 소스코드는 다음과 같다.
플라스크로 구현되어 있고 admin으로 접속을 하면 flag가 출력이 된다.
/admin 디렉토리에 세션 스토리지가 출력이 되므로 admin세션으로 admin계정에 로그인이 가능할 것이다.
admin의 세션을 노출하고 있다.
세션을 admin의 세션으로 변경을 하면 admin계정으로 로그인을 할 수 있다.
admin 계정으로 접속을 하니 flag를 출력한다.
반응형
'WEB hacking > 드림핵(dreamhack)' 카테고리의 다른 글
드림핵 xss-2 (Level1) Write up (0) | 2023.03.29 |
---|---|
드림핵 xss-1 (Level1) Write up (0) | 2023.03.25 |
XSS(크로스 사이트 스크립팅) (0) | 2023.03.23 |
드림핵 CSRF (0) | 2023.01.14 |
드림핵 cookie (Level1) Write up (0) | 2022.12.20 |