개발세발보안중
Wargame Challenges 6 본문

문제 파일
#!/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)
#취약점 분석
- 이용자의 계정을 나타내는 username 변수가 요청에 포함되니 쿠키에 의해 결정되어 문제가 발생
- 쿠키는 클라이언트의 요청에 포함되는 정보로, 이용자가 임의로 조작할 수 있음
- 서버는 별다른 검증 없이 이용자 요청에 포함된 쿠키를 신뢰하고, 이용자 인증 정보를 식별하기 때문에 공격자는 쿠키에 타 계정 정보를 삽입해 계정을 탈취할 수 있음
여기에서
users = {
'guest': 'guest',
'admin': FLAG
}
admin : FLAG
접속정보에 나와있는 링크를 타고 들어가니

이런 페이지가 나온다. F12 를 눌러 개발자 도구를 킨다

애플리케이션-쿠키
>쿠키에 존재하는 username을 admin 문자열로 조작해야함
>username을 admin으로 변경해 서버로 요청하면 FLAG 획득!
'CTF' 카테고리의 다른 글
| Webhacking.kr 15 (0) | 2022.10.03 |
|---|---|
| Webhacking.kr 34번 (0) | 2022.09.26 |
| Codeengn Basic RCE L09 (0) | 2022.09.26 |
| Codeengn Basic RCE L10 (0) | 2022.09.26 |
| webhacking.kr challenge 42 (0) | 2022.09.25 |
Comments