소스 코드 분석
/
cookie로부터 가져온 username이 admin이면 FLAG를 출력하고 아니면 admin이 아니라는 문구를 출력한다
@app.route('/')
def index():
username = request.cookies.get('username', None)
if username:
return render_template('index.html', text=f'Hello {username}, {"flag is " + FLAG if username == "admin" else "you are not admin"}')
return render_template('index.html')
/login
form으로부터 전달 받은 password와 users의 password를 비교하여 일치하면 cookie의 username 변수의 값을 전달 받은 username으로 설정한다
users = {
'guest': 'guest',
'admin': FLAG
}
@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')) )
resp.set_cookie('username', username)
return resp
return '<script>alert("wrong password");history.go(-1);</script>'
취약점 분석
/login
login 시에 cookie를 설정하므로 이를 변조할 수 있는 취약점이 존재한다
익스플로잇
cookie 변경
value를 admin으로 변경한 후 새로고침한다
FLAG 확인
반응형
'Wargame > Web' 카테고리의 다른 글
[Dreamhack] csrf-1 (0) | 2024.02.17 |
---|---|
[Dreamhack] xss-2 (2) | 2024.02.11 |
[Dreamhack] xss-1 (0) | 2024.02.11 |
[Dreamhack] session-basic (0) | 2024.02.08 |
[Dreamhack] devtools-sources (0) | 2024.02.04 |