CTF-问鼎杯-WEB之请帮忙找出秘密

                      **问鼎杯-WEB之请帮忙找出秘密**

对于这道题,我还是有点心得的。来和大家分享一下!!!
老样子,进网页扒源码。不过这回这个有点特殊,不是一下子能够弄出来的,重点在于那个js脚本,下面我来详细说明一下。

  1. 步骤一:将整个页面复制下来,观察之后发现这个js脚本不是一个正常的脚本。其实这是一个加密后的脚本,解密的代码我附在下面了。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JS解密</title>
</head>
<body>
    <script>   
    a=62;   
    function encode() 
    {   
     var code = document.getElementById('code').value;   
     code = code.replace(/[ ]+/g, '');   
     code = code.replace(/'/g, "\'");   
     var tmp = code.match(/(w+)/g);   
     tmp.sort();   
     var dict = [];   
     var i, t = '';   
     for(var i=0; i<tmp.length; i++) 
     {   
         if(tmp[i] != t) dict.push(t = tmp[i]);   
     }   
     var len = dict.length;   
     var ch;   
     for(i=0; i<len; i++) 
     {   
         ch = num(i);   
         code = code.replace(new RegExp('\b'+dict[i]+'\b','g'), ch);   
     if(ch == dict[i]) dict[i] = '';   
     }   
     document.getElementById('code').value = "eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}("   
     + "'"+code+"',"+a+","+len+",'"+ dict.join('|')+"'.split('|'),0,{}))";   
    }  

    function num(c)
    {   
     return(c<a?'':num(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36));   
    }  

    function run()
    {   
     eval(document.getElementById('code').value);   
    }  
    function decode()
    {   
     var code = document.getElementById('code').value;   
     code2 = code.replace(/^eval/, '');   
     //alert(code);  
     document.getElementById('code').value = eval(code2);   
    }   
    </script>  
    <textarea id=code cols=80 rows=20> 
    </textarea>  
    <input type=button onclick=encode() value=编码>   
    <input type=button onclick=run() value=执行>   
    <input type=button onclick=decode() value=解码>  
</body>
</html>

2.步骤2:新建一个.txt文档,将下面的代码复制进去,然后改格式为.html。将加密后的js代码复制进去。 注意:代码复制进去的时候,首行不能留空格,意思就是将第一行前面的空格全部消去。要不然解密不出来。
3.步骤3:解密出来之后应该是下面这样的代码。

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>simple js decode</title>
</head>
<body>
    <form id="levelQuest" method="post">
    <p>
        password:</p>
    <p>
        <input id="password" class="input" name="password" type="password">
        <input class="button" value="Go" type="submit">
    </p>
    </form>
    <p id="errorMessage">
    </p>
    <script>
        function pseudoHash(string, method)
         {
             if (!('ENCRYPT' == method || 'DECRYPT' == method)) 
            {
                method = 'ENCRYPT'
            }
            if ('ENCRYPT' == method) 
            {
                var output = '';
                for(var x = 0,y=string.length,charCode, hexCode; x < y; ++x)
                 {
                    charCode = string.charCodeAt(x);
                    if (128 > charCode) 
                    {
                        charCode += 128
                    }
                     else if (127 < charCode)
                     {
                        charCode -= 128
                     }
                    charCode = 255 - charCode;
                    hexCode = charCode.toString(16);
                    if (2 > hexCode.length) 
                    {
                        hexCode = '0' + hexCode
                    }
                    output += hexCode
                }
                return output
            } 
            else if('DECRYPT' == method)
             {
                return string
            }
        }
        document.getElementById('password').value = pseudoHash('1a4d494e4b47461e1d464b4d4b4d461e49494f4f1c4e1c4b4e4d4e1e1c4e4b1b', 'DECRYPT');
  </script>
    <p id="tip">
    </p>
</body>
</html>

估计这样的代码对新手来说还是有点看不懂。所以本人特意将他的c#代码写了出来:

public string pseudoHash(string str, string method)  
    {  
        // Default method is encryption  
        if (!("ENCRYPT" == method || "DECRYPT" == method))  
        {  
            method = "ENCRYPT";  
        }  
        // Run algorithm with the right method  
        if ("ENCRYPT" == method)  
        {  
            // Variable for output string  
            string output = "";  
            // Algorithm to encrypt  
            char[] ch = str.ToCharArray();  
            char charCode;  
            string hexCode;  
            for (int x = 0, y = str.Length; x < y; ++x)  
            {  
                charCode = ch[x];  
                if (charCode < 128)  
                {  
                    charCode = (char)(charCode + 128);  
                }  
                else if (charCode > 127)  
                {  
                    charCode = (char)(charCode - 128);  
                }  
                charCode = (char)(255 - charCode);  
                hexCode = Convert.ToString(charCode,16);  
                if (hexCode.Length < 2)  
                {  
                    hexCode = '0' + hexCode;  
                }  
                output += hexCode;  
            }  
            // Return output  
            return output;  
        }  
        else if ("DECRYPT" == method)  
        {  
            return str;  
        }  
        return "";  
    }  
这样似乎大功告成,其实这只是加密的js代码,你需要写出解密的代码,解密的c#代码如下:
    public string getIt(string str)  
    {  
        char[] ch = str.ToCharArray();  
        string s = "";  
        for(int i = 0; i < str.Length - 1; i+=2)  
        {  
            s += (char)(255-Convert.ToInt32(ch[i] + "" + ch[i + 1], 16)-128) + "";  
        }  
        return s;  
    }  

这是一个方法,自己去调用它,解出来的字符串为“e261489ab942429a6600c1c4121ac14d”,这是一个32位的字符串,试用md5解密,
http://cmd5.com/,解出来得:7415。
最后遇到麻烦了:将7415填上去,系统显示答案错误。嗨,请有心人帮帮忙,告诉我怎么回事!!!
由于第一次写博客,不周之处,敬请谅解

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值