Advertisement
Th3-822

[rapidleech][d] nitroflare_com

Dec 12th, 2015
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.37 KB | None | 0 0
  1. <?php
  2.  
  3. if (!defined('RAPIDLEECH')) {
  4.     require_once('index.html');
  5.     exit;
  6. }
  7.  
  8. class nitroflare_com extends DownloadClass {
  9.     private $page, $cookie = array(), $pA, $DLRegexp = '@https?://s\d+\.nitroflare\.com/d/\w+/[^\s\'\"<>]+@i';
  10.     public function Download($link) {
  11.         if (!preg_match('@https?://(?:www\.)?nitroflare\.com/view/(\w{15,})(?:/[^\s<>\'\"/]+)?@i', $link, $fid)) html_error('Invalid link?.');
  12.         $this->fid = $fid[1];
  13.         $this->link = $fid[0];
  14.  
  15.         if (empty($_POST['step'])) {
  16.             $this->page = $this->GetPage($this->link, $this->cookie);
  17.             $this->followLinkRedirect();
  18.             is_present($this->page, 'This file has been removed due to inactivity.');
  19.             is_present($this->page, 'This file has been removed due to infringement of copyright.');
  20.             is_present($this->page, 'This file has been removed by its owner.');
  21.             $this->cookie = GetCookiesArr($this->page, $this->cookie);
  22.         }
  23.  
  24.         $this->pA = (empty($_REQUEST['premium_user']) || empty($_REQUEST['premium_pass']) ? false : true);
  25.         if (($_REQUEST['premium_acc'] == 'on' && ($this->pA || (!empty($GLOBALS['premium_acc']['nitroflare_com']['user']) && !empty($GLOBALS['premium_acc']['nitroflare_com']['pass']))))) {
  26.             $user = ($this->pA ? $_REQUEST['premium_user'] : $GLOBALS['premium_acc']['nitroflare_com']['user']);
  27.             $pass = ($this->pA ? $_REQUEST['premium_pass'] : $GLOBALS['premium_acc']['nitroflare_com']['pass']);
  28.             if ($this->pA && !empty($_POST['pA_encrypted'])) {
  29.                 $user = decrypt(urldecode($user));
  30.                 $pass = decrypt(urldecode($pass));
  31.                 unset($_POST['pA_encrypted']);
  32.             }
  33.             return $this->CookieLogin($user, $pass);
  34.         } else return $this->FreeDL();
  35.     }
  36.  
  37.     private function followLinkRedirect() {
  38.         if (!preg_match("@\nLocation: ((https?://(?:www\.)?nitroflare\.com)?/view/{$this->fid}/[^\s<>\'\"/]+)@i", $this->page, $redir)) return;
  39.         $redir = (empty($redir[2]) ? 'http://nitroflare.com'.$redir[1] : $redir[1]);
  40.  
  41.  
  42.         // Follow Redirect
  43.         $this->cookie = GetCookiesArr($this->page, $this->cookie);
  44.         $this->page = $this->GetPage($redir, $this->cookie);
  45.         // Update $this->link and $Referer
  46.         $this->link = $GLOBALS['Referer'] = $redir;
  47.     }
  48.  
  49.     private function FreeDL() {
  50.         if (empty($_POST['step']) || $_POST['step'] != '1') {
  51.             $page = $this->GetPage($this->link, $this->cookie, array('goToFreePage' => 'Submit'));
  52.             $this->cookie = GetCookiesArr($page, $this->cookie);
  53.  
  54.             $page = $this->GetPage($this->link.'/free', $this->cookie);
  55.             $this->cookie = GetCookiesArr($page, $this->cookie);
  56.  
  57.             if (!preg_match('@https?://(?:[^/]+\.)?(?:(?:google\.com/recaptcha/api)|(?:recaptcha\.net))/(?:(?:challenge)|(?:noscript))\?k=([\w\.\-]+)@i', $page, $pid)) html_error('CAPTCHA not found.');
  58.  
  59.             $post = array('method' => 'startTimer', 'fileId' => $this->fid);
  60.             $page = $this->GetPage('http://nitroflare.com/ajax/freeDownload.php', $this->cookie, $post, $this->link . "\r\nX-Requested-With: XMLHttpRequest");
  61.             list($ajaxHeader, $ajaxBody) = explode("\r\n\r\n", $page, 2);
  62.  
  63.             is_present($ajaxBody, 'This file is available with Premium only. Reason: this file is larger than 1024mb.');
  64.             is_present($ajaxBody, 'This file is available with Premium only. Reason: the file\'s owner disabled free downloads.');
  65.             if (preg_match('@Free downloading is not possible. You have to wait (\d+) \w+ to download your next file.@i', $ajaxBody, $err)) html_error($err[0]);
  66.  
  67.             $ajaxBody = trim($ajaxBody);
  68.             if ($ajaxBody != "\xEF\xBB\xBF1" && $ajaxBody != '1') html_error('Unexpected result at freeDownload request.');
  69.  
  70.             if (preg_match('@id="CountDownTimer"\s+data-timer="(\d+)"@i', $page, $cD))$this->CountDown($cD[1]);
  71.  
  72.             $data = $this->DefaultParamArr($this->link, $this->cookie, 1, 1);
  73.             $data['step'] = 1;
  74.             return $this->reCAPTCHA($pid[1], $data);
  75.         }
  76.  
  77.         $this->cookie = StrToCookies(decrypt(urldecode($_POST['cookie'])));
  78.         if (empty($_POST['recaptcha_response_field'])) html_error('You didn\'t enter the image verification code.');
  79.  
  80.         $post = array();
  81.         $post['method'] = 'fetchDownload';
  82.         $post['recaptcha_challenge_field'] = urlencode($_POST['recaptcha_challenge_field']);
  83.         $post['recaptcha_response_field'] = urlencode($_POST['recaptcha_response_field']);
  84.  
  85.         $page = $this->GetPage('http://nitroflare.com/ajax/freeDownload.php', $this->cookie, $post, $this->link . "\r\nX-Requested-With: XMLHttpRequest");
  86.         is_present($page, 'Free users have to wait ', 'Error: Skipped CountDown?');
  87.         is_present($page, 'The captcha wasn\'t entered correctly');
  88.  
  89.         if (!preg_match($this->DLRegexp, $page, $dl)) html_error('Download Link Not Found.');
  90.  
  91.         return $this->RedirectDownload($dl[0], urldecode(parse_url($dl[0], PHP_URL_PATH)));
  92.     }
  93.  
  94.     private function PremiumDL() {
  95.         $page = $this->GetPage($this->link, $this->cookie);
  96.         $this->cookie = GetCookiesArr($page, $this->cookie);
  97.  
  98.         if (!preg_match($this->DLRegexp, $page, $dl)) html_error('Download-Link Not Found.');
  99.  
  100.         return $this->RedirectDownload($dl[0], urldecode(parse_url($dl[0], PHP_URL_PATH)));
  101.     }
  102.  
  103.     private function Login($user, $pass) {
  104.         $purl = 'https://nitroflare.com/login';
  105.         if (!empty($_POST['step']) && $_POST['step'] == '1') {
  106.             $post = $this->verifyReCaptchav2();
  107.             $post['email'] = urlencode($user);
  108.             $post['password'] = urlencode($pass);
  109.             $post['login'] = 'Submit';
  110.             $post['token'] = urlencode($_POST['token']);
  111.  
  112.             $this->cookie = StrToCookies(decrypt(urldecode($_POST['cookie'])));
  113.             $page = $this->GetPage($purl, $this->cookie, $post, $purl);
  114.             $this->cookie = GetCookiesArr($page, $this->cookie);
  115.  
  116.             is_present($page, 'Account does not exist.', 'Login Error: Invalid or Inexistent Email.');
  117.             is_present($page, 'Wrong Email / Password', 'Login Error: Incorrect Email / Password.');
  118.             if (preg_match('@Please try again in \d+ minutes@i', $page, $err)) html_error("Login Error: {$err[0]}.");
  119.             is_present($page, 'CAPTCHA error', 'Login Error: Unknown Captcha Error.');
  120.         } else {
  121.             $post = array();
  122.             $post['email'] = urlencode($user);
  123.             $post['password'] = urlencode($pass);
  124.             $post['login'] = 'Submit';
  125.  
  126.             $page = $this->GetPage($purl, $this->cookie);
  127.             if (!($post['token'] = urlencode(cut_str($page, 'name="token" value="', '"')))) html_error('Login Error: Cannot find login token');
  128.             $this->cookie = GetCookiesArr($page, $this->cookie);
  129.  
  130.             $page = $this->GetPage($purl, $this->cookie, $post, $purl);
  131.             $this->cookie = GetCookiesArr($page, $this->cookie);
  132.  
  133.             is_present($page, 'Account does not exist.', 'Login Error: Invalid or Inexistent Email');
  134.             is_present($page, 'Wrong Email / Password', 'Login Error: Incorrect Email / Password');
  135.             if (preg_match('@Please try again in \d+ minutes@i', $page, $err)) html_error('Login Error: ' . $err[0]);
  136.  
  137.             if (!preg_match('@class="g-recaptcha" data-sitekey="([\w\.\-]+)"@i', $page, $cpid) && stripos($page, 'CAPTCHA error') !== false) html_error('reCAPTCHA2 Not Found.');
  138.  
  139.             if (!empty($cpid[1])) {
  140.                 // Captcha Required
  141.                 $data = $this->DefaultParamArr($this->link, $this->cookie, true, true);
  142.                 $data['step'] = '1';
  143.                 if (!($data['token'] = html_entity_decode(cut_str($page, 'name="token" value="', '"'), ENT_QUOTES))) html_error('Login Error: Cannot find login token.');
  144.                 $data['premium_acc'] = 'on';
  145.                 if ($this->pA) {
  146.                     $data['pA_encrypted'] = 'true';
  147.                     $data['premium_user'] = urlencode(encrypt($user));
  148.                     $data['premium_pass'] = urlencode(encrypt($pass));
  149.                 }
  150.                 return $this->reCAPTCHAv2($cpid[1], $data, 0, 'Login');
  151.             }
  152.         }
  153.  
  154.         if (empty($this->cookie['user'])) html_error('Login Error: Cannot find "user" cookie.');
  155.         $this->SaveCookies($user, $pass); // Update cookies file
  156.  
  157.         // Test Login
  158.         $page = $this->GetPage('https://nitroflare.com/member', $this->cookie, 0, $purl);
  159.         is_present($page, '>Inactive</', 'Login Error: Account isn\'t premium.');
  160.  
  161.         return $this->PremiumDL();
  162.     }
  163.  
  164.     private function IWillNameItLater($cookie, $decrypt=true) {
  165.         if (!is_array($cookie)) {
  166.             if (!empty($cookie)) return $decrypt ? decrypt(urldecode($cookie)) : urlencode(encrypt($cookie));
  167.             return '';
  168.         }
  169.         if (count($cookie) < 1) return $cookie;
  170.         $keys = array_keys($cookie);
  171.         $values = array_values($cookie);
  172.         $keys = $decrypt ? array_map('decrypt', array_map('urldecode', $keys)) : array_map('urlencode', array_map('encrypt', $keys));
  173.         $values = $decrypt ? array_map('decrypt', array_map('urldecode', $values)) : array_map('urlencode', array_map('encrypt', $values));
  174.         return array_combine($keys, $values);
  175.     }
  176.  
  177.     private function CookieLogin($user, $pass, $filename = 'nitroflare_dl.php') {
  178.         global $secretkey;
  179.         if (empty($user) || empty($pass)) html_error('Login Failed: User or Password is empty.');
  180.  
  181.         $filename = DOWNLOAD_DIR . basename($filename);
  182.         if (!file_exists($filename)/* || (!empty($_POST['step']) && $_POST['step'] == '1')*/) return $this->Login($user, $pass);
  183.  
  184.         $file = file($filename);
  185.         $savedcookies = unserialize($file[1]);
  186.         unset($file);
  187.  
  188.         $hash = hash('crc32b', $user.':'.$pass);
  189.         if (array_key_exists($hash, $savedcookies)) {
  190.             $_secretkey = $secretkey;
  191.             $secretkey = sha1($user.':'.$pass);
  192.             $testCookie = (decrypt(urldecode($savedcookies[$hash]['enc'])) == 'OK') ? $this->IWillNameItLater($savedcookies[$hash]['cookie']) : '';
  193.             $secretkey = $_secretkey;
  194.             if (empty($testCookie) || (is_array($testCookie) && count($testCookie) < 1)) return $this->Login($user, $pass);
  195.  
  196.             $page = $this->GetPage('https://nitroflare.com/member', $testCookie);
  197.             if (stripos($page, '>Logout</a>') === false) return $this->Login($user, $pass);
  198.             $this->cookie = GetCookiesArr($page, $testCookie); // Update cookies
  199.             $this->SaveCookies($user, $pass); // Update cookies file
  200.             is_present($page, '>Inactive</', 'Account isn\'t premium');
  201.             return $this->PremiumDL();
  202.         }
  203.         return $this->Login($user, $pass);
  204.     }
  205.  
  206.     private function SaveCookies($user, $pass, $filename = 'nitroflare_dl.php') {
  207.         global $secretkey;
  208.         $maxdays = 31; // Max days to keep cookies saved
  209.         $filename = DOWNLOAD_DIR . basename($filename);
  210.         if (file_exists($filename)) {
  211.             $file = file($filename);
  212.             $savedcookies = unserialize($file[1]);
  213.             unset($file);
  214.  
  215.             // Remove old cookies
  216.             foreach ($savedcookies as $k => $v) if (time() - $v['time'] >= ($maxdays * 24 * 60 * 60)) unset($savedcookies[$k]);
  217.         } else $savedcookies = array();
  218.         $hash = hash('crc32b', $user.':'.$pass);
  219.         $_secretkey = $secretkey;
  220.         $secretkey = sha1($user.':'.$pass);
  221.         $savedcookies[$hash] = array('time' => time(), 'enc' => urlencode(encrypt('OK')), 'cookie' => $this->IWillNameItLater($this->cookie, false));
  222.         $secretkey = $_secretkey;
  223.  
  224.         file_put_contents($filename, "<?php exit(); ?>\r\n" . serialize($savedcookies), LOCK_EX);
  225.     }
  226.  
  227.     // Special Function Called by verifyReCaptchav2 When Captcha Is Incorrect, To Allow Retry. - Required
  228.     protected function retryReCaptchav2() {
  229.         $data = $this->DefaultParamArr($this->link);
  230.         $data['cookie'] = (!empty($_POST['cookie']) ? $_POST['cookie'] : '');
  231.         $data['step'] = '1';
  232.         $data['token'] = (!empty($_POST['cookie']) ? $_POST['token'] : '');
  233.         $data['premium_acc'] = 'on';
  234.         if ($this->pA && !empty($_GET['pA_encrypted']) && !empty($_REQUEST['premium_user']) && !empty($_REQUEST['premium_pass'])) {
  235.             $data['pA_encrypted'] = 'true';
  236.             $data['premium_user'] = $_REQUEST['premium_user'];
  237.             $data['premium_pass'] = $_REQUEST['premium_pass'];
  238.         }
  239.         return $this->reCAPTCHAv2($_POST['recaptcha2_public_key'], $data, 0, 'Retry Login');
  240.     }
  241. }
  242.  
  243. //[18-10-2015] Written by Th3-822.
  244. //[13-12-2015] Fixed FreeDL CountDown. - Th3-822
  245.  
  246. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement