【第二十八天 - XSS Lab(2)-6】

Q1. XSS Lab(2)-6

题目:https://alf.nu/alert1

  1. Quine

    • 题目:

      // submitted by Somebody
      function escape(s) {
          // We've got a quine level in all of the other
          // games, so why not have one here?
          var win = alert;
          window.alert = function(t) {
              if (t === s)
                  win(1);
              else
                  console.log("Alert: " + t + "\n(That's not a quine)");
          }
          return s;
      }
      
    • 解题:

      • Quine 是「自产生程序」的意思,意思是是「输出结果」等同「自身原始码」的程序。
      • 本题需要输入值 s 能够呼叫 alert,但呼叫的参数 t 等同於 s
      • 由於 s 会是整个 document 的内容,这边用 document.body.innerHTML 当参数 t 传入即可
      • 参考资料:https://codepen.io/rileyjshaw/pen/iGjgs
    • ANS: <script>alert(document.body.innerHTML)</script>

  2. Entities

    // submitted by securityMB
    function escape(s) {
      function htmlentities(s) {
        return s.replace(/[&<>"']/g, c => `&#${c.charCodeAt(0)};`)
      }
      s = htmlentities(s);
      return `<script>
    	  var obj = {};
    	  obj["${s}"] = "${s}";
    	</script>`;
    }
    
    • 题目过滤了 &<>"',但是没有过滤 ;/\

    • 宣告了个物件 obj,并且命 obj["输入字串"] ="输入字串";

    • 而 JS 有个特性,若找不存在的 key,不会造成语法错误

      https://ithelp.ithome.com.tw/upload/images/20211012/20140592MJCpPP4FMD.png

    • 那我们就利用这个特性,将 obj 变成 obj["字串"];alert(1); ,来执行 alert(1)

    https://ithelp.ithome.com.tw/upload/images/20211012/20140592I7CXfNfsvK.png

    • ANS
      • ];alert(1);//\
  3. %level%

    • 题目:

      // submitted anonymously
      function escape(s) {
          const userInput = JSON.stringify(s).replace(/[<]/g, '%lt').replace(/[>]/g, '%gt');
          const userTemplate = '<script>let some = %userData%</script>';
          return userTemplate.replace(/%userData%/, userInput);
      }
      
    • 解题:

      • Regex 中, $' 表示 after match , $` 表示 before match
      • 因此在 userTemplate.replace(/%userData%/, userInput); 中:
        • userInput 中出现$'表示 </script>
        • userInput 中出现 $` 表示 <script>let some =
      • 藉此我们可以构建出 </script><script>let some = alert(1)// 绕过限制。
    • ANS

      • $'$`alert(1)//

<<:  JavaScript Day27 - IIFE (立即函式)

>>:  [Day27] HTB Legacy

[DAY 16] Route 53 part 3

路由政策 routing policies 这些 routing policies 定义了 Rout...

Day12# interface

第 12 天要来介绍 interface 那麽话不多说,我们就进入正题吧 ─=≡Σ(((っ゚∀゚)っ...

Day29 - this&Object Prototypes Ch3 Objects - Review

Iteration for (var i=0; i<myArr.length; i++){}...

Day1 浅入浅出分散式储存

我是谁? 在某虚拟机公司担任分散式储存工程师,熟悉云端储存的相关知识 继去年的计算机网路主题 - 用...

Powershell 入门之 policy

今天我们来看看 powershell 的执行策略。 在默认情况下,你自己编写的脚本,或者从网上找的第...