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}”

转载于:https://www.cnblogs.com/renzongxian/p/4662906.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值