Ejemplo n.º 1
0
        public static Dictionary <string, bool> TestExecutionProxys()
        {
            Dictionary <string, bool> results = new Dictionary <string, bool>();

            Type     parentType = typeof(Tonsil.Processes.ExecutionProxys.ExecutionProxy);
            Assembly assembly   = parentType.Assembly;

            Type[]             types      = assembly.GetTypes();
            IEnumerable <Type> subclasses = types.Where(t => t.IsSubclassOf(parentType));

            foreach (Type type in subclasses)
            {
                Tonsil.Processes.Process targetProcess = new Notepad();
                Tonsil.Processes.ExecutionProxys.ExecutionProxy processUnderTest = (Tonsil.Processes.ExecutionProxys.ExecutionProxy)Activator.CreateInstance(type);
                processUnderTest.AddCmdlineExecution(targetProcess);
                bool result = TestExecutionProxy(processUnderTest, targetProcess);
                Console.WriteLine(string.Format("{1}: \t{0}", processUnderTest.CmdLine.ToString(), result ? "Pass" : "Fail"));
                results.Add(processUnderTest.CmdLine.ToString(), result);
            }
            return(results);
        }
Ejemplo n.º 2
0
        public static Dictionary <string, bool> TestExecuters()
        {
            Dictionary <string, bool> results = new Dictionary <string, bool>();

            string serverHost = "10.141.41.1";

            System.IO.File.WriteAllText(@"c:\somefile.vbs", @"CreateObject(""WScript.Shell"").Run(""Notepad.exe"")");

            Tonsil.Files.HttpFilePath httpFilePath = new Tonsil.Files.HttpFilePath()
            {
                Host      = serverHost,
                Port      = 80,
                Directory = "/somedir/",
                Filename  = "somefile.vbs"
            };
            Tonsil.Files.SmbFilePath smbFilePath = new Tonsil.Files.SmbFilePath()
            {
                Host      = serverHost,
                Port      = 445,
                ShareName = "someshare",
                Directory = @"\somedir\",
                Filename  = "somefile.vbs"
            };
            Tonsil.Files.LocalFilePath localFilePath = new Tonsil.Files.LocalFilePath()
            {
                Directory = @"c:\",
                Filename  = "somefile.vbs"
            };

            List <Tonsil.Files.FilePath> filePaths = new List <Tonsil.Files.FilePath>()
            {
                httpFilePath, smbFilePath, localFilePath
            };

            Type     parentType = typeof(Tonsil.Processes.Executers.Executer);
            Assembly assembly   = parentType.Assembly;

            Type[]             types      = assembly.GetTypes();
            IEnumerable <Type> subclasses = types.Where(t => t.IsSubclassOf(parentType));

            foreach (Type type in subclasses)
            {
                foreach (var filePath in filePaths)
                {
                    Tonsil.Files.File sourceFile = new Tonsil.Files.File()
                    {
                        FilePath = filePath
                    };
                    var processUnderTest = (Tonsil.Processes.Executers.Executer)Activator.CreateInstance(type);
                    if (processUnderTest.IsValidSource(sourceFile))
                    {
                        Tonsil.Processes.Process targetProcess = new Notepad(); // The process that sourceFile should spawn
                        processUnderTest.AddFileExecution(sourceFile);
                        bool result = TestExecutionProxy(processUnderTest, targetProcess);
                        Console.WriteLine(string.Format("{1}: \t{0}", processUnderTest.CmdLine.ToString(), result ? "Pass" : "Fail"));
                        results.Add(processUnderTest.CmdLine.ToString(), result);
                    }
                }
            }
            return(results);
        }