Th3-822

[rapidleech][d] keep2share_cc

Feb 16th, 2014
1,237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.00 KB | None | 0 0
  1. <?php
  2.  
  3. if (!defined('RAPIDLEECH')) {
  4.     require_once('index.html');
  5.     exit;
  6. }
  7.  
  8. class keep2share_cc extends DownloadClass {
  9.     private $page, $cookie = array('use_new_design' => 0), $pA;
  10.     public function Download($link) {
  11.         $this->LnkRegexp = '@https?://(?:www\.)?(keep2share\.(?:cc|com)|k(?:eep)?2s\.cc)/file(?:/info)?/(\w+)@i';
  12.         $this->RDRegexp = '@/file/url.html\?file=\w+@i';
  13.         $this->DLRegexp = '@https?://(?:slow|prx)-\d+\.(?:keep2share\.(?:cc|com)|k(?:eep)?2s\.cc)/[^\s\'\"<>]+@i';
  14.  
  15.         if (!preg_match($this->LnkRegexp, $link, $fid)) html_error('Invalid link?.');
  16.         $this->domain = $fid[1];
  17.         $this->link = $GLOBALS['Referer'] = 'https://'.$fid[1].'/file/'.$fid[2];
  18.  
  19.         if (empty($_POST['step'])) {
  20.             $this->page = $this->GetPage($this->link, $this->cookie);
  21.             if (preg_match($this->LnkRegexp, $this->page, $fid)) {
  22.                 $this->domain = $fid[1];
  23.                 $this->link = $GLOBALS['Referer'] = 'https://'.$fid[1].'/file/'.$fid[2];
  24.                 $this->cookie = GetCookiesArr($this->page, $this->cookie);
  25.                 $this->page = $this->GetPage($this->link, $this->cookie);
  26.             }
  27.             is_present($this->page, 'File not found or deleted');
  28.             $this->cookie = GetCookiesArr($this->page, $this->cookie);
  29.         }
  30.  
  31.         $this->pA = (empty($_REQUEST['premium_user']) || empty($_REQUEST['premium_pass']) ? false : true);
  32.         if (($_REQUEST['premium_acc'] == 'on' && ($this->pA || (!empty($GLOBALS['premium_acc']['keep2share_cc']['user']) && !empty($GLOBALS['premium_acc']['keep2share_cc']['pass']))))) {
  33.             $user = ($this->pA ? $_REQUEST['premium_user'] : $GLOBALS['premium_acc']['keep2share_cc']['user']);
  34.             $pass = ($this->pA ? $_REQUEST['premium_pass'] : $GLOBALS['premium_acc']['keep2share_cc']['pass']);
  35.             if ($this->pA && !empty($_POST['pA_encrypted'])) {
  36.                 $user = decrypt(urldecode($user));
  37.                 $pass = decrypt(urldecode($pass));
  38.                 unset($_POST['pA_encrypted']);
  39.             }
  40.             return $this->CookieLogin($user, $pass);
  41.         } else return $this->FreeDL();
  42.     }
  43.  
  44.     private function FreeDL() {
  45.         if (empty($_POST['step']) || !in_array($_POST['step'], array('1', '2'))) {
  46.             is_present($this->page, 'This file is available<br>only for premium members.', 'This file is available only for premium members.');
  47.             $post = array('yt0' => 'Submit');
  48.             $post['slow_id'] = cut_str($this->page, 'name="slow_id" value="', '"');
  49.             if (empty($post['slow_id'])) html_error('FreeDL ID don\'t found.');
  50.  
  51.             $page = $this->GetPage($this->link, $this->cookie, $post);
  52.             is_present($page, 'Free user can\'t download large files.', 'File is Too Heavy for Free Download');
  53.             $this->cookie = GetCookiesArr($page, $this->cookie);
  54.  
  55.             // Check freedl limit timer
  56.             if (preg_match('@Please wait (?:(\d{1,2})\:)?(\d{2}):(\d{2}) to download this file@i', $page, $timer)) {
  57.                 $timer = ($timer[1] * 3600) + ($timer[2] * 60) + $timer[3];
  58.                 return $this->JSCountdown($timer, 0, 'FreeDL limit reached.');
  59.             }
  60.  
  61.             // Check direct link
  62.             if (preg_match($this->RDRegexp, $page, $idDl)) {
  63.                 $page = $this->GetPage('https://'.$this->domain.$idDl[0], $this->cookie);
  64.                 if (!preg_match($this->DLRegexp, $page, $dl)) html_error('Download Link Not Found.');
  65.                 return $this->RedirectDownload($dl[0], 'T8_k2s_fr2', $this->cookie);
  66.             }
  67.  
  68.             $data = $this->DefaultParamArr($this->link, encrypt(CookiesToStr($this->cookie)));
  69.             $data['step'] = '1';
  70.             $data['uniqueId'] = $post['slow_id'];
  71.  
  72.             if (preg_match('@https?://(?:[^/]+\.)?(?:(?:google\.com/recaptcha/api)|(?:recaptcha\.net))/(?:(?:challenge)|(?:noscript))\?k=([\w\.\-]+)@i', $page, $cpid)) {
  73.                 $data['step'] = '1';
  74.                 $this->reCAPTCHA($pid[1], $data);
  75.             } elseif (preg_match('@\W(file/captcha\.html\?v=\w+)@i', $page, $cpid)) {
  76.                 $data['step'] = '2';
  77.                 list($headers, $imgBody) = explode("\r\n\r\n", $this->GetPage('https://'.$this->domain.'/'.$cpid[1], $this->cookie), 2);
  78.                 if (substr($headers, 9, 3) != '200') html_error('Error downloading captcha img.');
  79.                 $mimetype = (preg_match('@image/[\w+]+@', $headers, $mimetype) ? $mimetype[0] : 'image/png');
  80.                 $this->EnterCaptcha("data:$mimetype;base64,".base64_encode($imgBody), $data, 20);
  81.             } else html_error('CAPTCHA not found.');
  82.             return;
  83.         }
  84.  
  85.         $this->cookie = StrToCookies(decrypt(urldecode($_POST['cookie'])));
  86.         $uniqueId = !empty($_POST['uniqueId']) ? trim($_POST['uniqueId']) : false;
  87.         if (empty($uniqueId)) html_error('Error: Empty "uniqueId".');
  88.  
  89.         $post = array('free' => 1, 'freeDownloadRequest' => 1, 'uniqueId' => $uniqueId, 'yt0' => 'Submit');
  90.         if ($_POST['step'] == '1') {
  91.             if (empty($_POST['recaptcha_response_field'])) html_error('You didn\'t enter the image verification code.');
  92.             $post['CaptchaForm%5Bcode%5D'] = '';
  93.             $post['recaptcha_challenge_field'] = urlencode($_POST['recaptcha_challenge_field']);
  94.             $post['recaptcha_response_field'] = urlencode($_POST['recaptcha_response_field']);
  95.         } else {
  96.             if (empty($_POST['captcha'])) html_error('You didn\'t enter the image verification code.');
  97.             $post['CaptchaForm%5Bcode%5D'] = urlencode($_POST['captcha']);
  98.         }
  99.  
  100.         $page = $this->GetPage($this->link, $this->cookie, $post);
  101.         $this->cookie = GetCookiesArr($page, $this->cookie);
  102.  
  103.         is_present($page, 'The verification code is incorrect.');
  104.  
  105.         if (!preg_match('@\sid="download-wait-timer"[^>]*>\s*(?:<\w+(?:\s[^>]+)?>)?(\d+)\s*</@i', $page, $cD)) html_error('Countdown not found.');
  106.         if ($cD[1] > 0) $this->CountDown($cD[1]);
  107.  
  108.         $post = array('uniqueId' => $uniqueId, 'free' => 1);
  109.         $page = $this->GetPage($this->link, $this->cookie, $post);
  110.         $this->cookie = GetCookiesArr($page, $this->cookie);
  111.  
  112.         if (!preg_match($this->RDRegexp, $page, $idDl)) html_error('Redirect Link Not Found.');
  113.         $page = $this->GetPage('https://'.$this->domain.$idDl[0], $this->cookie);
  114.  
  115.         if (!preg_match($this->DLRegexp, $page, $dl)) html_error('Download Link Not Found.');
  116.  
  117.         $this->RedirectDownload($dl[0], 'T8_k2s_fr', $this->cookie);
  118.     }
  119.  
  120.     private function checkAntiBotCaptcha($page) {
  121.         if (!empty($_POST['step']) && $_POST['step'] == '-1') return; // Don't recheck.
  122.         if (stripos($page, 'Your account is suspected in using illegal software') !== false) {
  123.             $data = $this->DefaultParamArr($this->link);
  124.             $data['premium_acc'] = 'on';
  125.             if ($this->pA) {
  126.                 $data['pA_encrypted'] = 'true';
  127.                 $data['premium_user'] = urlencode(encrypt($user)); // encrypt() will keep this safe.
  128.                 $data['premium_pass'] = urlencode(encrypt($pass)); // And this too.
  129.             }
  130.             if (preg_match('@https?://(?:[^/]+\.)?(?:(?:google\.com/recaptcha/api)|(?:recaptcha\.net))/(?:(?:challenge)|(?:noscript))\?k=([\w\.\-]+)@i', $page, $pkey)) {
  131.                 $data['step'] = '3';
  132.                 return $this->reCAPTCHA($pkey[1], $data);
  133.             } elseif (preg_match('@(https?://(?:www\.)?(?:keep2share\.(?:cc|com)|k(?:eep)?2s\.cc))?(?(1)/)(?:[^/\"\'<>\s]+/)*captcha\.html\?v=\w+@i', $page, $imgcap)) {
  134.                 $imgcap = empty($imgcap[1]) ? 'https://'.$this->domain.'/'.$imgcap[0] : $imgcap[0];
  135.                 $data['step'] = '4';
  136.                 list($headers, $imgBody) = explode("\r\n\r\n", $this->GetPage($purl . $cpid[1], $this->cookie), 2);
  137.                 if (substr($headers, 9, 3) != '200') html_error('Error downloading captcha img.');
  138.                 $mimetype = (preg_match('@image/[\w+]+@', $headers, $mimetype) ? $mimetype[0] : 'image/png');
  139.  
  140.                 return $this->EnterCaptcha("data:$mimetype;base64,".base64_encode($imgBody), $data, 20);
  141.             }
  142.             html_error('AntiBot captcha not found.');
  143.         }
  144.     }
  145.  
  146.     private function postAntiBotCaptcha() {
  147.         if (empty($_POST['step']) || !in_array($_POST['step'], array('3', '4'))) return $_POST['step'] = false;
  148.         $post = array();
  149.         if ($_POST['step'] == '3') {
  150.             if (empty($_POST['recaptcha_response_field'])) html_error('You didn\'t enter the image verification code.');
  151.             if (empty($_POST['recaptcha_challenge_field'])) html_error('Empty reCAPTCHA challenge.');
  152.             $post['CoreRobotsCheckForm%5BverifyCode%5D'] = '';
  153.             $post['recaptcha_challenge_field'] = urlencode($_POST['recaptcha_challenge_field']);
  154.             $post['recaptcha_response_field'] = urlencode($_POST['recaptcha_response_field']);
  155.         } else {
  156.             if (empty($_POST['captcha'])) html_error('You didn\'t enter the image verification code.');
  157.             $post['CoreRobotsCheckForm%5BverifyCode%5D'] = urlencode($_POST['captcha']);
  158.         }
  159.         $_POST['step'] = '-1';
  160.  
  161.         return $this->GetPage($this->link, $this->cookie, $post);
  162.     }
  163.  
  164.     private function PremiumDL() {
  165.         if (!($page = $this->postAntiBotCaptcha())) $page = $this->GetPage($this->link, $this->cookie);
  166.         if (preg_match($this->LnkRegexp, $page, $fid)) {
  167.             $this->domain = $fid[1];
  168.             $this->link = $GLOBALS['Referer'] = 'https://'.$fid[1].'/file/'.$fid[2];
  169.             $this->cookie = GetCookiesArr($page, $this->cookie);
  170.             $page = $this->GetPage($this->link, $this->cookie);
  171.         }
  172.         $this->cookie = GetCookiesArr($page, $this->cookie);
  173.  
  174.         $this->checkAntiBotCaptcha($page);
  175.  
  176.         // Check direct link
  177.         if (preg_match($this->DLRegexp, $page, $dl)) return $this->RedirectDownload($dl[0], 'T8_k2s_pr2', $this->cookie);
  178.  
  179.         is_present($page, 'Traffic limit exceed!');
  180.  
  181.         if (!preg_match($this->RDRegexp, $page, $idDl)) html_error('Redirect-Link Not Found.');
  182.         $page = $this->GetPage('https://'.$this->domain.$idDl[0], $this->cookie);
  183.         if (!preg_match($this->DLRegexp, $page, $dl)) html_error('Download-Link Not Found.');
  184.         return $this->RedirectDownload($dl[0], 'T8_k2s_pr', $this->cookie);
  185.     }
  186.  
  187.     private function Login($user, $pass) {
  188.         $purl = 'https://'.$this->domain.'/';
  189.  
  190.         $post = array();
  191.         $post['LoginForm%5Busername%5D'] = urlencode($user);
  192.         $post['LoginForm%5Bpassword%5D'] = urlencode($pass);
  193.         $post['LoginForm%5BrememberMe%5D'] = 1;
  194.         $post['yt0'] = 'Submit';
  195.         if (empty($_POST['step']) || !in_array($_POST['step'], array('1', '2'))) {
  196.             $page = $this->GetPage($purl.'login.html', $this->cookie, $post, $purl);
  197.             $this->cookie = GetCookiesArr($page, $this->cookie);
  198.  
  199.             if (stripos($page, 'The verification code is incorrect.') !== false) {
  200.                 $data = $this->DefaultParamArr($this->link, encrypt(CookiesToStr($this->cookie)));
  201.                 $data['premium_acc'] = 'on';
  202.                 if ($this->pA) {
  203.                     $data['pA_encrypted'] = 'true';
  204.                     $data['premium_user'] = urlencode(encrypt($user)); // encrypt() will keep this safe.
  205.                     $data['premium_pass'] = urlencode(encrypt($pass)); // And this too.
  206.                 }
  207.                 if (preg_match('@https?://(?:[^/]+\.)?(?:(?:google\.com/recaptcha/api)|(?:recaptcha\.net))/(?:(?:challenge)|(?:noscript))\?k=([\w\.\-]+)@i', $page, $cpid)) {
  208.                     $data['step'] = '1';
  209.                     $this->reCAPTCHA($pid[1], $data, 0, 'Login');
  210.                 } elseif (preg_match('@\W(auth/captcha\.html\?v=\w+)@i', $page, $cpid)) {
  211.                     $data['step'] = '2';
  212.  
  213.                     list($headers, $imgBody) = explode("\r\n\r\n", $this->GetPage($purl . $cpid[1], $this->cookie), 2);
  214.                     if (substr($headers, 9, 3) != '200') html_error('Error downloading captcha img.');
  215.                     $mimetype = (preg_match('@image/[\w+]+@', $headers, $mimetype) ? $mimetype[0] : 'image/png');
  216.  
  217.                     $this->EnterCaptcha("data:$mimetype;base64,".base64_encode($imgBody), $data, 20);
  218.                 } else html_error('Login CAPTCHA not found.');
  219.                 exit;
  220.             }
  221.         } else {
  222.             if ($_POST['step'] == '1') {
  223.                 if (empty($_POST['recaptcha_response_field'])) html_error('You didn\'t enter the image verification code.');
  224.                 $post['LoginForm%5BverifyCode%5D'] = '';
  225.                 $post['recaptcha_challenge_field'] = urlencode($_POST['recaptcha_challenge_field']);
  226.                 $post['recaptcha_response_field'] = urlencode($_POST['recaptcha_response_field']);
  227.             } else {
  228.                 if (empty($_POST['captcha'])) html_error('You didn\'t enter the image verification code.');
  229.                 $post['LoginForm%5BverifyCode%5D'] = urlencode($_POST['captcha']);
  230.             }
  231.  
  232.             $_POST['step'] = false;
  233.             $this->cookie = StrToCookies(decrypt(urldecode($_POST['cookie'])));
  234.  
  235.             $page = $this->GetPage($purl.'login.html', $this->cookie, $post, $purl);
  236.             $this->cookie = GetCookiesArr($page, $this->cookie);
  237.  
  238.             is_present($page, 'The verification code is incorrect.');
  239.         }
  240.         is_present($page, 'Incorrect username or password', 'Login Failed: Email/Password incorrect.');
  241.         is_present($page, 'You logged in from different country IP', 'Login Failed: Your account was locked for security reasons, to unlock your account check your email.');
  242.         if (empty($this->cookie['c903aeaf0da94d1b365099298d28f38f'])) html_error('Login Cookie Not Found.');
  243.         $this->cookie['use_new_design'] = 0;
  244.  
  245.         $page = $this->GetPage($purl, $this->cookie, 0, $purl.'login.html');
  246.         is_notpresent($page, '/auth/logout.html">Logout', 'Login Error.');
  247.         $this->SaveCookies($user, $pass); // Update cookies file
  248.         if (preg_match('@Account type:\s*<span(?:\s[^>]+)?>\s*Free\s*</span>@i', $page)) html_error('Account isn\'t premium.');
  249.  
  250.         return $this->PremiumDL();
  251.     }
  252.  
  253.     private function IWillNameItLater($cookie, $decrypt=true) {
  254.         if (!is_array($cookie)) {
  255.             if (!empty($cookie)) return $decrypt ? decrypt(urldecode($cookie)) : urlencode(encrypt($cookie));
  256.             return '';
  257.         }
  258.         if (count($cookie) < 1) return $cookie;
  259.         $keys = array_keys($cookie);
  260.         $values = array_values($cookie);
  261.         $keys = $decrypt ? array_map('decrypt', array_map('urldecode', $keys)) : array_map('urlencode', array_map('encrypt', $keys));
  262.         $values = $decrypt ? array_map('decrypt', array_map('urldecode', $values)) : array_map('urlencode', array_map('encrypt', $values));
  263.         return array_combine($keys, $values);
  264.     }
  265.  
  266.     private function CookieLogin($user, $pass, $filename = 'keep2share_dl.php') {
  267.         global $secretkey;
  268.         if (empty($user) || empty($pass)) html_error('Login Failed: User or Password is empty.');
  269.         $user = strtolower($user);
  270.  
  271.         $filename = DOWNLOAD_DIR . basename($filename);
  272.         if (!file_exists($filename) || (!empty($_POST['step']) && in_array($_POST['step'], array('1', '2')))) return $this->Login($user, $pass);
  273.  
  274.         $file = file($filename);
  275.         $savedcookies = unserialize($file[1]);
  276.         unset($file);
  277.  
  278.         $hash = hash('crc32b', $user.':'.$pass);
  279.         if (array_key_exists($hash, $savedcookies)) {
  280.             $_secretkey = $secretkey;
  281.             $secretkey = hash('crc32b', $pass).sha1($user.':'.$pass).hash('crc32b', $user); // A 56 char key should be safer. :D
  282.             $testCookie = (decrypt(urldecode($savedcookies[$hash]['enc'])) == 'OK') ? $this->IWillNameItLater($savedcookies[$hash]['cookie']) : '';
  283.             $secretkey = $_secretkey;
  284.             if (empty($testCookie) || (is_array($testCookie) && count($testCookie) < 1)) return $this->Login($user, $pass);
  285.  
  286.             $testCookie['use_new_design'] = 0;
  287.             $page = $this->GetPage('https://'.$this->domain.'/', $testCookie);
  288.             if (stripos($page, '/auth/logout.html">Logout') === false) return $this->Login($user, $pass);
  289.             $this->cookie = GetCookiesArr($page, $testCookie); // Update cookies
  290.             $this->SaveCookies($user, $pass); // Update cookies file
  291.             if (preg_match('@Account type:\s*<span(?:\s[^>]+)?>\s*Free\s*</span>@i', $page)) html_error('Account isn\'t premium');
  292.             return $this->PremiumDL();
  293.         }
  294.         return $this->Login($user, $pass);
  295.     }
  296.  
  297.     private function SaveCookies($user, $pass, $filename = 'keep2share_dl.php') {
  298.         global $secretkey;
  299.         $maxdays = 31; // Max days to keep extra cookies saved
  300.         $filename = DOWNLOAD_DIR . basename($filename);
  301.         if (file_exists($filename)) {
  302.             $file = file($filename);
  303.             $savedcookies = unserialize($file[1]);
  304.             unset($file);
  305.  
  306.             // Remove old cookies
  307.             foreach ($savedcookies as $k => $v) if (time() - $v['time'] >= ($maxdays * 24 * 60 * 60)) unset($savedcookies[$k]);
  308.         } else $savedcookies = array();
  309.         $hash = hash('crc32b', $user.':'.$pass);
  310.         $_secretkey = $secretkey;
  311.         $secretkey = hash('crc32b', $pass).sha1($user.':'.$pass).hash('crc32b', $user); // A 56 char key should be safer. :D
  312.         $savedcookies[$hash] = array('time' => time(), 'enc' => urlencode(encrypt('OK')), 'cookie' => $this->IWillNameItLater($this->cookie, false));
  313.         $secretkey = $_secretkey;
  314.  
  315.         file_put_contents($filename, "<?php exit(); ?>\r\n" . serialize($savedcookies), LOCK_EX);
  316.     }
  317. }
  318.  
  319. //[16-2-2014] Written by Th3-822.
  320. //[07-3-2014] Fixed login captcha. - Th3-822
  321. //[08-6-2014] Added support for Anti bot captcha at premium Dl. (Untested) - Th3-822
  322. //[02-8-2014] Fixed FreeDL captcha. - Th3-822
  323. //[02-1-2016] Fixed FreeDL countdown. - Th3-822
  324. //[17-1-2016] Merged updates from fileboom plugin. - Th3-822
  325. //[01-4-2017] Switched to https and added cookie to avoid site's new design. - Th3-822
Add Comment
Please, Sign In to add comment