No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mega-dl.sh 875B

123456789101112131415161718192021222324
  1. #!/bin/bash
  2. if [[ $# != 2 ]]; then
  3. echo "usage: mega-dl.sh <url> <output>"
  4. exit 1
  5. fi
  6. url="$1"
  7. enc_file="$2.enc"
  8. out_file="$2"
  9. id=`echo $url | awk -F '!' '{print $2}'`
  10. key=`echo $url | awk -F '!' '{print $3}' | sed -e 's/-/+/g' -e 's/_/\//g' -e 's/,//g'`
  11. b64_hex_key=`echo -n $key | base64 --decode --ignore-garbage 2> /dev/null | xxd -p | tr -d '\n'`
  12. key[0]=$(( 0x${b64_hex_key:00:16} ^ 0x${b64_hex_key:32:16} ))
  13. key[1]=$(( 0x${b64_hex_key:16:16} ^ 0x${b64_hex_key:48:16} ))
  14. key=`printf "%x" ${key[*]}`
  15. iv="${b64_hex_key:32:16}0000000000000000"
  16. response=`curl --silent --request POST --data-binary '[{"a":"g","g":1,"p":"'$id'"}]' https://eu.api.mega.co.nz/cs`
  17. echo "$response"
  18. new_url=`echo "$response" | awk -F '"' '{print $10}'`
  19. curl --output "$enc_file" "$new_url"
  20. openssl enc -d -aes-128-ctr -K $key -iv $iv -in "$enc_file" -out "$out_file"
  21. rm -f "$enc_file"