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