보안/XSS
[XSS] xss-game Level 4: Context matters
dDong2
2022. 12. 28. 09:54
XSS game : https://xss-game.appspot.com/
✔️ 문제
문제는 다음과 같다.
어플리케이션에 자바스크립트 alert를 삽입하는 것으로 보인다.
✔️ 풀이
다음처럼 script 구문을 삽입하게 되면 time 제한에
걸리는 것으로 보이니 코드를 살펴보자.
function startTimer(seconds) {
seconds = parseInt(seconds) || 3;
setTimeout(function() {
window.confirm("Time is up!");
window.history.back();
}, seconds * 1000);
}
다음과 같은 자바스크립트 코드가 구성되어 있다.
seconds 파라미터를 받아와서 문자열을 숫자로 변환하거나
또는 3의 변수를 저장하고, confirm 메세지를 띄워준다.
setTimeout 메서드는 만료된 후 해당 숫자 * 1000 만큼의 시간 뒤에
history.back() 함수를 동작하게 된다.
예를 들어 2를 입력하면 2000 만큼의 시간 뒤에
Time is up! 이라는 문구가 뜨게 된다.
<body id="level4">
<img src="/static/logos/level4.png" />
<br>
<img src="/static/loading.gif" onload="startTimer('{{ timer }}');" />
<br>
<div id="message">Your timer will execute in {{ timer }} seconds.</div>
</body>
HTML과 같이 보게되면, startTimer('2'); 가 되는 것이다.
그렇다면 해당 구문을 조작하여 startTimer('2'); alert(1);이 되게 만든다면?
해당 구문과 같이 만들어주기 위해서 다음과 같이 삽입해보자.
2');alert('1
정상적으로 문제가 풀리면서 성공적으로 alert를 띄울 수 있었다.
화이팅 💪