Advertisement
Guest User

Untitled

a guest
Mar 4th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.90 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @ This file is created by http://DeZender.Net
  5. * @ deZender (PHP7 Decoder for ionCube Encoder)
  6. *
  7. * @ Version : 4.0.8.2
  8. * @ Author : DeZender
  9. * @ Release on : 02.01.2019
  10. * @ Official site : http://DeZender.Net
  11. *
  12. */
  13.  
  14. class AntiFlood
  15. {
  16. const OPTION_COUNTER_RESET_SECONDS = 'COUNTER_RESET_SECONDS';
  17. const OPTION_BAN_REMOVE_SECONDS = 'BAN_REMOVE_SECONDS';
  18. const OPTION_MAX_REQUESTS = 'MAX_REQUESTS';
  19. const OPTION_DATA_PATH = 'DATA_PATH';
  20.  
  21. private $options;
  22. private $ip;
  23.  
  24. public function __construct($overrideOptions = [])
  25. {
  26. $this->options = array_merge(['COUNTER_RESET_SECONDS' => 2, 'MAX_REQUESTS' => 5, 'BAN_REMOVE_SECONDS' => 60, 'DATA_PATH' => '/tmp/antiflood_' . str_replace(['www.', '.'], ['', '_'], $_SERVER['SERVER_NAME'])], $overrideOptions);
  27. @mkdir($this->options['DATA_PATH']);
  28. $this->ip = $_SERVER['REMOTE_ADDR'];
  29. }
  30.  
  31. public function isBanned()
  32. {
  33. $controlLockFile = $this->options['DATA_PATH'] . '/' . str_replace('.', '_', $this->ip);
  34.  
  35. if (file_exists($controlLockFile)) {
  36. if ($this->options['BAN_REMOVE_SECONDS'] < (time() - filemtime($controlLockFile))) {
  37. unlink($controlLockFile);
  38. }
  39. else {
  40. touch($controlLockFile);
  41. return true;
  42. }
  43. }
  44.  
  45. $controlFile = $this->options['DATA_PATH'] . '/ctrl';
  46. $control = [];
  47.  
  48. if (file_exists($controlFile)) {
  49. $fh = fopen($controlFile, 'r');
  50. $fileContentsArr = (0 < filesize($controlFile) ? json_decode(fread($fh, filesize($controlFile)), true) : []);
  51. $control = array_merge($control, $fileContentsArr);
  52. fclose($fh);
  53. }
  54.  
  55. if (isset($control[$this->ip])) {
  56. if ((time() - $control[$this->ip]['t']) < $this->options['COUNTER_RESET_SECONDS']) {
  57. $control[$this->ip]['c']++;
  58. }
  59. else {
  60. $control[$this->ip]['c'] = 1;
  61. }
  62. }
  63. else {
  64. $control[$this->ip]['c'] = 1;
  65. }
  66.  
  67. $control[$this->ip]['t'] = time();
  68.  
  69. if ($this->options['MAX_REQUESTS'] < $control[$this->ip]['c']) {
  70. $fh = fopen($controlLockFile, 'w');
  71. fwrite($fh, '');
  72. fclose($fh);
  73. }
  74.  
  75. $fh = fopen($controlFile, 'w');
  76. fwrite($fh, json_encode($control));
  77. fclose($fh);
  78. return false;
  79. }
  80. }
  81.  
  82. class Signatures
  83. {
  84. static public function generateSignature($data)
  85. {
  86. return hash_hmac('sha256', $data, Constants::IG_SIG_KEY);
  87. }
  88.  
  89. static public function signData($data, $exclude = [])
  90. {
  91. $result = [];
  92.  
  93. foreach ($exclude as $key) {
  94. if (isset($data[$key])) {
  95. $result[$key] = $data[$key];
  96. unset($data[$key]);
  97. }
  98. }
  99.  
  100. foreach ($data as &$value) {
  101. if (is_scalar($value)) {
  102. $value = (string) $value;
  103. }
  104. }
  105.  
  106. unset($value);
  107. $data = json_encode((object) Utils::reorderByHashCode($data));
  108. $result['ig_sig_key_version'] = Constants::SIG_KEY_VERSION;
  109. $result['signed_body'] = self::generateSignature($data) . '.' . $data;
  110. return Utils::reorderByHashCode($result);
  111. }
  112.  
  113. static public function generateDeviceId()
  114. {
  115. $megaRandomHash = md5(number_format(microtime(true), 7, '', ''));
  116. return 'android-' . substr($megaRandomHash, 16);
  117. }
  118.  
  119. static public function generateUUID($keepDashes = true)
  120. {
  121. $uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 4095) | 16384, mt_rand(0, 16383) | 32768, mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
  122. return $keepDashes ? $uuid : str_replace('-', '', $uuid);
  123. }
  124. }
  125.  
  126. class Utils
  127. {
  128. const BOUNDARY_CHARS = '-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  129. const BOUNDARY_LENGTH = 30;
  130.  
  131. static protected $_lastUploadId;
  132.  
  133. static public function generateMultipartBoundary()
  134. {
  135. $result = '';
  136. $max = strlen('-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') - 1;
  137.  
  138. for ($i = 0; $i < 30; ++$i) {
  139. $result .= '-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'[mt_rand(0, $max)];
  140. }
  141.  
  142. return $result;
  143. }
  144.  
  145. static public function hashCode($string)
  146. {
  147. $result = 0;
  148. $len = strlen($string);
  149.  
  150. for ($i = 0; $i < $len; ++$i) {
  151. $result = ((-1 * $result) + ($result << 5) + ord($string[$i])) & 4294967295.0;
  152. }
  153.  
  154. if (4 < PHP_INT_SIZE) {
  155. if (2147483647 < $result) {
  156. $result -= 4294967296.0;
  157. }
  158. else if ($result < -2147483648.0) {
  159. $result += 4294967296.0;
  160. }
  161. }
  162.  
  163. return $result;
  164. }
  165.  
  166. static public function reorderByHashCode($data)
  167. {
  168. $hashCodes = [];
  169.  
  170. foreach ($data as $key => $value) {
  171. $hashCodes[$key] = self::hashCode($key);
  172. }
  173.  
  174. uksort($data, function($a, $b) use($hashCodes) {
  175. $a = $hashCodes[$a];
  176. $b = $hashCodes[$b];
  177.  
  178. if ($a < $b) {
  179. return -1;
  180. }
  181. else if ($b < $a) {
  182. return 1;
  183. }
  184. else {
  185. return 0;
  186. }
  187. });
  188. return $data;
  189. }
  190.  
  191. static public function generateUploadId($useNano = false)
  192. {
  193. $result = NULL;
  194.  
  195. if (!$useNano) {
  196. while (true) {
  197. $result = number_format(round(microtime(true) * 1000), 0, '', '');
  198. if ((self::$_lastUploadId !== NULL) && ($result === self::$_lastUploadId)) {
  199. usleep(1000);
  200. continue;
  201. }
  202.  
  203. self::$_lastUploadId = $result;
  204. break;
  205. }
  206. }
  207. else {
  208. $result = number_format(microtime(true) - strtotime('Last Monday'), 6, '', '');
  209. $result .= str_pad((string) mt_rand(1, 999), 3, '0', STR_PAD_LEFT);
  210. }
  211.  
  212. return $result;
  213. }
  214.  
  215. static public function generateUserBreadcrumb($size)
  216. {
  217. $key = 'iN4$aGr0m';
  218. $date = (int) microtime(true) * 1000;
  219. $term = (rand(2, 3) * 1000) + ($size * rand(15, 20) * 100);
  220. $text_change_event_count = round($size / rand(2, 3));
  221.  
  222. if ($text_change_event_count == 0) {
  223. $text_change_event_count = 1;
  224. }
  225.  
  226. $data = $size . ' ' . $term . ' ' . $text_change_event_count . ' ' . $date;
  227. return base64_encode(hash_hmac('sha256', $data, $key, true)) . "\n" . base64_encode($data) . "\n";
  228. }
  229.  
  230. static public function cookieToArray($string, $domain)
  231. {
  232. $arrCookies = [];
  233. $fileVals = self::extractCookies($string);
  234.  
  235. foreach ($fileVals as $cookie) {
  236. if ($cookie['domain'] == $domain) {
  237. $arrCookies[$cookie['name']] = $cookie['value'];
  238. }
  239. }
  240.  
  241. return $arrCookies;
  242. }
  243.  
  244. static public function generateAsns($asnsNumber)
  245. {
  246. $asnsNumber = intval($asnsNumber);
  247. if (($asnsNumber == 0) || (intval(Wow::get('ayar/proxyStatus')) == 0)) {
  248. return [NULL, NULL];
  249. }
  250.  
  251. if (Wow::get('ayar/proxyStatus') == 3) {
  252. $byPassServerCode = trim(Wow::get('ayar/proxyList'));
  253. $byPassServerUA = (strpos($byPassServerCode, '@') !== false ? explode('@', $byPassServerCode)[0] : NULL);
  254. $byPassServerRange = (strpos($byPassServerCode, '@') !== false ? explode(':', explode('@', $byPassServerCode)[1]) : explode(':', $byPassServerCode));
  255. return [$byPassServerRange[0] . ':' . (intval($byPassServerRange[1]) + $asnsNumber), $byPassServerUA];
  256. }
  257.  
  258. $asnsNumber--;
  259. $proxyList = explode("\r\n", Wow::get('ayar/proxyList'));
  260. $proxyString = (isset($proxyList[$asnsNumber]) ? $proxyList[$asnsNumber] : NULL);
  261.  
  262. if (empty($proxyString)) {
  263. return [NULL, NULL];
  264. }
  265.  
  266. if (Wow::get('ayar/proxyStatus') == 4) {
  267. $ipType = (strpos($proxyString, ':') !== false ? CURL_IPRESOLVE_V6 : NULL);
  268. return [$proxyString, $ipType];
  269. }
  270.  
  271. $proxyUserPwd = (strpos($proxyString, '@') !== false ? explode('@', $proxyString)[0] : NULL);
  272. $proxyHostPort = (strpos($proxyString, '@') !== false ? explode('@', $proxyString)[1] : $proxyString);
  273. return [$proxyHostPort, $proxyUserPwd];
  274. }
  275.  
  276. static public function extractCookies($string)
  277. {
  278. $lines = explode(PHP_EOL, $string);
  279. $cookies = [];
  280.  
  281. foreach ($lines as $line) {
  282. $cookie = [];
  283.  
  284. if (substr($line, 0, 10) == '#HttpOnly_') {
  285. $line = substr($line, 10);
  286. $cookie['httponly'] = true;
  287. }
  288. else {
  289. $cookie['httponly'] = false;
  290. }
  291. if ((substr($line, 0, 1) != '#') && (substr_count($line, '\\' . "\t") == 6)) {
  292. $tokens = explode('\\' . "\t", $line);
  293. $tokens = array_map('trim', $tokens);
  294. $cookie['domain'] = $tokens[0];
  295. $cookie['flag'] = $tokens[1];
  296. $cookie['path'] = $tokens[2];
  297. $cookie['secure'] = $tokens[3];
  298. $cookie['expiration-epoch'] = $tokens[4];
  299. $cookie['name'] = urldecode($tokens[5]);
  300. $cookie['value'] = urldecode($tokens[6]);
  301. $cookie['expiration'] = date('Y-m-d h:i:s', $tokens[4]);
  302. $cookies[] = $cookie;
  303. }
  304. }
  305.  
  306. return $cookies;
  307. }
  308.  
  309. static public function cookieConverter($cookie, $cnf, $c)
  310. {
  311. $confData = [];
  312.  
  313. if (!empty($cnf)) {
  314. $separator = "\r\n";
  315. $line = strtok($cnf, $separator);
  316.  
  317. while ($line !== false) {
  318. if ($line[0] == '#') {
  319. continue;
  320. }
  321.  
  322. $kv = explode('=', $line, 2);
  323. $confData[$kv[0]] = trim($kv[1], "\r\n" . ' ');
  324. $line = strtok($separator);
  325. }
  326. }
  327.  
  328. if (!isset($confData['username_id'])) {
  329. $confData['username_id'] = $c['username_id'];
  330. }
  331.  
  332. if (isset($confData['user_agent'])) {
  333. ..................................................................................
  334. .............................................
  335. ................
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement