CIDY
[Web_Hacking] 문제풀이(session) 본문
#!/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
}
session_storage = {
}
@app.route('/')
def index():
session_id = request.cookies.get('sessionid', None)
try:
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:
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(4).hex()
session_storage[session_id] = username
resp.set_cookie('sessionid', session_id)
return resp
return '<script>alert("wrong password");history.go(-1);</script>'
if __name__ == '__main__':
import os
session_storage[os.urandom(1).hex()] = 'admin'
print(session_storage)
app.run(host='0.0.0.0', port=8000)
admin의 쿠키값이…hex1바이트 랜덤값이다. → 브루트포스해도 금방 될 것 같다.
send to Intruder해주고..
브루트포스로 맞추고 값 설정 해준 다음 start attack하면
길이가 혼자만 다르길래 응답을 봤더니 플래그가 보인다.
'Hack > DreamHack' 카테고리의 다른 글
[System_Hacking] 문제풀이(shell_basic) (0) | 2022.08.08 |
---|---|
[Reverse_Engineering] 문제풀이(Secure Mail) (0) | 2022.08.01 |
[System_Hacking] 문제풀이(environ) (0) | 2022.07.17 |
[Reverse_Engineering] 문제풀이(rev-basic-3) (0) | 2022.07.17 |
[Reverse_Engineering] 문제풀이(patch) (0) | 2022.07.17 |