如何让一个 IIS 应用程序 运行 一个简单的命令?
How to have an IIS Application run a simple command?
那么,假设您在 IIS 中有一个名为 Test
的网站。我希望能够添加一个应用程序,当用户访问该页面时,它只需 运行s foo.exe /runfoo
。假设我不关心性能,"clean code",运行过于频繁地使用命令等等。这是为了概念验证/更大工具包的一部分。
我已经尝试并正在工作的是,我可以部署一个包含所有 DLLs/other 垃圾的完整 C# Web 应用程序,并让它创建一个 Process
和 运行 它。我不想那样做。理想的情况是我会在现有网站下创建一个应用程序,该网站有一个单独的应用程序池(我可以更改),并且在其中我可以修改 web.config 或与应用程序池有关的东西以拥有它运行一个命令。一个简单的应用程序,只有一个文件夹,其中包含最少的文件。
一些要求:
- 该命令可以 运行 定期执行,而不是仅在用户访问页面时执行,但这并不可取。
- 该命令必须能够接受参数。
- 应用程序目录中需要最少的文件。
我查看了所有我能找到的现有选项,其中 none 对我来说很有用,除了应用程序中的 "Process Orphaning"池设置。有没有办法通过访问页面来触发它(无需部署成熟的网络应用程序)?
编辑:
看起来这是一项关于攻击性安全技术的研究工作以及 IIS 的要求
- 该命令可以 运行 定期而不是仅在用户访问
页面,但这不是更可取的。
- 命令必须能够接受
参数。
- 应用程序目录中需要最少的文件。
您可以 运行 一个 exe 作为 IIS 中的 CGI 可执行文件,如解释的那样 here . This article talks about passing query string value . Also explore fastCGI 以及对 CGI 的改进
编辑2:Adding另一个选项
You can also simply put a simple aspx and it's code behind in a IIS
website's content and can access that aspx page. No Compilation,No
deployment,no bin directory etc.All you need is two files
- 在您的 IIS 网站中创建两个文件 default.aspx 和 Default.aspx.cs
这是代码
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
和Default.aspx.cs文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Process process = new Process();
process.StartInfo.FileName = "echo.exe";
process.Start();
}
}
那么,假设您在 IIS 中有一个名为 Test
的网站。我希望能够添加一个应用程序,当用户访问该页面时,它只需 运行s foo.exe /runfoo
。假设我不关心性能,"clean code",运行过于频繁地使用命令等等。这是为了概念验证/更大工具包的一部分。
我已经尝试并正在工作的是,我可以部署一个包含所有 DLLs/other 垃圾的完整 C# Web 应用程序,并让它创建一个 Process
和 运行 它。我不想那样做。理想的情况是我会在现有网站下创建一个应用程序,该网站有一个单独的应用程序池(我可以更改),并且在其中我可以修改 web.config 或与应用程序池有关的东西以拥有它运行一个命令。一个简单的应用程序,只有一个文件夹,其中包含最少的文件。
一些要求:
- 该命令可以 运行 定期执行,而不是仅在用户访问页面时执行,但这并不可取。
- 该命令必须能够接受参数。
- 应用程序目录中需要最少的文件。
我查看了所有我能找到的现有选项,其中 none 对我来说很有用,除了应用程序中的 "Process Orphaning"池设置。有没有办法通过访问页面来触发它(无需部署成熟的网络应用程序)?
编辑:
看起来这是一项关于攻击性安全技术的研究工作以及 IIS 的要求
- 该命令可以 运行 定期而不是仅在用户访问 页面,但这不是更可取的。
- 命令必须能够接受 参数。
- 应用程序目录中需要最少的文件。
您可以 运行 一个 exe 作为 IIS 中的 CGI 可执行文件,如解释的那样 here . This article talks about passing query string value . Also explore fastCGI 以及对 CGI 的改进
编辑2:Adding另一个选项
You can also simply put a simple aspx and it's code behind in a IIS website's content and can access that aspx page. No Compilation,No deployment,no bin directory etc.All you need is two files
- 在您的 IIS 网站中创建两个文件 default.aspx 和 Default.aspx.cs
这是代码
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
和Default.aspx.cs文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Process process = new Process();
process.StartInfo.FileName = "echo.exe";
process.Start();
}
}