示例#1
0
        public void DifferentUserProcessShouldStopProgramAfterTimeIsEnded()
        {
            var exePath = this.CreateExe("TimeLimit.exe", TimeLimitSourceCode);

            var process = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);
            var result  = process.Start(100, 32 * 1024 * 1024);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.ProcessKilledBecauseOfTimeLimit);
        }
示例#2
0
        public void DifferentUserProcessShouldNotBlockWhenEnterEndlessLoop()
        {
            var exePath = this.CreateExe("EndlessLoop.exe", EndlessLoopSourceCode);

            var process = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);
            var result  = process.Start(50, 32 * 1024 * 1024);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.ProcessKilledBecauseOfTimeLimit);
        }
        public void DifferentUserProcessShouldReturnCorrectAmountOfUsedMemory()
        {
            var exePath = this.CreateExe("Consuming50MbOfMemory.exe", Consuming50MbOfMemorySourceCode);

            var process = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);
            var result = process.Start(5000, 100 * 1024 * 1024);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.MaxMemoryUsed > 50 * 1024 * 1024);
        }
        public void DifferentUserProcessShouldNotBlockWhenEnterEndlessLoop()
        {
            var exePath = this.CreateExe("EndlessLoop.exe", EndlessLoopSourceCode);

            var process = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);
            var result = process.Start(50, 32 * 1024 * 1024);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.ProcessKilledBecauseOfTimeLimit);
        }
示例#5
0
        public void DifferentUserProcessShouldReturnCorrectAmountOfUsedMemory()
        {
            var exePath = this.CreateExe("Consuming50MbOfMemory.exe", Consuming50MbOfMemorySourceCode);

            var process = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);
            var result  = process.Start(5000, 100 * 1024 * 1024);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.MaxMemoryUsed > 50 * 1024 * 1024);
        }
示例#6
0
        public void DifferentUserProcessShouldNotBeAbleToWriteToClipboard()
        {
            var exePath = this.CreateExe("WriteToClipboard.exe", WriteToClipboardSourceCode);

            var process = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);
            var result  = process.Start(1500, 32 * 1024 * 1024);

            Assert.IsNotNull(result);
            Assert.IsFalse(string.IsNullOrEmpty(result.StandardErrorContent), "No exception is thrown!"); // Exception is thrown
            Assert.AreNotEqual("i did it", Clipboard.GetText());
        }
示例#7
0
        public void DifferentUserProcessShouldNotBeAbleToReadClipboard()
        {
            Clipboard.SetText("clipboard test");
            var exePath = this.CreateExe("ReadClipboard.exe", ReadClipboardSourceCode);

            var process = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);
            var result  = process.Start(1500, 32 * 1024 * 1024);

            Assert.IsNotNull(result);
            Assert.IsFalse(string.IsNullOrEmpty(result.StandardErrorContent), "No exception is thrown!"); // Exception is thrown
        }
        public void DifferentUserProcessShouldNotBeAbleToReadClipboard()
        {
            Clipboard.SetText("clipboard test");
            var exePath = this.CreateExe("ReadClipboard.exe", ReadClipboardSourceCode);

            var process = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);
            var result = process.Start(1500, 32 * 1024 * 1024);

            Assert.IsNotNull(result);
            Assert.IsFalse(string.IsNullOrEmpty(result.StandardErrorContent), "No exception is thrown!"); // Exception is thrown
        }
示例#9
0
        public void DifferentUserProcessShouldStandardErrorContentShouldContainExceptions()
        {
            var exePath = this.CreateExe("ThrowException.exe", ThrowExceptionSourceCode);

            var process = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);
            var result  = process.Start(500, 32 * 1024 * 1024);

            Assert.IsNotNull(result);
            Assert.IsFalse(string.IsNullOrEmpty(result.StandardErrorContent), "StandardErrorContent is empty!"); // Exception is thrown
            Assert.IsTrue(result.StandardErrorContent.Contains("Exception message!"));
        }
        public void DifferentUserProcessShouldNotBeAbleToWriteToClipboard()
        {
            var exePath = this.CreateExe("WriteToClipboard.exe", WriteToClipboardSourceCode);

            var process = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);
            var result = process.Start(1500, 32 * 1024 * 1024);

            Assert.IsNotNull(result);
            Assert.IsFalse(string.IsNullOrEmpty(result.StandardErrorContent), "No exception is thrown!"); // Exception is thrown
            Assert.AreNotEqual("i did it", Clipboard.GetText());
        }
示例#11
0
        public void DifferentUserProcessShouldSendInputDataToProcess()
        {
            var exePath = this.CreateExe("InputOutput.exe", ReadInputAndThenOutputSourceCode);

            const string InputData = "SomeInputData!!@#$%^&*(\n";
            var          process   = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);

            process.SetTextToWrite(InputData);
            var result = process.Start(1000, 32 * 1024 * 1024);

            Assert.IsNotNull(result);
            Assert.AreEqual(InputData.Trim(), result.StandardOutputContent.Trim());
        }
        public void DifferentUserProcessShouldNotBeAbleToStartProcess()
        {
            var notepadsBefore = Process.GetProcessesByName("notepad.exe").Count();
            var exePath = this.CreateExe("StartProcess.exe", StartNotepadProcessSourceCode);

            var process = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);
            var result = process.Start(1500, 32 * 1024 * 1024);
            var notepadsAfter = Process.GetProcessesByName("notepad.exe").Count();

            Assert.IsNotNull(result);
            Assert.IsFalse(string.IsNullOrEmpty(result.StandardErrorContent), "No exception is thrown!"); // Exception is thrown
            Assert.AreEqual(notepadsBefore, notepadsAfter);
        }
