2023. 1. 27. 18:42ㆍ카테고리 없음
첫 화면은 이렇게 뜹니다.
댓글창도 없고 로그인 창도 없는 것을 보니 url을 이용해야 하는 문제인 것 같습니다.
늘 했던 대로 아래와 같은 코드를 입력했더니 평소처럼 풀리지 않았습니다.
<script>alert(1);</script>
여기서 Target code를 누르면 코드가 나오는데 참고해서 풀어보도록 하겠습니다.
아래와 같은 코드를 봤을 때 이미지를 #뒤에 받은 인자를 바탕으로 불러오는 것을 볼 수 있습니다. (실제 나오는 코드)
<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이라는 것을 알려줍니다.
검색을 해보니 아래와 같은 사이트가 나오는데
여기서 xss 예시 스크립트를 볼 수 있습니다.
https://security.stackexchange.com/questions/177261/is-xss-possible-with-jquerylocation-hash
Is XSS possible with jQuery(location.hash)?
Is it possible to exploit XSS in the following code? jQuery(window.location.hash) It seems to me that window.location.hash always starts with a hash #, and modern jQuery always interpretes this a...
security.stackexchange.com
하지만 그대로 적용하면 안 풀립니다.
아래처럼 script를 선언해주면 문제가 풀립니다.
'><script>alert('xss');</script>
xss 문제를 풀어보다보니 csrf를 찾아보게 되었습니다.
xss와 csrf는 공격 대상을 찾아 공격을 하는 것입니다.
공격 방식은 완전 비슷하지만 xss와 csrf는 명확한 차이첨이 있습니다.
xss는 주로 session 탈취를 목적으로 사용되고 csrf는 주로 admin을 해킹하려는 목적으로 사용된다고 합니다.
그렇지만 xss는 임의의 javascript를 실행할 수 있다는 것이고 csrf는 임의의 url로 요청을 보낼 수 있다는 거니 목적이 다르다기보다 다른 종류의 취약점입니다.
xss는 사용자 특정 웹사이트를 이용한다는 점을 노리고, csrf는 특정 웹사이트가 사용자의 웹 브라우저를 사용하는 상태를 노립니다.
즉 xss는 사이트 변조나 백도어를 통해 클라이언트에 대한 악성공격을 하고,
csrf는 요청을 위조하여 사용자의 권한을 이용해 서버에 대한 악성공격을 합니다.