合天网安实验室CTF-Web100-Give Me Flag

合天网安实验室CTF-Web100-Give Me Flag

题目描述

  哎,不小心把代码弄乱惹

相关附件

  web100.zip
gmf

参考解题步骤

1、下载附件打开后是一段JavaScript代码,但看起来被混淆了
源文件是没有换行的,我这里手动换行以便观察
code

2、试了一下直接翻译,比如很容易看出getEleById中的 = ment,但后面的就很难判断了。于是调整思路,直接用Chrome跑一下看看。(注意要将上一步的手动换行还原)
chrome
调试界面的代码
chrome
还是不清楚,但可以看出大体的代码逻辑:
  1) _(下划线)被赋值为第一行的整个字符串
  2) 第二行的for循环是对_(下划线)中的字符串进行处理
  3) 使用eval()函数执行_(下划线)中的字符串
  注:eval(string) 函数可计算某个字符串,并执行其中的的 JavaScript 代码。

3、使用alert()显示for循环处理后的_(下划线)中的字符串
alert
网页显示
复制到VSCode格式化一下

<script>
    function $(){
        var e = document.getElementById("c").value;
        if (e.length == 16)
            if (e.match(/^be0f23/) != null) 
                if (e.match(/233ac/) != null)
                    if (e.match(/e98aa$/) != null)
                        if (e.match(/c7be9/) != null){
                            var t = ["fl", "s_a", "i", "e}"];
                            var n = ["a", "_h0l", "n"];
                            var r = ["g{", "e", "_0"];
                            var i = ["it'", "_", "n"];
                            var s = [t, n, r, i];
                            for (var o = 0; o < 13; ++o){
                                document.write(s[o % 4][0]);
                                s[o % 4].splice(0, 1)
                            }
                        }
    }
    document.write('<input id="c"><button οnclick=$()>Ok</button>');
    delete _
</script>

4、可以看出最内层if里的代码运行结果即为答案
  flag{it’s_a_h0le_in_0ne}
flag

5、提交it's_a_h0le_in_0ne即可通过
通过

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章