示例#13
0
        public void DifferentUserProcessShouldNotBeAbleToStartProcess()
        {
            var notepadsBefore = Process.GetProcessesByName("notepad.exe").Count();
            var exePath        = this.CreateExe("StartProcess.exe", StartNotepadProcessSourceCode);

            var process       = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);
            var result        = process.Start(1500, 32 * 1024 * 1024);
            var notepadsAfter = Process.GetProcessesByName("notepad.exe").Count();

            Assert.IsNotNull(result);
            Assert.IsFalse(string.IsNullOrEmpty(result.StandardErrorContent), "No exception is thrown!"); // Exception is thrown
            Assert.AreEqual(notepadsBefore, notepadsAfter);
        }
        private static void ExecuteProcessWithDifferentUser(string applicationPath, string textToWrite, int timeLimit, int memoryLimit)
        {
            try
            {
                var process = new DifferentUserProcessExecutor(applicationPath, Environment.UserDomainName, UserName, Password);
                process.Process.Exited += ProcessOnExited;
                process.SetTextToWrite(textToWrite);
                Console.WriteLine("Chars to write to the process: {0}", process.CharsToWrite.Length);
                Console.WriteLine("Starting sandbox target process...");
                var executionInfo = process.Start(timeLimit, memoryLimit);

                Console.WriteLine("================== Process output ==================");
                Console.WriteLine(executionInfo.StandardOutputContent);

                if (!string.IsNullOrEmpty(executionInfo.StandardErrorContent))
                {
                    Console.WriteLine("================== Process error ===================");
                    Console.WriteLine(executionInfo.StandardErrorContent);
                }

                // Process information
                Console.WriteLine("================== Process info ====================");
                Console.WriteLine(ProcessInfoFormat, "Id:", process.Process.Id);
                Console.WriteLine(ProcessInfoFormat, "HasExited:", process.Process.HasExited);
                Console.WriteLine(ProcessInfoFormat, "ExitCode:", process.Process.ExitCode);
                Console.WriteLine(ProcessInfoFormat, "Error code description:", new Win32Exception(process.Process.ExitCode).Message);
                Console.WriteLine(ProcessInfoFormat, "PriorityClass:", process.Process.PriorityClass);
                Console.WriteLine(ProcessInfoTimeFormat, "StartTime:", process.Process.StartTime);
                Console.WriteLine(ProcessInfoTimeFormat, "ExitTime:", process.Process.ExitTime);
                Console.WriteLine(ProcessInfoFormat, "PrivilegedProcessorTime:", process.Process.PrivilegedProcessorTime);
                Console.WriteLine(ProcessInfoFormat, "UserProcessorTime:", process.Process.UserProcessorTime);
                Console.WriteLine(ProcessInfoFormat, "TotalProcessorTime:", process.Process.TotalProcessorTime);
                Console.WriteLine(ProcessInfoFormat, "ExitTime - StartTime:", process.Process.ExitTime - process.Process.StartTime);
                //// When process is exited no access to: process.BasePriority, process.HandleCount, MaxWorkingSet, etc.
                Console.WriteLine("==================== More info =====================");
                Console.WriteLine(ProcessInfoFormat, "ProcessKilledBecauseOfTimeLimit:", executionInfo.ProcessKilledBecauseOfTimeLimit);
                Console.WriteLine("====================================================");
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex);
                //// throw;
            }
        }
        public void DifferentUserProcessShouldSendInputDataToProcess()
        {
            var exePath = this.CreateExe("InputOutput.exe", ReadInputAndThenOutputSourceCode);

            const string InputData = "SomeInputData!!@#$%^&*(\n";
            var process = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);
            process.SetTextToWrite(InputData);
            var result = process.Start(1000, 32 * 1024 * 1024);

            Assert.IsNotNull(result);
            Assert.AreEqual(InputData.Trim(), result.StandardOutputContent.Trim());
        }
        public void DifferentUserProcessShouldStopProgramAfterTimeIsEnded()
        {
            var exePath = this.CreateExe("TimeLimit.exe", TimeLimitSourceCode);

            var process = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);
            var result = process.Start(100, 32 * 1024 * 1024);

            Assert.IsNotNull(result);
            Assert.IsTrue(result.ProcessKilledBecauseOfTimeLimit);
        }
        public void DifferentUserProcessShouldStandardErrorContentShouldContainExceptions()
        {
            var exePath = this.CreateExe("ThrowException.exe", ThrowExceptionSourceCode);

            var process = new DifferentUserProcessExecutor(exePath, string.Empty, string.Empty, string.Empty);
            var result = process.Start(500, 32 * 1024 * 1024);

            Assert.IsNotNull(result);
            Assert.IsFalse(string.IsNullOrEmpty(result.StandardErrorContent), "StandardErrorContent is empty!"); // Exception is thrown
            Assert.IsTrue(result.StandardErrorContent.Contains("Exception message!"));
        }