Advertisement
Guest User

megatools is shit so...

a guest
Jul 24th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.42 KB | None | 0 0
  1. #!/bin/bash
  2. id=$( echo "$1"| awk -F '!' '{print $2}')
  3. key=$(echo "$1"| awk -F '!' '{print $3}'|tr _- /+|tr -d ,)
  4.  
  5. if ! (test "$id"&&test "$key");then
  6.     echo "usage example:"
  7.     echo "$0 'https://mega.nz/#!gx5giRLT!y-fuezB5pFWwZ8tGRMNdLI_QeLWQK7b1nsHkIAAHCkA'"
  8.     exit 1
  9. fi
  10.  
  11. key64=$(echo -n "$key"|base64 -di 2>/dev/null|xxd -p|tr -d '\n')
  12. (( key[0] = 0x${key64:00:16} ^ 0x${key64:32:16} ))
  13. (( key[1] = 0x${key64:16:16} ^ 0x${key64:48:16} ))
  14. key=$(printf "%016x" ${key[*]})
  15. iv=${key64:32:16}0000000000000000
  16.  
  17. json=$(curl -sX POST --data-binary '[{"a":"g","g":1,"p":"'$id'"}]' https://eu.api.mega.co.nz/cs)
  18. if ((${#json} < 20));then
  19.     echo "got this instead of json: $json"
  20.     exit 1
  21. fi
  22. # file url:
  23. url1=$(echo "$json"|python -c "import json,sys;sys.stdout.write(json.loads(sys.stdin.read())[0]['g'])")
  24.  
  25. filenamejson=$(echo "$json"|\
  26.   python -c "import json,sys;sys.stdout.write(json.loads(sys.stdin.read())[0]['at'])"|\
  27.   tr _- /+|tr -d ,|base64 -di 2>/dev/null|\
  28.   openssl enc -d -aes-128-cbc -K $key -iv 0 -nopad)
  29. # the output seems to begin with "MEGA", followed by json, thus the sed
  30. filename=$(echo "$filenamejson"|sed 's/^.[^{]*{/{/'|\
  31.   python -c "import json,sys;sys.stdout.write(json.loads(sys.stdin.read())['n'])")
  32.  
  33. if ! test -e "$filename";then
  34.     echo "saving to: $filename"
  35.     curl "$url1"|openssl enc -d -aes-128-ctr -K $key -iv $iv -out "$filename"
  36. else
  37.     echo "already exists: $filename"
  38. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement