c# - 故意编写易受命令注入(inject)攻击的页面

标签 c# asp.net-mvc code-injection

我正在尝试编写一个故意容易受到命令注入(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/

相关文章:

c# - SqlCommand.Parameters.AddWithValue 未返回正确结果

jquery - 如何使用jquery调用html.actionlink

php - [已解决]PDO/MySQL 准备语句注入(inject)分号

当注入(inject)的服务具有较旧的 Grails 版本时,Grails 服务注入(inject) null

php - 评论区sql注入(inject)

c# - await 正在停止程序的执行

c# - 访问 MemoryCache 会创建副本吗?

c# - 在 WCF 中初始化对象一次

asp.net-mvc - 处理ajax调用中的 session 超时

asp.net - 自动化功能性 Web GUI 测试框架 (asp.net)