Пример #1
0
        public ReleaseInfo GetReleaseInfo(ProcessPrison prison)
        {
            string exe = GetExecutable(Path.Combine(this.path, "bin"), "release");

            string outputPath = Path.Combine(this.cacheDir, "release.yml");
            string script     = string.Format("{0} {1} > {2} 2>&1", exe, this.appDir, outputPath);

            var runInfo = new ProcessPrisonRunInfo();

            runInfo.WorkingDirectory = Path.Combine(this.appDir);
            runInfo.FileName         = null;
            runInfo.Arguments        = script;
            Process process = prison.RunProcess(runInfo);

            process.WaitForExit(5000);

            string output = File.ReadAllText(outputPath);

            File.Delete(outputPath);
            using (var reader = new StringReader(output))
            {
                Deserializer deserializer = new Deserializer();
                return((ReleaseInfo)deserializer.Deserialize(reader, typeof(ReleaseInfo)));
            }
        }
Пример #2
0
        public Process StartCompile(ProcessPrison prison)
        {
            string exe  = GetExecutable(Path.Combine(path, "bin"), "compile");
            string args = string.Format("{0} {1} >> {2} 2>&1", this.appDir, this.cacheDir, this.logFile);

            Logger.Debug("Running compile script {0} {1}", exe, args);

            var runInfo = new ProcessPrisonRunInfo();

            runInfo.WorkingDirectory = Path.Combine(this.appDir);
            runInfo.FileName         = null;
            runInfo.Arguments        = string.Format("{0} {1}", exe, args);
            return(prison.RunProcess(runInfo));
        }
