Ejemplo n.º 1
0
 public static function decryptLink($link, $ignore_exceptions = false)
 {
     if (preg_match('/^.*?!(?P<data>[0-9a-z_-]+)!(?P<hash>[0-9a-f]+)/i', trim(str_replace('/', '', $link)), $match)) {
         if (hash_hmac(self::HMAC_ALGO, $match['data'], md5(MASTER_KEY)) != $match['hash']) {
             throw new Exception_MegaCrypterLinkException(self::LINK_ERROR);
         } else {
             if (!$ignore_exceptions && BLACKLIST_LEVEL >= self::BLACKLIST_LEVEL_MC && self::isBlacklistedLink($match['data'])) {
                 throw new Exception_MegaCrypterLinkException(self::BLACKLISTED_LINK);
             } else {
                 list($secret, $file_id, $file_key, $pass, $extra, $auth) = explode(self::SEPARATOR, gzinflate(Utils_CryptTools::aesCbcDecrypt(Utils_MiscTools::urlBase64Decode($match['data']), Utils_MiscTools::hex2bin(MASTER_KEY), md5(MASTER_KEY, true))));
                 if (!$ignore_exceptions && BLACKLIST_LEVEL == self::BLACKLIST_LEVEL_MEGA && self::isBlacklistedLink($file_id)) {
                     throw new Exception_MegaCrypterLinkException(self::BLACKLISTED_LINK);
                 } else {
                     if ($extra) {
                         list($extra_info, $hide_name, $expire, $referer, $email, $zombie, $no_expire_token) = explode(self::SEPARATOR_EXTRA, $extra);
                         if (!$ignore_exceptions && !empty($expire) && time() >= $expire) {
                             throw new Exception_MegaCrypterLinkException(self::EXPIRED_LINK);
                         }
                         if (!empty($zombie) && $zombie != $_SERVER['REMOTE_ADDR']) {
                             throw new Exception_MegaCrypterLinkException(self::LINK_ERROR);
                         }
                     }
                     return ['file_id' => $file_id, 'file_key' => $file_key, 'extra_info' => !empty($extra_info) ? base64_decode($extra_info) : false, 'pass' => !empty($pass) ? $pass : false, 'auth' => !empty($auth) ? base64_decode($auth) : false, 'hide_name' => !empty($hide_name), 'expire' => !empty($expire) ? $expire : false, 'no_expire_token' => !empty($no_expire_token), 'referer' => !empty($referer) ? base64_decode($referer) : false, 'email' => !empty($email) ? base64_decode($email) : false, 'zombie' => !empty($zombie) ? $zombie : false, 'secret' => $secret];
                 }
             }
         }
     } else {
         throw new Exception_MegaCrypterLinkException(self::LINK_ERROR);
     }
 }
Ejemplo n.º 2
0
 public static function decryptMegaDownloaderLinks($data)
 {
     return preg_replace_callback('/mega\\:\\/\\/(?P<folder>f)?(?P<enc>enc\\d*?)\\?(?P<linkdata>[\\da-z_,-]*?)(?=https?\\:|mega\\:|[^\\da-z_,-]|$)/i', function ($match) {
         $key = ['enc' => '6B316F36416C2D316B7A3F217A30357958585858585858585858585858585858', 'enc2' => 'ED1F4C200B35139806B260563B3D3876F011B4750F3A1A4A5EFD0BBE67554B44'];
         $iv = '79F10A01844A0B27FF5B2D4E0ED3163E';
         return Utils_MegaApi::MEGA_HOST . '/#' . strtoupper($match['folder']) . Utils_CryptTools::aesCbcDecrypt(Utils_MiscTools::urlBase64Decode($match['linkdata']), Utils_MiscTools::hex2bin($key[$match['enc']]), Utils_MiscTools::hex2bin($iv), true);
     }, $data);
 }
Ejemplo n.º 3
0
 private function _actionInfo($post_data)
 {
     $dec_link = $this->_decryptLink($post_data->link);
     $ma = new Utils_MegaApi(MEGA_API_KEY);
     $file_info = $ma->getFileInfo($dec_link['file_id'], $dec_link['file_key']);
     $data = ['name' => $dec_link['hide_name'] ? Utils_MiscTools::hideFileName($file_info['name'], ($dec_link['zombie'] ? $dec_link['zombie'] : null) . base64_decode(GENERIC_PASSWORD)) : $file_info['name'], 'path' => isset($file_info['path']) ? $file_info['path'] : false, 'size' => $file_info['size'], 'key' => isset($file_info['key']) ? $file_info['key'] : $dec_link['file_key'], 'extra' => $dec_link['extra_info'], 'expire' => $dec_link['expire'] ? $dec_link['expire'] . '#' . ($dec_link['no_expire_token'] ? base64_encode(hash('sha256', base64_decode($dec_link['secret']), true)) : self::NO_EXP_TOK_NOT_ALLOWED) : false];
     if ($dec_link['pass']) {
         list($iterations, $pass, $pass_salt) = explode('#', $dec_link['pass']);
         $b64p = base64_decode($pass);
         $iv = openssl_random_pseudo_bytes(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
         $data['name'] = $this->_encryptApiField($data['name'], $b64p, $iv);
         if ($data['path']) {
             $data['path'] = $this->_encryptApiField($data['path'], $b64p, $iv);
         }
         $data['key'] = $this->_encryptApiField(Utils_MiscTools::urlBase64Decode($data['key']), $b64p, $iv);
         if ($data['extra']) {
             $data['extra'] = $this->_encryptApiField($data['extra'], $b64p, $iv);
         }
         $data['pass'] = $iterations . '#' . base64_encode(hash_hmac('sha256', $b64p, $iv, true)) . '#' . $pass_salt . '#' . base64_encode($iv);
     } else {
         $data['pass'] = false;
     }
     return $data;
 }
Ejemplo n.º 4
0
 private function _urlBase64KeyDecode($key)
 {
     $key_bin = Utils_MiscTools::urlBase64Decode($key);
     if (strlen($key_bin) < self::FILE_KEY_BYTE_LENGTH) {
         return substr($key_bin, 0, self::FOLDER_KEY_BYTE_LENGTH);
     } else {
         $key_i32a = Utils_MiscTools::bin2i32a(substr($key_bin, 0, self::FILE_KEY_BYTE_LENGTH));
         return Utils_MiscTools::i32a2Bin([$key_i32a[0] ^ $key_i32a[4], $key_i32a[1] ^ $key_i32a[5], $key_i32a[2] ^ $key_i32a[6], $key_i32a[3] ^ $key_i32a[7]]);
     }
 }