xss-2
wargame, web
문제
XSS 공격으로 플래그를 얻는 문제이다.
문제 분석
전체적인 구조는 이전 글 xss-1 과 유사한 것 같다.
/vuln 페이지에 들어가봤는데 스크립트가 실행되지 않는다.. 분명 param에는 XSS 페이로드가 있는데..?
문제 파일을 확인해보자… templates/vuln.html의 소스코드를 확인해보았다.
<div id="vuln"></div>
<script>
var x = new URLSearchParams(location.search);
document.getElementById('vuln').innerHTML = x.get('param');
</script>
음.. 쿼리스트링의 param 을 vuln 엘리먼트의 innerHTML 로 설정한다.
<script> 태그는 잘 들어가있는데 실행이 안된다.
innerHTML 에 대해 조금 더 찾아봤는데 이런 글이 있다. innerHTML docs
Although this may look like a cross-site scripting attack, the result is harmless. HTML specifies that a
<script>tag inserted with innerHTML should not execute
innerHTML 로 삽입된 <script> 태그는 실행되지 않는다고 한다.
However, there are ways to execute JavaScript without using <script> elements, so there is still a security risk whenever you use innerHTML to set strings over which you have no control. For example:
const name = "<img src='x' onerror='alert(1)'>";
el.innerHTML = name; // shows the alert
그러나 <script> 태그를 사용하지 않고 대신 <img> 태그를 사용하는 방법이 있다고 한다. 이는 <script> 태그가 아니기 때문에 자바스크립트가 실행된다.
풀이
innerHTML 로 삽입된 <script> 태그는 실행되지 않기 때문에 <img> 태그를 대신 이용하여 해결하였다.
// 페이로드
<img src="AS" onerror="location.href='/memo?memo=' + document.cookie">

페이로드 제출 후 /memo 페이지
