Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- id=$( echo "$1"| awk -F '!' '{print $2}')
- key=$(echo "$1"| awk -F '!' '{print $3}'|tr _- /+|tr -d ,)
- if ! (test "$id"&&test "$key");then
- echo "usage example:"
- echo "$0 'https://mega.nz/#!gx5giRLT!y-fuezB5pFWwZ8tGRMNdLI_QeLWQK7b1nsHkIAAHCkA'"
- exit 1
- fi
- key64=$(echo -n "$key"|base64 -di 2>/dev/null|xxd -p|tr -d '\n')
- (( key[0] = 0x${key64:00:16} ^ 0x${key64:32:16} ))
- (( key[1] = 0x${key64:16:16} ^ 0x${key64:48:16} ))
- key=$(printf "%016x" ${key[*]})
- iv=${key64:32:16}0000000000000000
- json=$(curl -sX POST --data-binary '[{"a":"g","g":1,"p":"'$id'"}]' https://eu.api.mega.co.nz/cs)
- if ((${#json} < 20));then
- echo "got this instead of json: $json"
- exit 1
- fi
- # file url:
- url1=$(echo "$json"|python -c "import json,sys;sys.stdout.write(json.loads(sys.stdin.read())[0]['g'])")
- filenamejson=$(echo "$json"|\
- python -c "import json,sys;sys.stdout.write(json.loads(sys.stdin.read())[0]['at'])"|\
- tr _- /+|tr -d ,|base64 -di 2>/dev/null|\
- openssl enc -d -aes-128-cbc -K $key -iv 0 -nopad)
- # the output seems to begin with "MEGA", followed by json, thus the sed
- filename=$(echo "$filenamejson"|sed 's/^.[^{]*{/{/'|\
- python -c "import json,sys;sys.stdout.write(json.loads(sys.stdin.read())['n'])")
- if ! test -e "$filename";then
- echo "saving to: $filename"
- curl "$url1"|openssl enc -d -aes-128-ctr -K $key -iv $iv -out "$filename"
- else
- echo "already exists: $filename"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement