Xss-game level 4 write up
xss game level 4 write up
#번역
미션 설명 : 사용자가 제공한 모든 데이터는 표시도리 페이지의 내용에 맞게 올바르게 이스케이프되어야 합니다.
미션 목표 : alert()로 팝업하는 스크립트를 삽입하세요.
#분석
hint
1. startTimer 함수가 호출되는 방법을 살펴봅시다.
2. 브라우저가 태그 속성을 구문 분석할 때 먼저 HTML 값을 디코딩합니다. <foo bar = 'z'>는 <foo bar='z와 동일합니다.
3. 작은 따옴표(')를 입력하고 오류 콘솔을 확인하세요.
3번에서 작은 따옴표를 입력하면
이렇게 됩니다!
1번에서 startTimer 함수가 호출되는 방법을 확인하라고 했는데 그 내용은 timer.html에 존재함!
<!doctype html><html> <head> <!-- Internal game scripts/styles, mostly boring stuff --> <script src="/static/game-frame.js"></script> <link rel="stylesheet" href="/static/game-frame-styles.css" /> <script> function startTimer(seconds) { seconds = parseInt(seconds) || 3; setTimeout(function() { window.confirm("Time is up!"); window.history.back(); }, seconds * 1000); } </script> </head> <body id="level4"> <img src="/static/logos/level4.png" /> <br> <img src="/static/loading.gif" onload="startTimer('{{ timer }}');" /> <br> <div id="message">Your timer will execute in {{ timer }} seconds.</div> </body></html>또한 index.html를 보면
<!doctype html><html> <head> <!-- Internal game scripts/styles, mostly boring stuff --> <script src="/static/game-frame.js"></script> <link rel="stylesheet" href="/static/game-frame-styles.css" /> </head> <body id="level4"> <img src="/static/logos/level4.png" /> <br> <form action="" method="GET"> <input id="timer" name="timer" value="3"> <input id="button" type="submit" value="Create timer"> </form> </form> </body></html>get방식임을 확인할 수 있고, timer.html에서 onload로 입력한 time이 들어감을 확인할 수 있다.
url은 https://xss-game.appspot.com/level4/frame 이렇게 구성되어있는데, get방식으로 timer를 불러오니까 뒤에 스크립트를 추가하면 된다.
#익스
기존 url : https://xss-game.appspot.com/level4/frame
3을 input값에 넣으면 https://xss-game.appspot.com/level4/frame?timer=3 이렇게 된다.
https://xss-game.appspot.com/level4/frame?timer=('{{ timer }}'); 이렇게 전달되는것 같으니
timer=1'); alert(''yeali" 이 내용을 넣어주면, https://xss-game.appspot.com/level4/frame?timer=('1'); alert(''yeali")');
이렇게 깔끔하게 되니까 실행되겠지?!!
근데 안됨.
https://xss-game.appspot.com/level4/frame?timer=1')-alert('yeali 이렇게 하면 됨. -연산을 주면 alert창이 뜨면서 성공!
ps. 다른 블로그에서 다른 스크립트로 푼게 있어서 적어두려고 함.
나와 같이 세미콜론으로 해서 안 되는 경우였음. 나는 -연산을 사용했지만 다른 글은 url 인코딩해서 보내주어서 문제를 풀었다.
;를 %3B로 바꿔서 입력해서 ;으로 입력하여 푼 경우가 있음. hint를 보니 이 글과 같이 푸는게 출제의도인거같아서 적어둠.