View difference between Paste ID: gqHsEiH9 and dj1KcKKS
SHOW: | | - or go back to the newest paste.
1
#!/bin/bash
2
 
3
url=$1
4
5
# get id and key from url
6
id=`echo $url | awk -F '!' '{print $2}'`
7
key=`echo $url | awk -F '!' '{print $3}' | sed -e 's/-/+/g' -e 's/_/\//g' -e 's/,//g'`
8
9
# decode key
10
b64_hex_key=`echo -n $key | base64 --decode --ignore-garbage 2> /dev/null | xxd -p | tr -d '\n'`
11
key[0]=$(( 0x${b64_hex_key:00:16} ^ 0x${b64_hex_key:32:16} ))
12
key[1]=$(( 0x${b64_hex_key:16:16} ^ 0x${b64_hex_key:48:16} ))
13
key=`printf "%016x" ${key[*]}`
14
iv="${b64_hex_key:32:16}0000000000000000"
15
16
# send the request
17
json_data=`curl --silent --request POST --data-binary '[{"a":"g","g":1,"p":"'$id'"}]' https://eu.api.mega.co.nz/cs`
18
19
# get the download url
20
new_url=`echo $json_data | awk -F '"' '{print $10}'`
21
22
# get the file name, have to do a lot of weird things because openssl is tricky
23
tmp=`echo $json_data | awk -F '"' '{print $6}' | sed -e 's/-/+/g' -e 's/_/\//g' -e 's/,//g' | base64 --decode --ignore-garbage 2> /dev/null | xxd -p | tr -d '\n' > enc_attr.mdtmp`
24
tmp=`xxd -p -r enc_attr.mdtmp > enc_attr2.mdtmp`
25
openssl enc -d -aes-128-cbc -K $key -iv 0 -nopad -in enc_attr2.mdtmp -out dec_attr.mdtmp
26
file_name=`cat dec_attr.mdtmp | awk -F '"' '{print $4}'`
27
rm -f *.mdtmp
28
29
# download the file and decrypt it
30
enc_file=${file_name}.enc
31
32
curl --output $enc_file $new_url
33
openssl enc -d -aes-128-ctr -K $key -iv $iv -in $enc_file -out $file_name
34
rm -f $enc_file