[PortSwigger Web Security Academy]Lab: DOM XSS in document.write sink using source location.search write up

zzsla·2023년 8월 13일
0

문제 정보

This lab contains a DOM-based cross-site scripting vulnerability in the search query tracking functionality. It uses the JavaScript document.write function, which writes data out to the page. The document.write function is called with data from location.search, which you can control using the website URL.

To solve this lab, perform a cross-site scripting attack that calls the alert function.

문제

lab에 들어가면 가상 blog 사이트가 나온다.

분석

search query tracking 기능에 DOM-based XSS 취약점이 있다.
document.write는 페이지에 데이터를 쓴다.
document.write는 Website URL을 사용하여 제어할 수 있는 location.search의 데이터로 호출된다.
목표
XSS의 alert을 이용한다.

일단 search query tracking 기능, 즉 검색 기능에 DOM_based XSS 취약점이 있다고 하니까 확인하기 위해 검색창에 아무값이나 넣고 검색을 하고 코드를 보면 취약한 부분을 볼 수 있다.

검색을 하게 되면 document.write에 있는 <img src>에서 해당 query를 찾게 된다 여기서는 xss가 되기 때문에 "><img src>를 탈출하고 script문을 넣어서 xss를 작동시킨다. 그래서 이것을 종합하면 "><script>alert(1)</script>이 나온다.

이것을 검색하면 문제가 풀린다.

profile
[README]newbi security hacker :p

0개의 댓글