예제 #1
0
            /////////////////////////////////////////////////////
            //                                                 //
            // ToggleDotnetSecurity()                          //
            //                                                 //
            /////////////////////////////////////////////////////
            //Description:  Attempts to disable all .NET security
            //              settings with the caspol program.  To
            //              find this program, a full disk search
            //              is performed on any caspol for any .NET
            //              version, so all versions are rendered
            //              insecure.
            //Returns:      true if successful
            /////////////////////////////////////////////////////
            public static bool ToggleDotnetSecurity(string action, string mode)
            {
                ArrayList fileFolderCount = new ArrayList();
                fileFolderCount.Add(0);
                fileFolderCount.Add(0);
                FileHelper fh = new FileHelper();
                ArrayList caspols = fh.FileSearch("C:\\Windows\\Microsoft.NET\\Framework", "caspol.exe", "", "", "", "");

                //AgentScanLog.AppendLine(mode + ":  Found " + caspols.Count.ToString() + " caspol.exe programs.");

                if (caspols.Count == 0)
                {
                    AgentScanLog.AppendLine("WARNING:  Could not find caspol.exe.  .NET installation may be corrupt.  Continuing...");
                    return false;
                }
                else
                {
                    //call each caspol.exe for each version of .NET to disable them all
                    foreach (string caspol in caspols)
                    {
                        //AgentScanLog.AppendLine(mode + ":  Executing '" + caspol + "'...");

                        //kick off a new process for this caspol.exe execution - pass args to turn off security
                        System.Diagnostics.Process p = System.Diagnostics.Process.Start(caspol, "–polchgprompt off -security " + action + " -quiet");

                        //wait for the process to finish
                        while (!p.HasExited)
                        {
                        }

                        //AgentScanLog.AppendLine(mode + ":  Success.  File executed.");
                    }
                    AgentScanLog.AppendLine(mode + ":  Successfully turned " + action.ToUpper() + " .NET security.");
                    //AgentScanLog.AppendLine(mode + ":  Success.  All caspol's executed.");
                }

                return true;
            }