编写页面故意易受命令注入攻击

use*_*897 6 c# asp.net-mvc code-injection

我正在尝试编写一个故意容易受命令注入攻击的页面.这适用于培训环境.这是我到目前为止的代码:

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();
    }
Run Code Online (Sandbox Code Playgroud)

当它看到正常的域查找请求时似乎运行良好.

但是,当它看到这样的请求时:

http://localhost:50159/Home/CommandInjection?domain=www.google.com+%26+dir 它返回一个空白.

我期待的是它会返回域查找结果,然后是dir命令输出.

Evk*_*Evk 3

在这种情况下,搬起石头砸自己的脚并不容易,但你可以这样做:

ProcessStartInfo psi = new ProcessStartInfo("cmd.exe", "/c \"nslookup.exe " + domain + "\"")
{
    UseShellExecute = false,
    CreateNoWindow = true,
    RedirectStandardOutput = true
};
Run Code Online (Sandbox Code Playgroud)