문제 파일을 다운받고 접속 정보에 링크 클릭.
첫번째 vuln(csrf) page 클릭하면 나오는 화면.
두번째 flag 클릭하면 나오는 화면.
세번째 login 클릭하면 나오는 화면.
파일 코드.
#!/usr/bin/python3
from flask import Flask, request, render_template, make_response, redirect, url_for
from selenium import webdriver
import urllib
import os
app = Flask(__name__)
app.secret_key = os.urandom(32)
try:
FLAG = open("./flag.txt", "r").read()
except:
FLAG = "[**FLAG**]"
users = {
'guest': 'guest',
'admin': FLAG
}
session_storage = {}
def read_url(url, cookie={"name": "name", "value": "value"}):
cookie.update({"domain": "127.0.0.1"})
try:
options = webdriver.ChromeOptions()
for _ in [
"headless",
"window-size=1920x1080",
"disable-gpu",
"no-sandbox",
"disable-dev-shm-usage",
]:
options.add_argument(_)
driver = webdriver.Chrome("/chromedriver", options=options)
driver.implicitly_wait(3)
driver.set_page_load_timeout(3)
driver.get("http://127.0.0.1:8000/")
driver.add_cookie(cookie)
driver.get(url)
except Exception as e:
driver.quit()
print(str(e))
# return str(e)
return False
driver.quit()
return True
def check_csrf(param, cookie={"name": "name", "value": "value"}):
url = f"http://127.0.0.1:8000/vuln?param={urllib.parse.quote(param)}"
return read_url(url, cookie)
@app.route("/")
def index():
session_id = request.cookies.get('sessionid', None)
try:
username = session_storage[session_id]
except KeyError:
return render_template('index.html', text='please login')
return render_template('index.html', text=f'Hello {username}, {"flag is " + FLAG if username == "admin" else "you are not an admin"}')
@app.route("/vuln")
def vuln():
param = request.args.get("param", "").lower()
xss_filter = ["frame", "script", "on"]
for _ in xss_filter:
param = param.replace(_, "*")
return param
@app.route("/flag", methods=["GET", "POST"])
def flag():
if request.method == "GET":
return render_template("flag.html")
elif request.method == "POST":
param = request.form.get("param", "")
session_id = os.urandom(16).hex()
session_storage[session_id] = 'admin'
if not check_csrf(param, {"name":"sessionid", "value": session_id}):
return '<script>alert("wrong??");history.go(-1);</script>'
return '<script>alert("good");history.go(-1);</script>'
@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')) )
session_id = os.urandom(8).hex()
session_storage[session_id] = username
resp.set_cookie('sessionid', session_id)
return resp
return '<script>alert("wrong password");history.go(-1);</script>'
@app.route("/change_password")
def change_password():
pw = request.args.get("pw", "")
session_id = request.cookies.get('sessionid', None)
try:
username = session_storage[session_id]
except KeyError:
return render_template('index.html', text='please login')
users[username] = pw
return 'Done'
app.run(host="0.0.0.0", port=8000)
코드를 잘 보다보면,
맨 마지막에 /change_password 부분이 있습니다.
pw의 내가 원하는 비밀번호를 넣어 바꿔주면 로그인이 될 것 같습니다.
<img src="/change_password?pw=admin">
flag에 넣어주면 됩니다.
username은 admin 고정이고,
password는 위에서 flag에 뭐든 다른 단어를 넣고 로그인할 때 입력하기만 하면 된다.
<img src="/change_password?pw=swing">
flag에 이렇게 집어넣으면
swing도 된다.
답 : DH{c57d0dc12bb9ff023faf9a0e2b49e470a77271ef}
'Wargame > Dreamhack' 카테고리의 다른 글
[Dreamhack] sql injection bypass WAF (0) | 2022.11.12 |
---|---|
[Dreamhack] blind sql injection advanced (0) | 2022.11.12 |
[Dreamhack] XSS-2 (0) | 2022.09.20 |
[Dreamhack] rev-basic-1 (0) | 2022.07.31 |
[Dreamhack] rev-basic-0 (0) | 2022.07.31 |