Th3-822

[rapidleech][u] keep2share.cc_member.php

Jul 31st, 2014
885
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.04 KB | None | 0 0
  1. <?php
  2. ######## Account Info ########
  3. $upload_acc['keep2share_cc']['user'] = ''; //Set your login
  4. $upload_acc['keep2share_cc']['pass'] = ''; //Set your password
  5. ########################
  6.  
  7. $_GET['proxy'] = isset($_GET['proxy']) ? $_GET['proxy'] : '';
  8. $not_done = true;
  9.  
  10. if ($upload_acc['keep2share_cc']['user'] && $upload_acc['keep2share_cc']['pass']) {
  11.     $default_acc = true;
  12.     $_REQUEST['up_login'] = $upload_acc['keep2share_cc']['user'];
  13.     $_REQUEST['up_pass'] = $upload_acc['keep2share_cc']['pass'];
  14.     $_REQUEST['action'] = 'FORM';
  15.     echo "<b><center>Using Default Login.</center></b>\n";
  16. } else $default_acc = false;
  17.  
  18. if (empty($_REQUEST['action']) || $_REQUEST['action'] != 'FORM') {
  19.     echo "<table border='0' style='width:270px;' cellspacing='0' align='center'>
  20.     <form method='POST'>
  21.     <input type='hidden' name='action' value='FORM' />
  22.     <tr><td style='white-space:nowrap;'>&nbsp;Login*</td><td>&nbsp;<input type='text' name='up_login' value='' style='width:160px;' /></td></tr>
  23.     <tr><td style='white-space:nowrap;'>&nbsp;Password*</td><td>&nbsp;<input type='password' name='up_pass' value='' style='width:160px;' /></td></tr>\n";
  24.     echo "<tr><td colspan='2' align='center'><br /><input type='submit' value='Upload' /></td></tr>\n";
  25.     echo "<tr><td colspan='2' align='center'><small>*You can set it as default in <b>".basename(__FILE__)."</b></small></td></tr>\n";
  26.     echo "</table>\n</form>\n";
  27. } else {
  28.     $login = $not_done = false;
  29.     $domain = 'keep2share.cc';
  30.     $referer = "https://$domain/";
  31.  
  32.     // Login
  33.     echo "<table style='width:600px;margin:auto;'>\n<tr><td align='center'>\n<div id='login' width='100%' align='center'>Login to $domain</div>\n";
  34.  
  35.     $cookie = array('use_new_design' => 0);
  36.     if (!empty($_REQUEST['up_login']) && !empty($_REQUEST['up_pass'])) {
  37.         if (!empty($_REQUEST['A_encrypted'])) {
  38.             $_REQUEST['up_login'] = decrypt(urldecode($_REQUEST['up_login']));
  39.             $_REQUEST['up_pass'] = decrypt(urldecode($_REQUEST['up_pass']));
  40.             unset($_REQUEST['A_encrypted']);
  41.         }
  42.         CookieLogin($_REQUEST['up_login'], $_REQUEST['up_pass']);
  43.         $login = true;
  44.     } else html_error('Login failed: User/Password empty.');
  45.  
  46.     // Retrive upload ID
  47.     echo "<script type='text/javascript'>document.getElementById('login').style.display='none';</script>\n<div id='info' width='100%' align='center'>Retrieving upload ID</div>\n";
  48.  
  49.     $uploadData = k2s_apireq('getUploadFormData');
  50.     k2s_checkErrors($uploadData, 'Pre-Upload Error');
  51.  
  52.     // Uploading
  53.     echo "<script type='text/javascript'>document.getElementById('info').style.display='none';</script>\n";
  54.  
  55.     $url = parse_url($uploadData['form_action']);
  56.     $upfiles = upfile($url['host'], defport($url), $url['path'].(!empty($url['query']) ? '?'.$url['query'] : ''), $referer, 0, $uploadData['form_data'], $lfile, $lname, $uploadData['file_field'], '', $_GET['proxy'], $pauth, 0, $url['scheme']);
  57.  
  58.     // Upload Finished
  59.     echo "<script type='text/javascript'>document.getElementById('progressblock').style.display='none';</script>\n";
  60.  
  61.     is_page($upfiles);
  62.  
  63.     $status = intval(substr($upfiles, 9, 3));
  64.     $ulResult = ($status >= 500) ? array('status' => 'fail', 'code' => $status, 'message' => "HTTP Error $status.") : Get_Reply($upfiles);
  65.     k2s_checkErrors($ulResult, $prefix = 'Upload error');
  66.  
  67.     if (empty($ulResult['user_file_id'])) html_error('Download link not found.');
  68.     $download_link = 'https://k2s.cc/file/'.$ulResult['user_file_id'];
  69. }
  70.  
  71. // Edited For upload.php usage.
  72. function EnterCaptcha($captchaImg, $inputs, $captchaSize = '5', $sname = 'Enter Captcha', $iname = 'captcha') {
  73.     echo "\n<form name='captcha' method='POST'>\n";
  74.     foreach ($inputs as $name => $input) echo "\t<input type='hidden' name='$name' id='$name' value='$input' />\n";
  75.     echo "\t<h4>" . lang(301) . " <img alt='CAPTCHA Image' src='$captchaImg' /> " . lang(302) . ": <input type='text' id='captcha' name='$iname' size='$captchaSize' />&nbsp;&nbsp;\n\t\t<input type='submit' onclick='return check();' value='$sname' />\n\t</h4>\n\t<script type='text/javascript'>/* <![CDATA[ */\n\t\tfunction check() {\n\t\t\tvar captcha=document.getElementById('captcha').value;\n\t\t\tif (captcha == '') {\n\t\t\t\twindow.alert('You didn\'t enter the image verification code');\n\t\t\t\treturn false;\n\t\t\t} else return true;\n\t\t}\n\t/* ]]> */</script>\n</form>\n</body>\n</html>";
  76. }
  77.  
  78. // Edited For upload.php usage.
  79. function reCAPTCHA($publicKey, $inputs, $sname = 'Upload File') {
  80.     global $cookie, $domain, $referer, $pauth;
  81.     if (empty($publicKey) || preg_match('/[^\w\.\-]/', $publicKey)) html_error('Invalid reCAPTCHA public key.');
  82.     if (!is_array($inputs)) html_error('Error parsing captcha post data.');
  83.     // Check for a global recaptcha key
  84.     $page = geturl('www.google.com', 0, '/recaptcha/api/challenge?k=' . $publicKey, 'http://fakedomain.tld/fakepath', 0, 0, 0, $_GET['proxy'], $pauth);is_page($page);
  85.     if (substr($page, 9, 3) != '200') html_error('Invalid or deleted reCAPTCHA public key.');
  86.  
  87.     if (strpos($page, 'Invalid referer') === false) {
  88.         // Embed captcha
  89.         echo "<script language='JavaScript'>var RecaptchaOptions = {theme:'red', lang:'en'};</script>\n\n<center><form name='recaptcha' method='POST'><br />\n";
  90.         foreach ($inputs as $name => $input) echo "<input type='hidden' name='$name' id='C_$name' value='$input' />\n";
  91.         echo "<script type='text/javascript' src='//www.google.com/recaptcha/api/challenge?k=$publicKey'></script><noscript><iframe src='//www.google.com/recaptcha/api/noscript?k=$publicKey' height='300' width='500' frameborder='0'></iframe><br /><textarea name='recaptcha_challenge_field' rows='3' cols='40'></textarea><input type='hidden' name='recaptcha_response_field' value='manual_challenge' /></noscript><br /><input type='submit' name='submit' onclick='javascript:return checkc();' value='$sname' />\n<script type='text/javascript'>/*<![CDATA[*/\nfunction checkc(){\nvar capt=document.getElementById('recaptcha_response_field');\nif (capt.value == '') { window.alert('You didn\'t enter the image verification code.'); return false; }\nelse { return true; }\n}\n/*]]>*/</script>\n</form></center>\n</body>\n</html>";
  92.     } else {
  93.         // Download captcha
  94.         $page = geturl('www.google.com', 0, '/recaptcha/api/challenge?k=' . $publicKey, $referer, 0, 0, 0, $_GET['proxy'], $pauth);is_page($page);
  95.         if (!preg_match('@[\{,\s]challenge\s*:\s*[\'\"]([\w\-]+)[\'\"]@', $page, $challenge)) html_error('Error getting reCAPTCHA challenge.');
  96.         $inputs['recaptcha_challenge_field'] = $challenge = $challenge[1];
  97.  
  98.         $imgReq = geturl('www.google.com', 0, '/recaptcha/api/image?c=' . $challenge, $referer, 0, 0, 0, $_GET['proxy'], $pauth);is_page($imgReq);
  99.         list($headers, $imgBody) = explode("\r\n\r\n", $imgReq, 2);
  100.         unset($imgReq);
  101.         if (substr($headers, 9, 3) != '200') html_error('Error downloading captcha img.');
  102.         $mimetype = (preg_match('@image/[\w+]+@', $headers, $mimetype) ? $mimetype[0] : 'image/jpeg');
  103.  
  104.         EnterCaptcha("data:$mimetype;base64,".base64_encode($imgBody), $inputs, 20, $sname, 'recaptcha_response_field');
  105.     }
  106.     exit;
  107. }
  108.  
  109. function Login($user, $pass) {
  110.     global $cookie, $domain, $referer, $pauth, $default_acc;
  111.  
  112.     $post = array();
  113.     $post['LoginForm%5Busername%5D'] = urlencode($user);
  114.     $post['LoginForm%5Bpassword%5D'] = urlencode($pass);
  115.     $post['LoginForm%5BrememberMe%5D'] = 1;
  116.     if (empty($_POST['step']) || !in_array($_POST['step'], array('1', '2'))) {
  117.         $page = geturl($domain, 0, '/login.html', $referer, 0, $post, 0, $_GET['proxy'], $pauth, 0, 'https');is_page($page);
  118.         $cookie = GetCookiesArr($page);
  119.  
  120.         if (stripos($page, 'The verification code is incorrect.') !== false) {
  121.             $data = array();
  122.             $data['cookie'] = urlencode(encrypt(CookiesToStr($cookie)));
  123.             $data['action'] = 'FORM';
  124.             if (!$default_acc) {
  125.                 $data['A_encrypted'] = 'true';
  126.                 $data['up_login'] = urlencode(encrypt($user)); // encrypt() will keep this safe.
  127.                 $data['up_pass'] = urlencode(encrypt($pass)); // And this too.
  128.             }
  129.             if (preg_match('@https?://(?:[^/]+\.)?(?:(?:google\.com/recaptcha/api)|(?:recaptcha\.net))/(?:(?:challenge)|(?:noscript))\?k=([\w\.\-]+)@i', $page, $cpid)) {
  130.                 $data['step'] = '1';
  131.                 reCAPTCHA($pid[1], $data, 'Login');
  132.             } elseif (preg_match('@\W(auth/captcha\.html\?v=\w+)@i', $page, $cpid)) {
  133.                 $data['step'] = '2';
  134.  
  135.                 $imgReq = geturl($domain, 0, '/' . $cpid[1], $referer, $cookie, 0, 0, $_GET['proxy'], $pauth, 0, 'https');is_page($imgReq);
  136.                 list($headers, $imgBody) = explode("\r\n\r\n", $imgReq, 2);
  137.                 unset($imgReq);
  138.                 if (substr($headers, 9, 3) != '200') html_error('Error downloading captcha img.');
  139.                 $mimetype = (preg_match('@image/[\w+]+@', $headers, $mimetype) ? $mimetype[0] : 'image/png');
  140.  
  141.                 EnterCaptcha("data:$mimetype;base64,".base64_encode($imgBody), $data, 20, 'Login');
  142.             } else html_error('Login CAPTCHA not found.');
  143.             exit;
  144.         }
  145.  
  146.         is_present($page, 'Incorrect username or password', 'Login Failed: Email/Password incorrect.');
  147.         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.');
  148.         if (empty($cookie['c903aeaf0da94d1b365099298d28f38f'])) html_error('Login Cookie Not Found.');
  149.         if (empty($cookie['sessid'])) html_error('Session Cookie Not Found.');
  150.  
  151.         $test = k2s_apireq('test');
  152.         if ($test['code'] != 403) k2s_checkErrors($test, 'Login error');
  153.         else {
  154.             $page = geturl($domain, 0, '/', $referer.'login.html', $cookie, 0, 0, $_GET['proxy'], $pauth, 0, 'https');is_page($page);
  155.             is_notpresent($page, '/auth/logout.html">Logout', 'Login Error.');
  156.         }
  157.  
  158.         SaveCookies($user, $pass); // Update cookies file
  159.         return true;
  160.     }
  161.  
  162.     if ($_POST['step'] == '1') {
  163.         if (empty($_POST['recaptcha_response_field'])) html_error('You didn\'t enter the image verification code.');
  164.         $post['LoginForm%5BverifyCode%5D'] = '';
  165.         $post['recaptcha_challenge_field'] = urlencode($_POST['recaptcha_challenge_field']);
  166.         $post['recaptcha_response_field'] = urlencode($_POST['recaptcha_response_field']);
  167.     } else {
  168.         if (empty($_POST['captcha'])) html_error('You didn\'t enter the image verification code.');
  169.         $post['LoginForm%5BverifyCode%5D'] = urlencode($_POST['captcha']);
  170.     }
  171.  
  172.     $_POST['step'] = false;
  173.     $cookie = StrToCookies(decrypt(urldecode($_POST['cookie'])));
  174.  
  175.     $page = geturl($domain, 0, '/login.html', $referer, $cookie, $post, 0, $_GET['proxy'], $pauth, 0, 'https');is_page($page);
  176.     $cookie = GetCookiesArr($page, $cookie);
  177.  
  178.     is_present($page, 'The verification code is incorrect.');
  179.     is_present($page, 'Incorrect username or password', 'Login Failed: Email/Password incorrect');
  180.     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');
  181.     if (empty($cookie['c903aeaf0da94d1b365099298d28f38f'])) html_error('Login Cookie Not Found');
  182.     if (empty($cookie['sessid'])) html_error('Session Cookie Not Found');
  183.     $cookie['use_new_design'] = 0;
  184.  
  185.     $test = k2s_apireq('test');
  186.     if ($test['code'] != 403) k2s_checkErrors($test, 'Login Error');
  187.     else {
  188.         $page = geturl($domain, 0, '/', $referer.'login.html', $cookie, 0, 0, $_GET['proxy'], $pauth, 0, 'https');is_page($page);
  189.         is_notpresent($page, '/auth/logout.html">Logout', 'Login Error');
  190.     }
  191.  
  192.     SaveCookies($user, $pass); // Update cookies file
  193.     return true;
  194. }
  195.  
  196. function IWillNameItLater($cookie, $decrypt=true) {
  197.     if (!is_array($cookie)) {
  198.         if (!empty($cookie)) return $decrypt ? decrypt(urldecode($cookie)) : urlencode(encrypt($cookie));
  199.         return '';
  200.     }
  201.     if (count($cookie) < 1) return $cookie;
  202.     $keys = array_keys($cookie);
  203.     $values = array_values($cookie);
  204.     $keys = $decrypt ? array_map('decrypt', array_map('urldecode', $keys)) : array_map('urlencode', array_map('encrypt', $keys));
  205.     $values = $decrypt ? array_map('decrypt', array_map('urldecode', $values)) : array_map('urlencode', array_map('encrypt', $values));
  206.     return array_combine($keys, $values);
  207. }
  208.  
  209. function CookieLogin($user, $pass) {
  210.     global $domain, $referer, $secretkey, $pauth;
  211.     if (empty($user) || empty($pass)) html_error('Login Failed: User or Password is empty.');
  212.     $user = strtolower($user);
  213.  
  214.     $filename = 'keep2share_ul.php';
  215.     if (!defined('DOWNLOAD_DIR')) {
  216.         if (substr($GLOBALS['options']['download_dir'], -1) != '/') $GLOBALS['options']['download_dir'] .= '/';
  217.         define('DOWNLOAD_DIR', (substr($GLOBALS['options']['download_dir'], 0, 6) == 'ftp://' ? '' : $GLOBALS['options']['download_dir']));
  218.     }
  219.     $filename = DOWNLOAD_DIR.basename($filename);
  220.     if (!file_exists($filename)) return Login($user, $pass);
  221.  
  222.     $file = file($filename);
  223.     $savedcookies = unserialize($file[1]);
  224.     unset($file);
  225.  
  226.     $hash = hash('crc32b', $user.':'.$pass);
  227.     if (is_array($savedcookies) && array_key_exists($hash, $savedcookies)) {
  228.         $_secretkey = $secretkey;
  229.         $secretkey = hash('crc32b', $pass).sha1($user.':'.$pass).hash('crc32b', $user); // A 56 char key should be safer. :D
  230.         $testCookie = (decrypt(urldecode($savedcookies[$hash]['enc'])) == 'OK') ? IWillNameItLater($savedcookies[$hash]['cookie']) : false;
  231.         $secretkey = $_secretkey;
  232.         if (empty($testCookie) || (is_array($testCookie) && count($testCookie) < 1)) return Login($user, $pass);
  233.  
  234.         $testCookie['use_new_design'] = 0;
  235.         $test = k2s_apireq('test', array('auth_token' => urldecode($testCookie['sessid'])));
  236.         if ($test['code'] != 403) k2s_checkErrors($test, 'Login error');
  237.         else {
  238.             // If session is expired, try to get a updated one from the site with the cookies
  239.             $page = geturl($domain, 0, '/', $referer.'login.html', $testCookie, 0, 0, $_GET['proxy'], $pauth, 0, 'https');is_page($page);
  240.             $testCookie = GetCookiesArr($page, $testCookie);
  241.             if (stripos($page, '/auth/logout.html">Logout') === false || empty($testCookie['sessid'])) return Login($user, $pass);
  242.             // Test possibly updated session
  243.             $test2 = k2s_apireq('test', array('auth_token' => urldecode($testCookie['sessid'])));
  244.             if ($test2['code'] == 403) return Login($user, $pass);
  245.             k2s_checkErrors($test2, 'Login error');
  246.         }
  247.         $GLOBALS['cookie'] = $testCookie; // Update cookies
  248.         SaveCookies($user, $pass); // Update cookies file
  249.         return true;
  250.     }
  251.     return Login($user, $pass);
  252. }
  253.  
  254. function SaveCookies($user, $pass) {
  255.     global $secretkey;
  256.     $maxdays = 31; // Max days to keep cookies saved
  257.  
  258.     $filename = 'keep2share_ul.php';
  259.     $filename = DOWNLOAD_DIR.basename($filename);
  260.     if (file_exists($filename)) {
  261.         $file = file($filename);
  262.         $savedcookies = unserialize($file[1]);
  263.         unset($file);
  264.  
  265.         // Remove old cookies
  266.         foreach ($savedcookies as $k => $v) if (time() - $v['time'] >= ($maxdays * 86400)) unset($savedcookies[$k]);
  267.     } else $savedcookies = array();
  268.     $hash = hash('crc32b', $user.':'.$pass);
  269.     $_secretkey = $secretkey;
  270.     $secretkey = hash('crc32b', $pass).sha1($user.':'.$pass).hash('crc32b', $user); // A 56 char key should be safer. :D
  271.     $savedcookies[$hash] = array('time' => time(), 'enc' => urlencode(encrypt('OK')), 'cookie' => IWillNameItLater($GLOBALS['cookie'], false));
  272.     $secretkey = $_secretkey;
  273.  
  274.     write_file($filename, "<?php exit(); ?>\r\n" . serialize($savedcookies));
  275. }
  276.  
  277. function Get_Reply($content) {
  278.     if (!function_exists('json_decode')) html_error('Error: Please enable JSON in PHP.');
  279.     $content = ltrim($content);
  280.     if (($pos = strpos($content, "\r\n\r\n")) > 0) $content = trim(substr($content, $pos + 4));
  281.     $cb_pos = strpos($content, '{');
  282.     $sb_pos = strpos($content, '[');
  283.     if ($cb_pos === false && $sb_pos === false) html_error('JSON start braces not found.');
  284.     $sb = ($cb_pos === false || $sb_pos < $cb_pos) ? true : false;
  285.     $content = substr($content, strpos($content, ($sb ? '[' : '{')));$content = substr($content, 0, strrpos($content, ($sb ? ']' : '}')) + 1);
  286.     if (empty($content)) html_error('No JSON content.');
  287.     $rply = json_decode($content, true);
  288.     if ($rply === NULL) html_error('Error reading JSON.');
  289.     return $rply;
  290. }
  291.  
  292. function k2s_checkErrors($reply, $prefix = 'Error') {
  293.     if (strtolower($reply['status']) != 'fail') return;
  294.     switch ($reply['code']) {
  295.         default: $msg = ($reply['message'] ? $reply['message'] : '*No message for this error*');break;
  296.         case 429: $msg = 'Too many requests to the API, please try again later';break;
  297.         case 500: $msg = 'Server error while processing your request, please try again later';break;
  298.         case 503: $msg = 'API temporarily not available, please try again later';break;
  299.     }
  300.     html_error("$prefix: [{$reply['code']}] $msg.");
  301. }
  302.  
  303. function k2s_apireq($actionPath, $post = array()) {
  304.     if (!function_exists('json_encode')) html_error('Error: Please enable JSON in PHP.');
  305.     if (!is_array($post)) html_error('k2s_apireq: Parameter 2 must be passed as an array.');
  306.     $post['auth_token'] = (!empty($post['auth_token']) ? $post['auth_token'] : (!empty($GLOBALS['cookie']['sessid']) ? urldecode($GLOBALS['cookie']['sessid']) : false));
  307.  
  308.     $page = geturl($GLOBALS['domain'], 0, '/api/v1/'.$actionPath, $GLOBALS['referer'], 0, json_encode($post), 0, $_GET['proxy'], $GLOBALS['pauth'], 0, 'https');
  309.     is_page($page);
  310.  
  311.     $status = intval(substr($page, 9, 3));
  312.     if ($status >= 500) return array('status' => 'fail', 'code' => $status, 'message' => "k2s_apireq: HTTP Error $status.");
  313.  
  314.     return Get_Reply($page);
  315. }
  316.  
  317. //[31-7-2014]  Written by Th3-822.
  318. //[04-4-2017] Switched to https and added cookie to avoid site's new design. - Th3-822
Add Comment
Please, Sign In to add comment