获取nodejs中mega.nz文件夹的名称文件

时间:2016-07-08 20:59:52

标签: javascript node.js request cryptojs

请求mega.nz的api,解析url以获取文件夹的私钥,并尝试通过nodejs的crypto解码来自请求的响应的文件名。

我的代码:

Call MsgBox("Test", vbOkOnly)

我的输出文本更多,我尝试更改网址并获得更多损坏的文字:

const crypto = require('crypto')
const parse = require('url').parse
const request = require('request')

const link = 'https://mega.nz/#F!gE5WkDpS!Yh6AQtYHPgi-rEkir_gAEw'
const api = 'https://eu.api.mega.co.nz/cs?id=-1771463320&n=MBwjmCqR'

function d64 (s) {
  s += '=='.substr((2 - s.length * 3) & 3)
  s = s.replace(/-/g, '+').replace(/_/g, '/').replace(/,/g, '')
  return new Buffer(s, 'base64')
}

function from256to128 (s) {
  var o = new Buffer(16)
  for (var i = 0; i < 16; i++) {
    o[i] = s[i] ^ s[i + 16]
  }
  return o
}

function decodeName (at) {
  var end = at.length
  while (!at.readUInt8(end - 1)) end--
  return at.slice(0, end).toString()
}

const url = parse(link)
const split = url.hash.split('!')
const k0 = d64(split[2])

request({
  method: 'POST', uri: api, body: '[{"a":"f","c":1,"r":1,"ca":1}]'
}, (e, r, b) => {
  if (!e && r.statusCode === 200) {
    for (let file of JSON.parse(b)[0].f) {
      if (file.t === 1) {
        let k = d64(file.k.split(':')[1])
        let a = d64(file.a)
        let aes = crypto.createDecipheriv('aes-128-ecb', k0, Buffer(0))
        aes.setAutoPadding(false)
        let kdec = aes.update(k)
        aes = crypto.createDecipheriv('aes-128-cbc', kdec, Buffer(16))
        aes.setAutoPadding(false)
        let name = decodeName(aes.update(a))
        console.log(name)
      } else {
        let k = d64(file.k.split(':')[1])
        let a = d64(file.a)
        let aes = crypto.createDecipheriv('aes-128-ecb', k0, Buffer(0))
        aes.setAutoPadding(false)
        let k2dec = from256to128(aes.update(k))
        aes = crypto.createDecipheriv('aes-128-cbc', k2dec, Buffer(16))
        aes.setAutoPadding(false)
        let name = decodeName(aes.update(a))
        console.log(name)
      }
    }
  }
})

1 个答案:

答案 0 :(得分:1)

您的代码中有两个错误:

const link = 'https://mega.nz/#F!gE5WkDpS!Yh6AQtYHPgi-rEkir_gAEw'
const api = 'https://eu.api.mega.co.nz/cs?id=-1771463320&n=MBwjmCqR'

您正在请求MBwjmCqR文件夹信息,但使用gE5WkDpS密钥。

let aes = crypto.createDecipheriv('aes-128-ecb', k0, Buffer(0))
aes = crypto.createDecipheriv('aes-128-cbc', kdec, Buffer(16))

使用Buffer(size)不会初始化它,因此Buffer将包含以前在内存中的数据。使用Buffer.alloc(size, 0)用零初始化它,这将匹配MEGA的实现。