๐ Introduction
DOM Clobbering์ Javascript์์์ DOM ์ฒ๋ฆฌ ๋ฐฉ์์ ์ด์ฉํ ๊ณต๊ฒฉ ๊ธฐ๋ฒ์ ๋๋ค. Clobbering์ ์๋ฏธ ๊ทธ๋๋ก ์ํํธ์จ์ด ๊ณตํ์์ ์๋์ ,๋น์๋์ ์ผ๋ก ํน์ ๋ฉ๋ชจ๋ฆฌ๋ ๋ ์ง์คํฐ๋ฅผ ์์ ํ ๋ฎ์ด์ฐ๋ ํ์์ ์๋ฏธํฉ๋๋ค.
๋ค์ ๋งํ๋ฉด DOM์ ๋ฎ์ด์ด๋ค๋ ์๋ฏธ๊ฐ ๋ฉ๋๋ค. HTML ํ๊ทธ ์ค id ์์ฑ์ผ๋ก ๋ช ์๋ Object๋ window object์์๋ ํธ์ถ์ด ๊ฐ๋ฅํฉ๋๋ค. ์ด๋ฅผ ์ด์ฉํ ๊ณต๊ฒฉ์ด DOM Clobbering์ ๋๋ค.
|
|
ํ๊ฐ์ง ์์๋ฅผ ๋ค์ด๋ณด์ฃ . ์๋์ ๊ฐ์ด location.href์ window.mylocation์ ๊ฐ์ ๋ฃ๋ ์ฝ๋๊ฐ ์๋ค๊ณ ์นฉ์๋ค. ์ผ๋ฐ์ ์ผ๋ก mylocation ๊ฐ์ ์ง์ ์ ์ดํ์ง ๋ชปํ๋ค๋ฉด location.href๋ฅผ ์ปจํธ๋กคํ ์ ์์ต๋๋ค.
|
|
๋ค๋ง HTML ์ฝ๋๋ฅผ ์ฝ์ ํ ์ ์๋ ํ๊ฒฝ์ด๋ผ๋ฉด (์คํฌ๋ฆฝํธ ๊ณํต์ ์ฐจ๋จ์ด๋ผ๊ณ ํ๋๋ผ๋) ์๋์ ๊ฐ์ด window.mylocation ๊ฐ์ HTML ํ๊ทธ์ ์์ฑ์ ์ด์ฉํ์ฌ ๋ง๋ค ์ ์์ต๋๋ค.
|
|
name ์์ฑ์ผ๋ก๋ ๊ฐ๋ฅํฉ๋๋ค ๐
๐ก Offensive techniques
Detect
DOM Clobbering์ ๋จ๋ ์ ์ผ๋ก ์ฌ์ฉ๋๋ค๊ธฐ ๋ณด๋จ XSS๋ Open Redirect ๋ฑ ๋ค๋ฅธ ์ทจ์ฝ์ ๊ณผ ์ฐ๊ณ๋ ์ ์๋ ๊ณต๊ฒฉ ๋ฐฉ๋ฒ์ ๋๋ค. DOM ๊ฐ์ฒด๋ฅผ ๊ณต๊ฒฉ์๊ฐ ์์๋ก ๋ณ๊ฒฝํ ์ ์๊ธฐ ๋๋ฌธ์ ์ด๋ฅผ ํตํด innerHTML, eval() ๊ตฌ๊ฐ ๋ฑ ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ ์ ์๋ ๊ตฌ๊ฐ์ด๋ Prototype Pollution์ ํตํด ๋น์ ์์ ์ธ ์๋น์ค ๊ฐ์ฒด๊ฐ ์์ฑ๋๋๋ก ์ ๋ํ ์ ์์ต๋๋ค.
ํ๋ก์ฐ๋ฅผ ๋๋ ๋ณด๋ฉด ์๋์ ๊ฐ์ต๋๋ค.
- ์ฌ์ฉ์๊ฐ HTML์ ์ปจํธ๋กคํ ์ ์๋์ง ํ์ธํ๋ค. (๋ณดํต ์คํฌ๋ฆฝํธ๋ ์ฐจ๋จํ๋ HTML ํ์ฉ ์๋น์ค๊ฐ ํ ์คํธํ๊ธฐ ํธํ๊ฒ ์ฃ )
- ์๋น์ค ๋ด DOM ๊ด๋ จ ์ทจ์ฝ(
innerHTML
,eval()
,document.write
,location.href
๋ฑ) ๊ตฌ๊ฐ์ ํ์ธํ๋ค. - ํด๋น ๊ตฌ๊ฐ์ ์ปจํธ๋กคํ ์ ์๋ ๋ฐ์ดํฐ์
window.blah
์ ๊ฐ์ด DOM Clobbering์ด ๊ฐ๋ฅํ ์ง์ ์ ์ฐพ๋๋ค. - DOM Clobbering !!!
Regex
์๋ 2๊ฐ ํจํด ์ ๋๋ฉด ๋์ถฉ ์ฐ์ผ๋งํ ๋ถ๋ถ์ ํ์งํ ์ ์์ต๋๋ค.
|
|
ZAP Scripting
DOM Clobbering์ ์ฝ๊ฒ ์๋ณํ๊ฒ ์ํด์ ZAP์์ Passive ์คํฌ๋ฆฝํธ๋ฅผ ํ๋ ๋ง๋ค์ด๋์ต๋๋ค. ํด๋น ํจ์๋ธ ์คํฌ๋ฆฝํธ๋ฅผ ์ ์ฉํ์๋ฉด ์๋์ ๊ฐ์ด Response์ DOM Clobbering์ด ๊ฐ๋ฅํ ํจํด์ด ์๋ ๊ฒฝ์ฐ Alerts์์ Medium ์ด์๋ก ํ๊ธฐํด์ค๋๋ค ๐
Exploitation
XSS
|
|
Open Redirect
|
|
Etc
์ด์ธ์๋ DOM ์์ญ์์ ๋ฐ์ํ ์ ์๋ ๋ชจ๋ ๊ฒ๋ค์ ์ํฅ์ ์ค ์ ์์ต๋๋ค.
- DOM Clobbering through DOMPurify sanitizer
document.write(safe_dom.innerHTML)
. - Escaping the src= context in the
<img>
via " character. - Clobbering document variables through name=variable in the
<img>
. - Dangling markup in
<img>
allows invalidating/* config.js */
script. - Scripts were split into smaller pieces on purpose - itโs easier to invalidate unwanted parts of the code, like in the example above.
- Itโs not widely known but setTimeout works like eval, therefore
setTimeout(โalert(1)โ)
pops out an alert. - In the
/* trusted.js */
script itโs possible to make window.show_session undefined via name=cookie in the<img>
while preserving the function is_trusted() defined. - The function contains() is unsafely coded allowing many bypasses, e.g. ‘undefined in window’ returns true.
- Nested objects can be clobbered using stacked iframes.
- document.cookie can be overridden from sandbox.terjanq.me.
- When a page is loaded in an iframe, sandbox and allow can invalidate some parts of the code.
String to Code Table
Bypass protection
Two-Depth Clobbering
๋๋๋ก window.blah.blah ์ ๊ฐ์ด depth๊ฐ 2๋ฒ ์ด์ ๋ค์ด๊ฐ๋ ๊ฒฝ์ฐ๋ ์กด์ฌํฉ๋๋ค. ์ด๋ฌํ ๊ฒฝ์ฐ name ์์ฑ์ ์ด์ฉํ๋ฉด clobbering์ด ๊ฐ๋ฅํฉ๋๋ค. DOM์ ๋์ผํ ์ด๋ฆ์ id๊ฐ ๋ณต์๋ก ์กด์ฌํ๋ ๊ฒฝ์ฐ name ๊ฐ์ ํ์ ๊ฐ์ฒด์ ๋น์ทํ ํํ๋ก ์ธ์งํฉ๋๋ค.
|
|
|
|
Three-Depth Clobbering
form
ํ๊ทธ์ ๊ฐ์ด ํ์ Object๋ฅผ ๊ฐ์ง ์ ์๋ ํ๊ทธ๋ฅผ ์ด์ฉํ๋ฉด window.x.y.z
๊ณผ ๊ฐ์ด 3depth์ object๋ clobbering์ด ๊ฐ๋ฅํฉ๋๋ค.
|
|
|
|
More-Depth Clobbering
iframe๊ณผ srcdoc์ ์ด์ฉํ๋ฉด 4-Depth ์ด์์ Clobbering์ด ๊ฐ๋ฅํฉ๋๋ค.
|
|
Clobbering with ID/PW
|
|
๐ก Defensive techniques
DOM Clobbering์ Javascript์ DOM ์ฒ๋ฆฌ ๋ฐฉ์์ ์ด์ฉํ ๋ฐฉ๋ฒ์ด๋ผ ๋จ๋ ์ ์ผ๋ก ๋ง๊ธฐ๋ ์ด๋ ต์ต๋๋ค. ์ผ๋ฐ ์ฌ์ฉ์๊ฐ HTML ์ฝ๋๋ฅผ ์๋น์ค์์ ์ฌ์ฉํ ์ ์๋๋ก ์ ํํ๋ ๊ฒ์ด ๊ฐ์ฅ ์ข์ ๋ฐฉ๋ฒ์ด๋ฉฐ, ์๋น์ค ํน์ฑ ์ ํ์ฉํด์ผ ํ๋ค๋ฉด id, name ๋ฑ DOM Clobbering์ ์ฌ์ฉํ ์ ์๋ ์์ฑ์ ์ ๊ฑฐํฉ๋๋ค. ์ด๋ CSS Injection์ ๋์๋ฐฉ์๊ณผ ์ ์ฌํฉ๋๋ค.
๐น Tools
- BurpSuite DOM Invader for DOM Vulnerability
- My ZAP Script
๐ References
- https://www.slideshare.net/x00mario/in-the-dom-no-one-will-hear-you-scream
- https://portswigger.net/research/dom-clobbering-strikes-back
- https://portswigger.net/web-security/dom-based/dom-clobbering
- https://terjanq.medium.com/clobbering-the-clobbered-vol-2-fb199ad7ec41
- https://github.com/hahwul/fuzzstone/blob/main/zap-scripts/passive/findDOMClobbering.js