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 |
Tags
- dns
- Franklin-Reiter Related Message Attack
- dreamhack
- bandit
- weak key
- arp
- return address overflow
- rao
- Montgomery Reduction
- Hastad
- cryptography
- redirect
- spoofing
- XSS
- OverTheWire Bandit Level 1 → Level 2
- Crypto
- overthewire
- RSA Common Modulas Attack
- AES
- 암호학
- picoCTF
- 시스템해킹
- 웹해킹
- 드림핵
- Bandit Level 1 → Level 2
- RSA
- shellcode
- pycrpytodome
- Cube Root Attack
- CSRF
Archives
- Today
- Total
암호(수학) 등.. 공부한 거 잊을거 같아서 만든 블로그
[Dreamhack] cookie 본문
문제

문제 파일 : app.py
#!/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 = request.cookies.get('username', None)
username 쿠키의 값을 username 변수에 저장을 한다.
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')
username 이 'admin' 이면 flag 를 웹페이지에 출력해준다.
"flag is " + FLAG if username == "admin" else "you are not admin" if 문이 true 일 경우 "flag is " + FLAG, false 일 경우 "you are not admin" 를 출력한다.
따라서 '/' 경로에서 username 쿠키값을 admin으로 수정해주면 flag가 웹페이지 화면에 출력 될 것이다.

username : admin 쿠키를 추가하여 새로고침하면 플래그를 알 수 있다.
'Dreamhack > Web' 카테고리의 다른 글
[Dreamhack] xss-2 (0) | 2023.04.08 |
---|---|
[Dreamhack] xss-1 (0) | 2023.04.07 |
[Dreamhack] session-basic (0) | 2023.04.04 |
[Dreamhack] funjs (0) | 2023.04.03 |
[Dreamhack] Carve Party (0) | 2023.04.03 |