最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - get name files of a mega.nz folder in nodejs - Stack Overflow

programmeradmin2浏览0评论

Request to api of mega.nz, parse url for get private key of folder, and try decode name of files from responde of request, by crypto of nodejs.

My code:

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

const link = '!gE5WkDpS!Yh6AQtYHPgi-rEkir_gAEw'
const api = ';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)
      }
    }
  }
})

My output is more broken text, i try change url and get more broken text:

�MzM�ݾ��+,�BW���p�K����

Request to api of mega.nz, parse url for get private key of folder, and try decode name of files from responde of request, by crypto of nodejs.

My code:

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

My output is more broken text, i try change url and get more broken text:

�MzM�ݾ��+,�BW���p�K����
Share Improve this question asked Jul 8, 2016 at 20:59 lobitolobito 1211 gold badge1 silver badge5 bronze badges 2
  • You're requesting info for the MBwjmCqR folder and trying to decrypt it using gE5WkDpS key. But seems it's not the only problem. – Gustavo Rodrigues Commented Jul 26, 2016 at 17:52
  • Found the problem: use the correct key (as I noted above) then use Buffer.alloc(0) and Buffer.alloc(16) instead of Buffer(0) and Buffer(16). – Gustavo Rodrigues Commented Dec 6, 2016 at 11:00
Add a ment  | 

1 Answer 1

Reset to default 1

There are two errors in your code:

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

You're requesting MBwjmCqR folder info but using gE5WkDpS key.

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

Using Buffer(size) will not initialize it, so the Buffer will contain data that was previously in memory. Use Buffer.alloc(size, 0) to initialize it with zeroes, which will match MEGA's implementation.

发布评论

评论列表(0)

  1. 暂无评论