# Cross-site scripting Lab6
這題要使用 location.hash 控制頁面行為,透過 jQuery 的 `$() selector` 將 hash 傳入,觸發 DOM XSS,利用 `<iframe>` 自動傳送 payload 給受害者瀏覽器,目標是觸發 `print()` 函數(模擬 XSS 行為)。
一樣先進入網站。

查看原始碼。

當網址 `hash(#...)` 改變時,會觸發 hashchange 事件。
會取出 `window.location.hash` 的值,例如:
#hello → hello(使用 `.slice(1)` 去掉井字號)
用這個字串組成一個 jQuery selector:
```
$('section.blog-list h2:contains(hello)')
```
意思是找出 `section.blog-list` 裡包含 hello 的 `<h2>` 標題,如果有找到就呼叫 `.scrollIntoView()`,讓該 `<h2>` 自動滾到畫面上。
而這裡的 `contains(...)` 是一個 CSS selector 字串拼接,果 hash 是惡意內容(例如插入單引號、括號),會導致 selector injection、甚至 DOM XSS

```
<iframe src="https://0ac100360455cb1f81c534d9005b00cc.web-security-academy.net/#" onload="this.src+='<img src=x onerror=print()>'"></iframe>
```
iframe 的 onload 事件觸發,會把 `<img src=x onerror=print()>` 串接到 src,變成:
```
https://0ac100360455cb1f81c534d9005b00cc.web-security-academy.net/#<img src=x onerror=print()>
```
因為 hash 改變,觸發 hashchange 事件,jQuery 將這段 HTML 當成 selector 選取、渲染、執行 → 成功觸發 `print()`

---