Wargame(Web)/Webhacking.kr Writeup

Webhacking Writeup 16번 문제

P_Squirrel 2022. 7. 6. 07:10

Webhacking Writeup old-16번 문제 입니다.

접속해보니 소스코드도 없고 노란별 2개에 흐릿한 별 한개가 있습니다.

흐릿한 별에 마우스를 가져가니 사라졌습니다....

뭐하는 건지 아무것도 모르겠으니 HTML 소스를 한번 까보겠습니다.

<html>
<head>
<title>Challenge 16</title>
<body bgcolor=black onload=kk(1,1) onkeypress=mv(event.keyCode)>
<font color=silver id=c></font>
<font color=yellow size=100 style=position:relative id=star>*</font>
<script> 
document.body.innerHTML+="<font color=yellow id=aa style=position:relative;left:0;top:0>*</font>";
function mv(cd){
  kk(star.style.left-50,star.style.top-50);
  if(cd==100) star.style.left=parseInt(star.style.left+0,10)+50+"px";
  if(cd==97) star.style.left=parseInt(star.style.left+0,10)-50+"px";
  if(cd==119) star.style.top=parseInt(star.style.top+0,10)-50+"px";
  if(cd==115) star.style.top=parseInt(star.style.top+0,10)+50+"px";
  if(cd==124) location.href=String.fromCharCode(cd)+".php"; // do it!
}
function kk(x,y){
  rndc=Math.floor(Math.random()*9000000);
  document.body.innerHTML+="<font color=#"+rndc+" id=aa style=position:relative;left:"+x+";top:"+y+" onmouseover=this.innerHTML=''>*</font>";
}
</script>
</body>
</html>

 

일단 mv라는 함수가 있고 cd라는 인수를 받습니다.

mv함수가 kk로 별을 만들어 주고 있는데 잘 모르겠으니
밑의 if 구문을 하나씩 해석해보겠습니다.

cd가 100인 경우 별의 위치를 옮기고

cd가 97인 경우에도 별의 위치를 옮기고

.....

마지막에 cd가 124인경우 location.href=String.fromCharCode(cd)+".php"; 를 실행하는데

주석에 do it이라는 것으로 보아 저희가 접속해야할 링크인것 같습니다.

String.fromCharCode가 무엇인지 몰라 구글링을 해보니

숫자를 입력받아 문자열로 바꿔주는 함수라고 합니다.
바꿔보는 것도 가능하니 우리가 해결해야할 cd값 124로 바꿔보겠습니다.

| 하나만 출력되는데 이걸 아까전 if문에 대입해보면

if(cd==124) location.href=String.fromCharCode(cd)+".php"; // do it!

링크가 |.php 가 되는 것을 알 수 있습니다.

그럼 이것을 url에 대입해 보겠습니다.

자동적으로 %7C로 변경되며 링크에 접속해 문제가 해결되었습니다!