![[Dreamhack] wargame cookie 문제풀이](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdna%2FMD7R7%2FbtrkhoNXa4c%2FAAAAAAAAAAAAAAAAAAAAAB35SGxZLK0adq1A_rEcOaG2C3sYVJ_UzJXdW6eGSa1y%2Fimg.png%3Fcredential%3DyqXZFxpELC7KVnFOS48ylbz2pIh7yKj8%26expires%3D1756652399%26allow_ip%3D%26allow_referer%3D%26signature%3D6QO7%252BaTwW6b7mcbkmXSKS3vG1G0%253D)
[Dreamhack] wargame cookie 문제풀이Security/Web hacking2021. 11. 8. 13:33
Table of Contents
728x90
이번 문제는 쿠키를 통해 인증상태를 관리하는 로그인 서비스에서, 쿠키를 이용해 관리자 계정으로 로그인에 성공하는 방법을 알아보고자 한다.
#!/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',
'admin': FLAG //관리자
}
@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')
@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>'
app.run(host='0.0.0.0', port=8000)
문제의 코드 파일은 다음과 같다. 위와 같은 코드파일을 하나하나 뜯어보도록 하자..
try:
FLAG = open('./flag.txt', 'r').read()
except:
FLAG = '[**FLAG**]'
users = {
'guest': 'guest',
'admin': FLAG //관리자
}
위와 같이 봤을때, user는 guest와 admin으로 나뉘는 것을 볼 수 있다. 우선, guest의 경우 ID, PW가 모두 guest일때 풀 수 있는것을 보아 우선 guest로 로그인을 해보고자 한다.
guest로 로그인을 하게 되면 다음과 같은 화면이 뜬다. 실제로 코드에도 다음과 같이 명시되어있다
@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')
cookie를 보면 아까 user/user로 로그인 했을 때의 쿠키가 남아있다. 이때 name의 값이 username이고 value가 guest인것을 볼 수 있는데, 코드에 username의 value값이 admin이라면 flag값이 나온다고 명시되어있으니, 본 값을 admin으로 수정해보고자 한다.
admin으로 수정하게 되면 다음과 같은 플래그가 뜨고 문제풀이가 완료된다!
728x90
'Security > Web hacking' 카테고리의 다른 글
[Dreamhack]file-download 1 문제풀이 (0) | 2021.08.15 |
---|
@잉퓨_ :: 대학로에서 개발하기
보안 전공 개발자지만 대학로에서 살고 싶어요
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!