@app.route("/vuln")
def vuln():
param = request.args.get("param", "")
return param
/vuln 페이지는 url에 입력된 “param” 파라미터의 값을 필터링 없이 그대로 출력하는 취약점이 있다.
@app.route("/memo")
def memo():
global memo_text
text = request.args.get("memo", "")
memo_text += text + "\n"
return render_template("memo.html", memo=memo_text)
/memo 페이지는 url에 입력된 “memo” 파라미터의 값을 누적하여 보여준다.
/vuln 페이지와 다른 점은 render_template 함수를 사용하므로 입력된 값이 HTML Entity로 변환된다. 따라서 /vuln 페이지에만 XSS 취약점이 존재한다.
@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")
if not check_xss(param, {"name": "flag", "value": FLAG.strip()}):
return '<script>alert("wrong??");history.go(-1);</script>'
return '<script>alert("good");history.go(-1);</script>'

입력란에 페이로드를 입력하는 것 같다. 제출 버튼을 누르면 elif 문이 실행된다. 그러면 그 안에 있는 check_xss가 호출되는데 인자로 플래그가 들어간다.
def check_xss(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)
def read_url(url, cookie={"name": "name", "value": "value"}):
cookie.update({"domain": "127.0.0.1"})
try:
service = Service(executable_path="/chromedriver")
options = webdriver.ChromeOptions()
for _ in [
"headless",
"window-size=1920x1080",
"disable-gpu",
"no-sandbox",
"disable-dev-shm-usage",
]:
options.add_argument(_)
driver = webdriver.Chrome(service=service, 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()
# return str(e)
return False
driver.quit()
return True
webdriver.Chrome를 통해 새로운 크롬 클라이언트를 만드는 것 같다. driver.add_cookie(cookie)를 실행하여 이제 이 클라이언트의 쿠키에는 인자로 받은 FLAG가 추가되었다.