zoukankan      html  css  js  c++  java
  • IDF-CTF-简单的js加密 writeup

    题目链接: http://ctf.idf.cn/index.php?g=game&m=article&a=index&id=43

    知识点:js语法

    这里这里→ http://ctf.idf.cn/game/web/43/index.php

    思路:

    查看网页源码,阅读js代码,发现函数实现了加密方法,但是解密的方法并没有实现,根据加密的部分我们容易写出解密的方法,如下:

    <html>
    <body>
    
    <script>
    /**
     * Pseudo md5 hash function
     * @param {string} string
     * @param {string} method The function method, can be 'ENCRYPT' or 'DECRYPT'
     * @return {string}
     */
    function pseudoHash(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
        var output = '';
        // Algorithm to encrypt
        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
        return output;
      } else if ('DECRYPT' == method) {
        // Algorithm to encrypt
        // Variable for output string
        var output = '';
        var charCode = '';
        var hexCode = 0;
        for(var i=0; i<string.length; i+=2){
            if(string[i] == '0'){
                charCode = string[i+1];
            }
            else{
                charCode = string[i]+string[i+1];
            }
    
            hexCode = parseInt(charCode, 16)
            hexCode = 255 - hexCode
            if(hexCode > 128){
                hexCode -= 128
            }
            else if(hexCode < 128){
                hexCode += 128
            }
            output += String.fromCharCode(hexCode);
        }
        // Return output
        return output;
      }
    }
    document.write(pseudoHash('46191d4b494a4e1c4f4a1d4d1a1b484f191d1e4a1e191a4f1d4f4c461e4a4a4f', 'DECRYPT'));
    </script>
    
    </body>
    </html>
    

    解密的结果为“9fb4651c05b2ed70fba5afe0b039a550”,将该值粘入原网页的密码输入框,走你,得到答案“wctf{jS_decRypt__Eaaasy}”

  • 相关阅读:
    计算机网络的三种通讯模式(单播,广播,组播)
    java字符串面试题
    java使用纯命令行打包项目
    java字节码的工具(含IDEA插件)
    Spring配置之context:annotation与、component-scan以及annotation-driven
    Java ThreadLocal的使用案例
    对称平方数(to_string函数,stoi函数真香)
    字符串最后一位长度
    缺失的括号
    数三角形
  • 原文地址:https://www.cnblogs.com/renzongxian/p/4662906.html
Copyright © 2011-2022 走看看