이 문제는 팀원이 먼저 푼 문제인데, 나도 뒤이어 금새 풀었던 문제라 write-up를 작성한다.
⭐JS Easy (100)
.
flag가 출력되도록 코드를 수정
주어진 링크에 접속하여 얻은 html을 해석하고, flag가 출력되도록 코드를 수정하는 간단한 문제이다.
주어진 링크에서 개발자 모드를 열고 '소스' 에서 js_easy.html
이라는 html 파일을 얻었다. 내용은 다음과 같다.
<html>
<head>
<meta charset='utf-8'>
<title>Execute ME?</title>
<style>
body{background-color:#000000;color:#ffffff;font-weight:bold;font-size:30px}.main{text-align:center;margin-top:40vh}.flag{text-align:center;background-image:linear-gradient(90deg,red,yellow,green,blue,purple);-webkit-background-clip:text;color:transparent;font-weight:bold;font-size:40px;margin:0px 23vw}
</style>
</head>
<body>
<div class="main">
The Flag is<br />
</div>
<script>
"use strict";var a='1';var b='2';var c='3';var d='4';var e='5';var f='&ŧijŧŠ#ŇŠŇij,ŞŨųŞ)ňŲŞų2ŮįŞń?ŀŒŘŞ8őİŦŧ\x05ųľ';var h='';for(var i=0;i<f.length;i++){if(i%5){h=f[i];h=String.fromCharCode(h.charCodeAt()-a.charCodeAt());h=String.fromCharCode(h.charCodeAt()-b.charCodeAt());h=String.fromCharCode(h.charCodeAt()-c.charCodeAt());h=String.fromCharCode(h.charCodeAt()-d.charCodeAt());h=String.fromCharCode(h.charCodeAt()-e.charCodeAt());g+=h}else{h=i^38;h=String.fromCharCode(h);if(f[i]!=h){alert("SomeThing Wrong,,");break}}}var flag=g;
</script>
<script>
if(typeof(flag)!='undefined'){document.write("<div class='flag'>FLAG!!(",flag,")</div>")}
</script>
</body>
</html>
코드를 보면 FLAG!! 라는 글과 함께 flag가 출력되도록 하고 있는데, 이 코드가 작동되지 않는듯했다. 이 코드가 작동되도록 하려면 올바르게 작동하도록 수정해야한다.
위 코드에서
다음과 같이 g
가 defined 되지 않았다고 알림이 뜬다. 그렇다면 g
를 추가해주면 될 것이다.
아래는 수정된 코드다.
<html>
<head>
<meta charset='utf-8'>
<title>Execute ME?</title>
<style>
body{background-color:#000000;color:#ffffff;font-weight:bold;font-size:30px}.main{text-align:center;margin-top:40vh}.flag{text-align:center;background-image:linear-gradient(90deg,red,yellow,green,blue,purple);-webkit-background-clip:text;color:transparent;font-weight:bold;font-size:40px;margin:0px 23vw}
</style>
</head>
<body>
<div class="main">
The Flag is<br />
</div>
<script>
>---추가된부분---<
var g='';
"use strict";var a='1';var b='2';var c='3';var d='4';var e='5';var f='&ŧijŧŠ#ŇŠŇij,ŞŨųŞ)ňŲŞų2ŮįŞń?ŀŒŘŞ8őİŦŧ\x05ųľ';var h='';for(var i=0;i<f.length;i++){if(i%5){h=f[i];h=String.fromCharCode(h.charCodeAt()-a.charCodeAt());h=String.fromCharCode(h.charCodeAt()-b.charCodeAt());h=String.fromCharCode(h.charCodeAt()-c.charCodeAt());h=String.fromCharCode(h.charCodeAt()-d.charCodeAt());h=String.fromCharCode(h.charCodeAt()-e.charCodeAt());g+=h}else{h=i^38;h=String.fromCharCode(h);if(f[i]!=h){alert("SomeThing Wrong,,");break}}}var flag=g;
</script>
<script>
if(typeof(flag)!='undefined'){document.write("<div class='flag'>FLAG!!(",flag,")</div>")}
</script>
</body>
</html>
이렇게 수정하고 새로고침하면,
이렇게 flag를 얻을 수 있다.
나는 처음에는 이렇게 간단하게 한줄 추가하면 되는지 모르고 이것저것 건들다가 다음과 같이 flag가 깨져서 나오는 바람에 해결하는데 오래 걸렸다 ㅠㅠ