개발세발보안중
[드림핵]session-basic Write-up 본문
쿠키와 세션으로 인증 상태를 관리하는 간단한 로그인 서비스입니다.
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():
# 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)
주석 제거하라는 말..
admin sessionid를 만들고 저장하라..
브루트포싱으로 admin의 sessionid를 알 수 없다..하하 ... 하...............;
처음 쿠키 세션을 확인했을 땐 세션이 없다고 떴는데,
상단에 나와있는 guest guest로 로그인을 하니 세션이 생겼다

코드에 /admin이라는 경로의 페이지가 또 있다는걸 봤다

admin의 세션아이디인가보다
admin의 세션아이디를 바꿨더니 FLAG가 떴따 !

'CTF' 카테고리의 다른 글
| [Webhacking.kr]Challenge 38 Writeup (ing) (0) | 2023.04.05 |
|---|---|
| [Webhacking.kr]Challenge 6 Writeup (0) | 2023.04.05 |
| [wargame.kr] login filtering Write-up (0) | 2023.04.02 |
| [드림핵]웹해킹_simple_sqli_chatgpt Writeup (1) | 2023.04.02 |
| 드림핵 file-download-1 (0) | 2023.03.28 |
Comments