Пример #1
0
            public static void SetDiskQuotaLimit(string WindowsUsername, string Path, long DiskQuotaBytes)
            {
                var rootPath  = Alphaleonis.Win32.Filesystem.Volume.GetVolumePathName(Path);
                var userQuota = DiskQuotaManager.GetDiskQuotaUser(rootPath, WindowsUsername);

                userQuota.QuotaLimit = DiskQuotaBytes;
            }
Пример #2
0
            public static void SetDiskQuotaLimit(string WindowsUsername, string Path, long DiskQuotaBytes)
            {
                var rootPath  = DiskQuotaManager.GetVolumeRootFromPath(Path);
                var userQuota = DiskQuotaManager.GetDiskQuotaUser(rootPath, WindowsUsername);

                userQuota.QuotaLimit = DiskQuotaBytes;
            }
Пример #3
0
        public override void Init()
        {
            DiskQuotaManager.StartQuotaInitialization();

            while (!DiskQuotaManager.IsQuotaInitialized())
            {
                Thread.Sleep(200);
            }
        }
Пример #4
0
        public override void Apply(Prison prison)
        {
            // Set the disk quota to 0 for all disks, except disk quota path
            var volumesQuotas = GetUserQoutaDiskQuotaManager(prison);

            foreach (var volumeQuota in volumesQuotas)
            {
                volumeQuota.QuotaLimit = 0;
            }

            DiskQuotaManager.SetDiskQuotaLimit(prison.User.Username, prison.Rules.PrisonHomePath, prison.Rules.DiskQuotaBytes);
        }
Пример #5
0
        public override void Apply(Prison prison)
        {
            // Set the disk quota to 0 for all disks, except disk quota path
            var volumesQuotas = DiskQuotaManager.GetDisksQuotaUser(prison.User.Username);

            foreach (var volumeQuota in volumesQuotas)
            {
                volumeQuota.QuotaLimit = 0;
            }

            userQuota            = DiskQuotaManager.GetDiskQuotaUser(DiskQuotaManager.GetVolumeRootFromPath(prison.Rules.PrisonHomePath), prison.User.Username);
            userQuota.QuotaLimit = prison.Rules.DiskQuotaBytes;
        }
Пример #6
0
        public override void Apply(Prison prison)
        {
            if (prison == null)
            {
                throw new ArgumentNullException("prison");
            }

            // Set the disk quota to 0 for all disks, except disk quota path
            var volumesQuotas = GetUserQoutaDiskQuotaManager(prison);

            foreach (var volumeQuota in volumesQuotas)
            {
                volumeQuota.QuotaLimit = 0;
            }

            DiskQuotaManager.SetDiskQuotaLimit(prison.User.UserName, prison.PrisonHomePath, prison.Configuration.DiskQuotaBytes);
        }
Пример #7
0
 private static DIDiskQuotaUser[] GetUserQoutaDiskQuotaManager(Prison prison)
 {
     return(DiskQuotaManager.GetDisksQuotaUser(prison.User.UserName));
 }
Пример #8
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();
        }