Xss game level 6 write up - 마지막


#번역

미션 설명 : 복잡한 웹 응용 프로그램에는 URL 매개변수의 값 또는 일부의 값에 따라 Javascript 라이브러리를 동적으로 로드할 수 있는 location.hash 기능있습니다. 

스크립트를 비롯한 잠재적으로 위험한 유형의 XMLHttpRequest 데이터를 로드할 때마다  심각한 취약점을 초래할 수 있수 있기에 사용자 입력이 url에 영향을 미치도록 허용하는 것은 매우 까다로운 작업입니다. 


미션 목표 : 응용 프로그램이 외부 파일을 요청하도록 하여 alert()를 실행하도록 하시오.



#분석


우선 미션 설명에서 얻을 수 있는 정보는 url를 이용해야 되고 그 중 js라이브러리를 동적으로 로드할 수 있는 함수 중 location.hash를 사용해야 된다는거!

그럼 소스에서 location.hash를 찾아보자. 




<!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 setInnerText(element, value) {
      if (element.innerText) {
        element.innerText = value;
      } else {
        element.textContent = value;
      }
    }
 
    function includeGadget(url) {
      var scriptEl = document.createElement('script');
 
      // This will totally prevent us from loading evil URLs!
      if (url.match(/^https?:\/\//)) {
        setInnerText(document.getElementById("log"),
          "Sorry, cannot load a URL containing \"http\".");
        return;
      }
 
      // Load this awesome gadget
      scriptEl.src = url;
 
      // Show log messages
      scriptEl.onload = function() {
        setInnerText(document.getElementById("log"), 
          "Loaded gadget from " + url);
      }
      scriptEl.onerror = function() {
        setInnerText(document.getElementById("log"), 
          "Couldn't load gadget from " + url);
      }
 
      document.head.appendChild(scriptEl);
    }
 
    // Take the value after # and use it as the gadget filename.
    function getGadgetName() {
      return window.location.hash.substr(1) || "/static/gadget.js";
    }
 
    includeGadget(getGadgetName());
 
    // Extra code so that we can communicate with the parent page
    window.addEventListener("message", function(event){
      if (event.source == parent) {
        includeGadget(getGadgetName());
      }
    }, false);
 
    </script>
  </head>
 
  <body id="level6">
    <img src="/static/logos/level6.png">
    <img id="cube" src="/static/level6_cube.png">
    <div id="log">Loading gadget...</div>
  </body>
</html>

index.html 전체 소스 




// Take the value after # and use it as the gadget filename.
    function getGadgetName() {
      return window.location.hash.substr(1) || "/static/gadget.js";
    }

위에는 location.hash가 포함된 부분이다. 주석에는 #을 사용한 후에 gadget 파일을 사용한다고 한다.


#뒤의 내용을 출력해주고 있다. 



#? hint를 보면 #에 대한 언급이 있다. 




hint

1. 위치 #의 값이 로드된 스크립트의 url에 어떻게 영향을 미치는지 확인하세요.

2. Gadgets의 url 보안검사가 정말로 안전한가요?

3. 때때로 좌절감을 느낄때 비명을 지르고 싶다(??????이거 진짜임?)

4. 악의적인 JS파일을 쉽게 호스팅할 수 없다면, google.com/jsapi?callback=foo가 여기에 도움이 되는지 확인을 하세요. -> 스크립트 파일을 서버에 올려서 사용하라는 말이란다...음..


foo는 heap에서 공부할 때도 많이 나왔는데 그냥 빈칸 채우기 용인가???

검색해보니까 재밌는게 있어서 첨부함. http://aroundck.tistory.com/956

빈칸 채우기용 foo! 왜인지 heap 공부할 때 이해안되서 쳐보니까 아무것도 안 나오더라~~~


url을 보면 https://xss-game.appspot.com/level6/frame#/static/gadget.js 이렇게 구성이 되어있다. # 뒤에 있는 내용이 화면에 출력된다. 







#익스


서버 사용하기 귀찮아서 data url scheme으로 풀게 되었다. 

데이터를 url로 변경해서 data:[자료타입],[데이터] 이렇게 넣으면 된다. 


https://xss-game.appspot.com/level6/frame#data:text/javascript,alert('yeali');





이렇게 넣으면 성공.




pps. http://jeonyoungsin.tistory.com/480


이런식으로 푸는 방법도 있다.






'WebHacking > Xss-game Write-Up' 카테고리의 다른 글

Xss game level 5 write up  (0) 2018.07.17
Xss-game level 4 write up  (0) 2018.07.17
Xss game level 3 write-up  (0) 2018.07.17
Xss-game level 2 write_up  (0) 2018.07.17
Xss-game level 1 write-up  (0) 2018.07.17

Xss game level 5 write up


#번역


미션 설명 : XSS는 데이터를 올바르게 이스케이프 처리하는거에 멈추지 않습니다. 때로는 공격자가 Dom에 새 요소를 주입하지 않고도 나쁜일을 할 수 있습니다.


미션 목표 : alert()를 넣어서 팝업 스크립트를 삽입하시오.



#분석


Dom에 스크립트를 삽입하지 않고 푸는 문제라는게 무슨 뜻일까?? 풀면 알 듯하다. 


hint

1. 제목이 힌트이다.

2. 가입 프레임의 소스를 보고 URL 매캐 변수가 어떻게 사용되는지 살펴보는것이 좋다.

3. onclick 핸들러를 사용하지 않고 링크를 클릭하여 javascript를 실행하게 하려면 어떻게 해야 되는가?

4. 진짜 안 풀리면 IETF 초안을 살펴보자. (https://tools.ietf.org/html/draft-hoehrmann-javascript-scheme-00)




의심스러운 것!

<script>
      setTimeout(function() { window.location = '{{ next }}'; }, 5000);
    </script>


이 부분이 의심스러웠음. timeout을 하는 곳에 스크립트를 추가해서 하는건가?!


next는 

    <a href="{{ next }}">Next >></a>

이렇게 링크를 클릭하면 next를 받아서 넘어가도록 코딩해놓음. 



next변수가 get방식으로 하여 url에 드러나니 url로 스크립트를 전달하면 된다. 


url로 스크립트를 전달하는 것이 Dom에 스크립트를 삽입하지 않고 문제를 푸는 것일까??


" "안에 있는 내용은 내 생각임을 밝힘. 틀리면 말해주세여. 내가 이해한 내용이 틀렸다는거니까!



** Dom : Document Object Model 문서 객체 모델은 HTML 및 XML 문서를 처리하는 API라고 합니다. 문서의 구조적 형태를 제공하므로 자바스크립트와 같은 스크립트 언어를 사용하여 문서 내용과 시각적 표현을 수정할 수 있습니다. 

"문서를 구조화시키고 Dom이 이해해서 추상화를 시킨다. 여기서 추상화란, 핵심적인 개념을 뽑는 활동으로 생각했다. 추상화를 시켜서 그를 이미지화하여 브라우저에 보이게 하는 역할을 한다고 생각함. "


** API : 응용 프로그램에서 사용할 수 있도록 운영 체제나 프로그래밍 언어가 제공하는 기능을 제어할 수 있게 만든 인터페이스를 뜻함. 

"인터페이스란 다른 언어를 사용하고 있는 매체들 사이에서 의사소통이 가능하도록 하는 것을 말한다고 한다. 그러므로 프로그램에서 운영체제와 프로그래밍 언어를 제공할 수 있도록 만드는 의사소통 가능하게 만드는 것이라고 생각함"



next 변수를 활용하는 건 알았는데, next변수에 alert()를 넣고 Go를 눌러도 아무 반응이 없었다. 


Go를 누르는게 아닌거같다. next 링크가 url에 있는대로 가서 바꿔주지 않으면 confirm으로 가게 되는데, 이것을 팝업창을 띄어주는 스크립트를 넣으면 된다. 이런게 Dom에 스크립트를 추가하지 않고 실행하는 예시인듯하다. 


#익스



https://xss-game.appspot.com/level5/frame/signup?next=javascript:alert('yeali');

을 넣고, next를 누르면 뜸. 






'WebHacking > Xss-game Write-Up' 카테고리의 다른 글

Xss game level 6 write up  (0) 2018.07.17
Xss-game level 4 write up  (0) 2018.07.17
Xss game level 3 write-up  (0) 2018.07.17
Xss-game level 2 write_up  (0) 2018.07.17
Xss-game level 1 write-up  (0) 2018.07.17

xss game level 4 write up


#번역


미션 설명 : 사용자가 제공한 모든 데이터는 표시도리 페이지의 내용에 맞게 올바르게 이스케이프되어야 합니다. 


미션 목표 : alert()로 팝업하는 스크립트를 삽입하세요.





#분석


hint

1. startTimer 함수가 호출되는 방법을 살펴봅시다. 

2. 브라우저가 태그 속성을 구문 분석할 때 먼저 HTML 값을 디코딩합니다. <foo bar = 'z'>는 <foo bar='&#x7a;와 동일합니다. 

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를 보니 이 글과 같이 푸는게 출제의도인거같아서 적어둠. 

'WebHacking > Xss-game Write-Up' 카테고리의 다른 글

Xss game level 6 write up  (0) 2018.07.17
Xss game level 5 write up  (0) 2018.07.17
Xss game level 3 write-up  (0) 2018.07.17
Xss-game level 2 write_up  (0) 2018.07.17
Xss-game level 1 write-up  (0) 2018.07.17


Xss game level 3 write up


#번역


미션 설명 : level 2에서 보았듯이 일부 일반적인 js기능은 실행입니다. 즉, 브라우저가 입력에 나타는 스크립트를 실행하게 됩니다. 때로는 이러한 사실은 상위 수준의 API에 의해서 기능이 숨겨집니다. 이 레벨의 응용 프로그램은 그러한 숨겨진 싱크를 사용하고 있습니다. 


미션 목표: 이전과 마찬가지로 alert()를 사용한 팝업 스크립트를 삽입하세요. 


애플리케이션의 어느 위치에든 페이로드를 입력할 수 없으므로 아래의 url 표시줄에서 수동으로 주소를 편집해야 합니다. 





#분석



<!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" />
 
    <!-- Load jQuery -->
    <script
      src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js">
    </script>
 
    <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>
 
  </head>
  <body id="level3">
    <div id="header">
      <img id="logo" src="/static/logos/level3.png">
      <span>Take a tour of our cloud data center.</a>
    </div>
 
    <div class="tab" id="tab1" onclick="chooseTab('1')">Image 1</div>
    <div class="tab" id="tab2" onclick="chooseTab('2')">Image 2</div>
    <div class="tab" id="tab3" onclick="chooseTab('3')">Image 3</div>
 
    <div id="tabContent"> </div>
  </body>
</html> 





hint를 보았다!! 

1. 버그의 원인을 찾으려면 Javascript가 사용자가 제공한 입력을 처리하는 위치를 확인하세요.

2. window.location 개체의 데이터는 공격자의 영향을 받을 수 있습니다. 

3. 주입 지점을 확인했으면 새 HTML 요소에 들어가기 위해 할 일에 대해서 생각해보세요.

4. 브라우저가 페이지 로드 된 후에 추가된 스크립트를 실행하지 않기 때문에 이전과 마찬가지고 <script>를 사용하면 작동하지 않습니다.


window.onload = function() {
        chooseTab(unescape(self.location.hash.substr(1)) || "1");
      }
 


이걸 이용하는거같은데 어떻게 이용하는걸까?


그 hint에서 3번을 보면 html요소에 들어가기 위해서 할일이라고 해서 코드를 보니 html에 들어가는 곳이 있다.

 var html = "Image " + parseInt(num) + "<br>";
        html += "<img src='/static/level3/cloud" + num + ".jpg' />";
        $('#tabContent').html(html);

img src가 저기 안에 있고, html로 들어가 적용시키고 띄우게 코딩되어있다. 그럼 level 2번에서 한 것처럼 똑같이 해보면 되지 않을까?





#익스


<img src="image.gif" onerror="myFunction()">


현재 문제창에는 url : https://xss-game.appspot.com/level3/frame#3 이렇게 떠있다. 


onerror를 사용하기 위해서 https://xss-game.appspot.com/level3/frame#'4.png' onerror='alert("yeali")'> 이렇게 url창에 입력해준다!




'WebHacking > Xss-game Write-Up' 카테고리의 다른 글

Xss game level 6 write up  (0) 2018.07.17
Xss game level 5 write up  (0) 2018.07.17
Xss-game level 4 write up  (0) 2018.07.17
Xss-game level 2 write_up  (0) 2018.07.17
Xss-game level 1 write-up  (0) 2018.07.17


Xss game level 2 write up


#번역


미션 설명 : 웹 응용 프로그램은 종종 사용자 데이터를 서버 측 및 클라이언트 측 데이터베이스에 보관하고 나중에 사용자에게 표시합니다. 그러한 사용자 제어 데이터의 출처가 무엇이든 관계없이 신중하게 처리해야 합니다.


복잡한 응용 프로그램에서 xss 버그를 얼마나 쉽게 도입할 수 있는지 알 수 있습니다. 


미션 목표 : alert() 응용 프로그램의 내용 안에 팝업 스크립트를 삽입하세요.

참고 : 응용 프로그램에서 게시물을 저장하므로 코드를 몰래 사용하여 경고를 실행하면 다시 로드할 때마다 수준이 해결됩니다. 




#분석


<script>구문이 먹히지 않음으로 필터링하고 있음을 알게 되었다. (필터링 하는 법 공부 예정)


hint로 onerror를 사용하라고 했는데, onerror를 검색하니 이렇게 나왔다.

(https://www.w3schools.com/jsref/event_onerror.asp)



<img src="image.gif" onerror="myFunction()">


img src를 실행하고 없으면 에러가 발생하고 onerror를 실행하게 된다.


그래서 일부러 없는 파일을 실행시킨 후 onerror에 원하는 행동을 하면 xss를 실행할 수 있게 된다.  




#익스


<img src=image.gif onerror=alert("yeali")>




'WebHacking > Xss-game Write-Up' 카테고리의 다른 글

Xss game level 6 write up  (0) 2018.07.17
Xss game level 5 write up  (0) 2018.07.17
Xss-game level 4 write up  (0) 2018.07.17
Xss game level 3 write-up  (0) 2018.07.17
Xss-game level 1 write-up  (0) 2018.07.17

XSS game Level 1 Write up


# Analysis



번역)

미션 설명

사용자 입력이 적절한 이스케이프 처리없이 페이지에 직접 포함되는 크로스 사이트 스크립팅의 일반적인 원인을 보여준다. 

아래의 취약한 응용 프로그램 창과 상호 작용하고 원하는 JavaScript를 실행하는 방법을 찾아라. 취약한 창 내부에서 작업을 수행하거나 URL 표시 줄을 직접 편집 할 수 있다. 


미션 목표

아래 프레임에 JavaScript alert()를 삽입하시오! 

알림을 표시하면 다음 단계로 넘어갈 수 있습니다.  





** escape/이스케이프 :  번역을 하면 탈출이라는 뜻. 

값을 에러없이 전달하기 위해서 사용된다. 제어 문자로 인식될 수 있는 특정 문자 왼쪽에 슬래시를 붙이거나 URL 또는 HTML 엔티티 등으로 인코딩하여 제어 문자가 아닌 일반 문자로 인식시켜 에러 또는 에러를 이요한 부정행위를 방지하게 한다. 

또한 javascript에서 사용하는 함수 중 하나다. url로 데이터를 전달하기 위해서 문자열을 인코딩한다. 


***HTML Entity : HTML이나 XHTML 문서를 코딩할 때 특수문자를 써야 하는 경우에는 이러한 엔티티 코드 또는 엔티티 넘버로 변환해서 입력해야 한다. 변환하지 않고 특수문자를 그대로 입력해버리면 컴퓨터가 문서를 읽을 때 실제 문서 내용과 코드를 구분하지 못하는 문제가 발생한다. 또한 이스케이프때문에 사용한다. 

https://blog.outsider.ne.kr/380 



Exploit


<script>alert("yeali")</script>




'WebHacking > Xss-game Write-Up' 카테고리의 다른 글

Xss game level 6 write up  (0) 2018.07.17
Xss game level 5 write up  (0) 2018.07.17
Xss-game level 4 write up  (0) 2018.07.17
Xss game level 3 write-up  (0) 2018.07.17
Xss-game level 2 write_up  (0) 2018.07.17

+ Recent posts