Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- TCP
- 웹
- 소프트웨어보안
- bee-box
- reversing
- webhacking
- 리버싱
- 웹해킹
- WarGame
- System
- dreamhack
- hacking
- 워게임
- 시스템
- 네트워크보안
- ftz
- 알고리즘
- Web
- 모의해킹
- 드림핵
- XSS
- 비박스
- 네트워크
- CodeEngn
- network
- 해킹
- 순서도
- 시스템해킹
- Webhaking
- 소프트웨어
Archives
- Today
- Total
Without a Break
[Dreamhack] Cookie 본문
[문제 파일]
#!/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)
- users에는 guest, admin 총 2개의 계정이 저장되어 있다.
- 사용자가 입력한 아이디가 클라이언트의 요청에 포함된 쿠키에 존재하는지 확인 후, index.html에서 text를 보여준다.
- 사용자가 입력한 패스워드와 users에 저장된 해당 아이디의 패스워드가 같으면 username을 쿠키 변수로 생성한다.
이 문제에서는 쿠키를 조작하여 플래그를 찾아 볼 것이다.
첫 페이지에서 로그인창으로 이동한 후, 현재 우리가 비밀번호를 알고 있는 guest 계정으로 로그인을 한다.
쿠키 변수를 username으로 생성했기 때문에 username을 admin으로 변경하게 되면 admin 계정을 탈취할 수 있다.
개발자 도구에서 Application > Cookie > http://... 에서 username을 admin으로 바꿔준다.
바꿔준 후, 첫 페이지로 돌아오면 플래그가 보이게 된다.
답 : DH{7952074b69ee388ab45432737f9b0c56}
'Web > Wargame' 카테고리의 다른 글
[Dreamhack] xss-1 (0) | 2022.09.21 |
---|---|
[Dreamhack] ClientSide: XSS (0) | 2022.09.19 |
[Dreamhack] session-basic (0) | 2022.09.17 |
[Dreamhack] web-misconf-1 (0) | 2022.09.17 |
[Dreamhack] devtools-source (0) | 2022.09.17 |