コード例 #1
0
ファイル: HomeController.cs プロジェクト: shafe123/PenTester
        public ActionResult Test(VerifyPluginModel results)
        {
            if (ModelState.IsValid)
            {
            }

            return new JsonResult() { Data = new { success = ModelState.IsValid } };
        }
コード例 #2
0
        private void UpdateCSFile(string csFile, VerifyPluginModel userInput)
        {
            DynamicPlugin dp = CreateDynamicPluginObject(csFile);

            SyntaxTree tr = SyntaxTree.ParseFile(csFile);
            CompilationUnitSyntax root = tr.GetRoot();
            SyntaxList<MemberDeclarationSyntax> classes = tr.GetRoot().Members;
            PropertyDeclarationSyntax pd;
            StringBuilder sb = new StringBuilder();

            foreach (ClassDeclarationSyntax s in (classes.Where(m => m is ClassDeclarationSyntax)))
            {
                //find Host list
                if (s.Identifier.ToString() == userInput.HostList)
                {
                    ClassDeclarationSyntax hostList = s;
                    //add IDynamicHostList inheritance
                    hostList = hostList.AddBaseListTypes(Syntax.ParseTypeName(typeof(DynamicHostList).FullName));

                    //adds a get property for where the Host List is located is
                    //needs to be located underneath the Host List Tag
                    //adds Hosts property to match the interface
                    pd = CreateChildPropertyDeclaration("Hosts", userInput.Host, hostList.Members, typeof(DynamicHost));
                    hostList = hostList.AddMembers(pd);

                    //find class with 'ToolName'
                    pd = CreateStringProperty("ToolName", userInput.ReportName, userInput.HostList, classes, dp);
                    hostList = hostList.AddMembers(pd);

                    sb.AppendLine(hostList.NormalizeWhitespace().ToFullString());
                }
                else if (s.Identifier.ToString() == userInput.Host)
                {
                    //find Host class
                    ClassDeclarationSyntax host = s;
                    //add IDynamicHost inheritance
                    host = host.AddBaseListTypes(Syntax.ParseTypeName(typeof(DynamicHost).FullName));

                    //adds PortList property to match the interface
                    pd = CreateChildPropertyDeclaration("PortList", userInput.OpenPortList, host.Members, typeof(DynamicPortList));
                    host = host.AddMembers(pd);

                    //Adds IP property
                    pd = CreateStringProperty("IP", userInput.HostIP, userInput.Host, classes, dp);
                    host = host.AddMembers(pd);

                    //Adds OperatingSystem
                    if (userInput.HostOS != null)
                        host = host.AddMembers(CreateStringProperty("OperatingSystem", userInput.HostOS, userInput.Host, classes, dp));

                    //Adds Computer Name
                    if (userInput.HostName != null)
                        host = host.AddMembers(CreateStringProperty("Name", userInput.HostName, userInput.Host, classes, dp));

                    sb.AppendLine(host.NormalizeWhitespace().ToFullString());
                }
                else if (s.Identifier.ToString() == userInput.OpenPortList)
                {
                    //find port list
                    ClassDeclarationSyntax portList = (ClassDeclarationSyntax)classes.Where(m => m is ClassDeclarationSyntax)
                                                            .Single(m => ((ClassDeclarationSyntax)m).Identifier.ToString() == userInput.OpenPortList);
                    //adds IDynamicPortList inheritance
                    portList = portList.AddBaseListTypes(Syntax.ParseTypeName(typeof(DynamicPortList).FullName));

                    //adds OpenPorts property to match the interface
                    pd = CreateChildPropertyDeclaration("OpenPorts", userInput.OpenPort, portList.Members, typeof(DynamicPort));
                    portList = portList.AddMembers(pd).NormalizeWhitespace();

                    sb.AppendLine(portList.ToFullString());
                }
                else if (s.Identifier.ToString() == userInput.OpenPort)
                {
                    //find port class
                    ClassDeclarationSyntax port = s;
                    port = port.AddBaseListTypes(Syntax.ParseTypeName(typeof(DynamicPort).FullName));

                    port = port.AddMembers(CreateStringProperty("Number", userInput.PortNumber, userInput.OpenPort, classes, dp));

                    if (userInput.PortProtocol != null)
                        port = port.AddMembers(CreateStringProperty("Protocol", userInput.PortProtocol, userInput.OpenPort, classes, dp));
                    if (userInput.PortSeverity != null)
                        port = port.AddMembers(CreateStringProperty("Severity", userInput.PortSeverity, userInput.OpenPort, classes, dp));
                    if (userInput.PortThreatLevel != null)
                        port = port.AddMembers(CreateStringProperty("ThreatLevel", userInput.PortThreatLevel, userInput.OpenPort, classes, dp));
                    if (userInput.PortDescription != null)
                        port = port.AddMembers(CreateStringProperty("Description", userInput.PortDescription, userInput.OpenPort, classes, dp));

                    sb.AppendLine(port.NormalizeWhitespace().ToFullString());
                }
                else
                {
                    sb.AppendLine(s.NormalizeWhitespace().ToFullString());
                }
            }

            string final = sb.ToString();

            System.IO.File.WriteAllText(csFile, final);
        }
コード例 #3
0
        public JsonResult VerifyPlugin(VerifyPluginModel model)
        {
            if (ModelState.IsValid)
            {
                //add custom attributes based on user input
                //save class file
                UpdateCSFile((string)TempData["csLoc"], model);

                //dynamically load class as needed
                if (CreateDLL((string)TempData["csLoc"]))
                {
                    return new JsonResult() { Data = new { success = "True" } };
                }
                else
                {
                    Entities db = new Entities();
                    db.Plugins.Remove(db.Plugins.Single(p => p.PluginID == model.PluginId));
                    db.SaveChanges();
                }
            }

            return new JsonResult() { Data = new { success = "False" } };
        }