我正在尝试编写一个故意容易受到命令注入(inject)攻击的页面。这是一个训练环境。这是我到目前为止的代码:
public ActionResult CommandInjection()
{
string domain = Request.QueryString["domain"];
ViewBag.Domain = domain;
ProcessStartInfo psi = new ProcessStartInfo("nslookup.exe", domain)
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true
};
var proc = Process.Start(psi);
string result = proc.StandardOutput.ReadToEnd();
ViewBag.Msg = "This page is vulnerable to Command Injection";
ViewBag.Result = result;
return View();
}
当它看到正常的域查找请求时,它似乎工作正常。
但是,当它看到这样的请求时:
http://localhost:50159/Home/CommandInjection?domain=www.google.com+%26+dir
它返回空白。
我所期望的是它会返回域查找的结果,然后是 dir
命令的输出。
最佳答案
在这种情况下搬起石头砸自己的脚并不容易,但你可以这样做:
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", "/c \"nslookup.exe " + domain + "\"")
{
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true
};
关于c# - 故意编写易受命令注入(inject)攻击的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49746314/