๋ฐ์ํ
https://dreamhack.io/wargame/challenges/6/
๋ฌธ์ ์ ๋ณด
์ฟ ํค๋ก ์ธ์ฆ ์ํ๋ฅผ ๊ด๋ฆฌํ๋ ๊ฐ๋จํ ๋ก๊ทธ์ธ ์๋น์ค์
๋๋ค.
admin ๊ณ์ ์ผ๋ก ๋ก๊ทธ์ธ์ ์ฑ๊ณตํ๋ฉด ํ๋๊ทธ๋ฅผ ํ๋ํ ์ ์์ต๋๋ค.
๋ฌธ์ ํ์ผ
๋๋ณด๊ธฐ
#!/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)
ํ์ด
1. guest ๊ณ์ ์ผ๋ก ๋ก๊ทธ์ธํ๋ค
(๋ฌธ์ ํ์ผ 11๋ฒ์งธ ์ค์ ๋์์๋ user ์ ๋ณด ์ฐธ๊ณ )
users = {
'guest': 'guest',
'admin': FLAG
}
2. ๋ก๊ทธ์ธ ์ ์ฟ ํค๊ฐ ์์ฑ๋๋ค
(๊ฐ๋ฐ์ ๋๊ตฌ๋ฅผ ํตํด ํ์ธ ๊ฐ๋ฅ)
3. guest๋ก ๋์ด์๋ value ๊ฐ์ admin์ผ๋ก ๋ฐ๊พธ๋ฉด ์ ๋ต flag๊ฐ ๋ํ๋๋ค
๋ฐ์ํ
'๐ Cyber Security > Web Hacking (์นํดํน)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[DreamHack] ๋๋ฆผํต ์นํดํน: command-injection-1 (0) | 2023.07.05 |
---|---|
[DreamHack] ๋๋ฆผํต ์นํดํน: csrf-2 (0) | 2022.11.09 |
[DreamHack] ๋๋ฆผํต ์นํดํน: csrf-1 (0) | 2022.11.08 |
[DreamHack] ๋๋ฆผํต ์นํดํน: simple-sqli (0) | 2022.09.22 |
[DreamHack] ๋๋ฆผํต ์นํดํน: Session-basic (0) | 2022.09.21 |