WEB/webhacking.kr
[webhacking. kr] old-16
뇨롱
2020. 7. 31. 05:30
▷유형: JAVA Script
▷문제:
문제에 갑자기 이쁜 별이 있다
별에 홀리지 말고 소스코드를 보니 꽤 많은 것들이 숨겨져있다!
<페이지 소스>
<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>
4번째 줄에 함수가 사용되었기 때문에 script부분의 함수 정의 부분을 살펴야한다.
[16번에서 쓰인 문법과 용어]
∨ string.fromcharcode()
: 입력된 문자열을 아스키코드 값으로 바꿔 문자열을 출력한다.
첫번째, mv함수
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!
}
cd를 인자로 돌려 100,97,119,115,124를 받으면 별을 출력하는데
124를 받으면 string.fromcharcode(cd).php로 이동한다!
문제 해결을 위해, cd에 124를 넣어주는 걸 해야한다.
①
아스키코드표를 이용해 124를 문자로 바꾸면
아스키 코드를 잘보면 문제 | 가 124로 바뀌는 걸 알 수 있다.
②
문제 페이지로 가서 그냥 |를 입력하면,
문제가 해결된다 ㅋㅋㅋㅋㅋ
kk함수는 보지도 않았다..
일단 kk 함수
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>";
}
그다지, 의미가 없어보인다... 따라서 패쓰~~~~