Пример #3
0
        public bool Detect(ProcessPrison prison)
        {
            string exe = GetExecutable(Path.Combine(this.path, "bin"), "detect");

            string outputPath = Path.Combine(this.cacheDir, "detect.yml");
            string script     = string.Format("{0} {1} > {2} 2>&1", exe, this.appDir, outputPath);

            Logger.Debug("Running detect script: {0}", script);
            var runInfo = new ProcessPrisonRunInfo();

            runInfo.WorkingDirectory = Path.Combine(this.appDir);
            runInfo.FileName         = null;
            runInfo.Arguments        = script;
            Process process = prison.RunProcess(runInfo);

            process.WaitForExit(5000);
            if (!process.HasExited)
            {
                process.Kill();
            }
            if (File.Exists(outputPath))
            {
                this.detectOutput = File.ReadAllText(outputPath);
                Logger.Debug("Detect output: {0}", this.detectOutput);
                File.Delete(outputPath);
            }
            if (process.ExitCode == 0)
            {
                return(true);
            }
            else
            {
                Logger.Warning("Detect process exited with {0}", process.ExitCode);
                return(false);
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("--- PrisonProcess REPL ---\n");
            Console.WriteLine("Use the following keys:");
            Console.WriteLine("\tc: Create a new cmd prison");
            Console.WriteLine("\tn: Create a new notepad prison");
            Console.WriteLine("\td: Destroy all prissons");
            Console.WriteLine("\tq: Quit");

            List <ProcessPrison> prisonss = new List <ProcessPrison>();

            DiskQuotaManager.StartQuotaInitialization();
            while (!DiskQuotaManager.IsQuotaInitialized())
            {
                Thread.Sleep(100);
            }


            var usersDesc = WindowsUsersAndGroups.GetUsersDescription();

            foreach (var desc in usersDesc.Values)
            {
                try
                {
                    var id = ProcessPrison.GetIdFromUserDescription(desc);

                    var ppci = new ProcessPrisonCreateInfo();
                    ppci.Id = id;
                    ppci.TotalPrivateMemoryLimitBytes = 128 * 1024 * 1024;
                    ppci.DiskQuotaBytes = 128 * 1024 * 1024;
                    ppci.DiskQuotaPath  = @"C:\Users\Public";
                    // Cannot impersonate the user to create new processes or access the user's env.
                    ppci.WindowsPassword = "******";

                    var pp = new ProcessPrison();
                    pp.Attach(ppci);

                    prisonss.Add(pp);
                }
                catch (ArgumentException)
                {
                }
            }

            while (true)
            {
                var key = Console.ReadKey();
                if (key.Key == ConsoleKey.Q && key.Modifiers == ConsoleModifiers.Shift)
                {
                    break;
                }

                switch (key.Key)
                {
                case ConsoleKey.C:
                {
                    var ppci = new ProcessPrisonCreateInfo();
                    ppci.TotalPrivateMemoryLimitBytes = 128 * 1000 * 1000;
                    ppci.DiskQuotaBytes = 128 * 1024 * 1024;
                    ppci.DiskQuotaPath  = @"C:\Users\Public";
                    ppci.NetworkOutboundRateLimitBitsPerSecond = 80 * 1000;

                    var pp = new ProcessPrison();
                    pp.Create(ppci);
                    pp.SetUsersEnvironmentVariable("prison", pp.Id);

                    var ri = new ProcessPrisonRunInfo();
                    ri.Interactive = true;
                    ri.FileName    = @"C:\Windows\System32\cmd.exe";
                    ri.Arguments   = String.Format(" /k  title {1} & echo Wedcome to prisson {0}. & echo Running under user {1} & echo Private virtual memory limit: {2} B", pp.Id, pp.WindowsUsername, ppci.TotalPrivateMemoryLimitBytes);
                    ri.Arguments  += " & echo. & echo Cmd bomb for memory test: & echo 'set loop=cmd /k ^%loop^%' & echo 'cmd /k %loop%'";
                    ri.Arguments  += " & echo. & echo Ruby file server for network test: & echo 'rackup -b 'run Rack::Directory.new(\"\")''";

                    pp.RunProcess(ri);

                    prisonss.Add(pp);
                }
                break;

                case ConsoleKey.N:
                {
                    var ppci = new ProcessPrisonCreateInfo();
                    ppci.TotalPrivateMemoryLimitBytes = 128 * 1024 * 1024;
                    ppci.DiskQuotaBytes = 128 * 1024 * 1024;
                    ppci.DiskQuotaPath  = @"C:\Users\Public";

                    var pp = new ProcessPrison();
                    pp.Create(ppci);
                    pp.SetUsersEnvironmentVariable("prison", pp.Id);

                    var ri = new ProcessPrisonRunInfo();
                    ri.Interactive = true;
                    ri.FileName    = @"C:\Windows\System32\notepad.exe";

                    pp.RunProcess(ri);

                    prisonss.Add(pp);
                }
                break;

                case ConsoleKey.D:
                    foreach (var prison in prisonss)
                    {
                        prison.Destroy();
                    }
                    prisonss.Clear();
                    break;

                case ConsoleKey.Q:
                    return;
                }
            }

            var createInfo = new ProcessPrisonCreateInfo();

            var p = new ProcessPrison();

            p.Create(createInfo);
            var envs = p.GetUsersEnvironmentVariables();

            var runInfo = new ProcessPrisonRunInfo();

            runInfo.Interactive = false;
            runInfo.FileName    = @"C:\Windows\System32\cmd.exe";
            runInfo.FileName    = @"C:\Windows\System32\PING.EXE";
            // runInfo.Arguments = @"/c echo %PATH% & ping 10.0.0.10" ;
            runInfo.Arguments = @" /k rackup -b ""run lambda {|env| [200, {'Content-Type'=>'text/html'}, 'Hello World']}"" -P 2345";

            runInfo.Arguments        = " 10.0.0.10 -t";
            runInfo.WorkingDirectory = @"C:\Users\Public";
            runInfo.FileName         = @"C:\Windows\System32\mspaint.exe";
            runInfo.Arguments        = "";


            p.RunProcess(runInfo);

            //p.RunProcess(@"C:\Windows\System32\mspaint.exe");

            Console.ReadKey();

            p.Destroy();
        }