Yawin

index.php

Apr 19th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.70 KB | None | 0 0
  1. <?php
  2.   function str_to_a32($b)
  3.   {
  4.     // Add padding, we need a string with a length multiple of 4
  5.       $b = str_pad($b, 4 * ceil(strlen($b) / 4), "\0");
  6.       return array_values(unpack('N*', $b));
  7.   }
  8.  
  9.   function base64url_decode($data)
  10.   {
  11.     if (($s = (2 - strlen($data) * 3) % 4) < 2) $data .= substr(',,', $s);
  12.     return base64_decode(strtr($data, '-_,', '+/='));
  13.   }
  14.  
  15.   function a32_to_str($hex)
  16.   {
  17.     return call_user_func_array('pack', array_merge(array('N*'), $hex));
  18.   }
  19.  
  20.   function aes128_cbc_decrypt($raw, $key)
  21.   {
  22.     $ivlen = openssl_cipher_iv_length($cipher="AES-128-CBC");
  23.     $iv = str_repeat("\0",$ivlen);
  24.     return openssl_decrypt($raw,$cipher, $key,OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
  25.   }
  26.  
  27.   function aes128_cbc_decrypt1($raw, $key,$iv)
  28.   {
  29.     $ivlen = openssl_cipher_iv_length($cipher="AES-128-CTR");
  30.     return openssl_decrypt($raw,$cipher, $key,OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
  31.   }
  32.  
  33.   function mega($path,$paramm)
  34.   {
  35.     $curl = curl_init('https://g.api.mega.co.nz/cs');
  36.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  37.     curl_setopt($curl, CURLOPT_HEADER, 0);
  38.     if($paramm)
  39.     {
  40.       curl_setopt($curl, CURLOPT_POST, 1);
  41.       curl_setopt($curl, CURLOPT_POSTFIELDS, $paramm);
  42.     }
  43.  
  44.     $response = curl_exec($curl);
  45.     $code = curl_getinfo($curl);
  46.     curl_close($curl);
  47.     return json_decode($response);
  48.   }
  49.  
  50.   $jsondata = json_decode(file_get_contents("./data.json"));
  51.  
  52.   if(isset($_GET['pic']) && $_GET['pic'] != "" && array_key_exists($_GET['pic'], $jsondata->pics))
  53.   {
  54.     $data = explode("/",$jsondata->pics->{$_GET['pic']});
  55.     $pic = explode("#", $data[count($data)-1]);
  56.  
  57.     $param = [];
  58.     $param['a'] = 'g';
  59.     $param['g'] = '1';
  60.     $param['ssl'] = '2';
  61.     $param['v'] = '2';
  62.     $param['p'] = $pic[0];
  63.  
  64.     $key_plain = base64url_decode($pic[1]);
  65.     $key = str_to_a32($key_plain);
  66.  
  67.     $m = mega('',json_encode([$param]));
  68.     $enc = $m[0]->at;
  69.     $enc = base64url_decode($enc);
  70.  
  71.     $iv = array($key[4], $key[5], 0, 0);
  72.     if (count($key) != 4)
  73.     {
  74.       $key = array($key[0] ^ $key[4], $key[1] ^ $key[5], $key[2] ^ $key[6], $key[3] ^ $key[7]);
  75.     }
  76.  
  77.     $url = $m[0]->g;
  78.     $curl = curl_init();
  79.     curl_setopt($curl, CURLOPT_URL, $url);
  80.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  81.     curl_setopt($curl, CURLOPT_HEADER, false);
  82.     $enc = curl_exec($curl);
  83.     curl_close($curl);
  84.  
  85.     $iv = a32_to_str($iv);
  86.     $raw = aes128_cbc_decrypt1($enc,a32_to_str($key),$iv);
  87.   }
  88.   else
  89.   {
  90.     $raw = "";
  91.   }
  92.  
  93.   //Si no hemos obtenido ninguna imagen
  94.     if($raw == "")
  95.     {
  96.       //Cargamos la imagen
  97.         $source = imagecreatefromjpeg("placeholder.jpg");
  98.     }
  99.   //Si hemos obtenido una imagen
  100.     else
  101.     {
  102.       //Convertimos la imagen en un objeto GD
  103.         $source = imagecreatefromstring($raw);
  104.     }
  105.  
  106.   //Obtenemos las dimensiones de la imagen
  107.     $width = imagesx($source);
  108.     $height = imagesy($source);
  109.  
  110.   //Cargamos el tamaño
  111.     $size = $jsondata->default;
  112.     if(isset($_GET['size']) && array_key_exists($_GET['size'], $jsondata->sizes))
  113.     {
  114.       $size = $_GET['size'];
  115.     }
  116.  
  117.   //Establecemos las nuevas dimensiones
  118.     $newwidth = $jsondata->sizes->{$size}->width;
  119.     $newheight = $jsondata->sizes->{$size}->height;
  120.  
  121.   //Instanciamos una imagen vacía con las nuevas dimensiones
  122.     $thumb = imagecreatetruecolor($newwidth, $newheight);
  123.  
  124.   // Copiamos resizeando la imagen en la nueva instancia
  125.     imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  126.  
  127.   // Cabecera html que indica que mandamos imagen
  128.     header('Content-Type: image/jpeg');
  129.  
  130.   // Mostramos la imagen
  131.     imagejpeg($thumb);
  132. ?>
  133.  
Add Comment
Please, Sign In to add comment