35번째 문제 가자~~
소스코드를 보자
#!/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)
users = {
'guest': 'guest',
'user': 'user1234',
'admin': FLAG
}
user : user1234
admin : flag
어드민 비번이 flag다
일단 user : user1234로 로그인해봤다
답은 소스코드에 있다.
@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 페이지다
들어가보자
세션들이 기록되어있는 사이트가 나왔다.
이전 로그인 세션 정보가 표시되어있다
이제 새싹문제가아닌 처음으로 1단계 문제를 풀어봤는데 확실히...단계가 더 추가가된다..
큰일났다 이거 잘 풀 수 있을려나;;
공부 더 열심히 해야겠다
'Dreamhack > Dreamhack Wargame (Challenge)' 카테고리의 다른 글
[37] IT 비전공자 [dreamhack]simple_sqli문제 풀기 (4) | 2024.10.16 |
---|---|
[36] IT 비전공자 [dreamhack]xss-1문제 풀기 (2) | 2024.10.15 |
[34] IT 비전공자 [dreamhack]Broken Password문제 풀기 (0) | 2024.10.13 |
[33] IT 비전공자 [dreamhack]Path Finder문제 풀기 (3) | 2024.10.12 |
[32] IT 비전공자 [dreamhack] whatsdifferent문제 풀기 (4) | 2024.10.11 |