// Returns a list of IDs of all prisoners who match the given predicate public static int[] FindPrisoners(Prison prison, Predicate <Prisoner> predicate) { return(prison.Objects.Prisoners.Values .Where(prisoner => predicate(prisoner)) .Select(prisoner => prisoner.Id) .ToArray()); }
public void PrisonApplyNetworkAppTest() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); PrisonTestsHelper.ApplyNetworkRuleFakes(); ManagementObject mobj = null; ShimManagementObject.AllInstances.Put = (@this) => { mobj = @this; return(new ShimManagementPath()); }; Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.CellType |= RuleType.Network; prisonRules.UrlPortAccess = 56444; prisonRules.AppPortOutboundRateLimitBitsPerSecond = 500; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); Assert.AreEqual(mobj["ThrottleRateAction"].ToString(), 500.ToString()); Assert.IsTrue(mobj["URIMatchCondition"].ToString().Contains(56444.ToString())); } }
public void StopForkBombs() { Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.Memory; // prisonRules.CellType = RuleType.WindowStation; prisonRules.CPUPercentageLimit = 2; prisonRules.TotalPrivateMemoryLimitBytes = 50 * 1024 * 1024; prisonRules.PrisonHomePath = @"c:\prison_tests\p7"; prisonRules.ActiveProcessesLimit = 5; prison.Lockdown(prisonRules); Process process = prison.Execute("", "cmd /c for /L %n in (1,0,10) do ( start cmd /k echo 32 )"); // Wait for the bomb to explode while (true) { if (prison.JobObject.ActiveProcesses >= 4) { break; } Thread.Sleep(100); } Thread.Sleep(500); Assert.IsTrue(prison.JobObject.ActiveProcesses < 6); prison.Destroy(); }
public void TestMultipleEcho() { // Arrange Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = CellType.None; prison.Lockdown(prisonRules); // Act Process process1 = prison.Execute( @"c:\windows\system32\cmd.exe", @"/c echo test"); Process process2 = prison.Execute( @"c:\windows\system32\cmd.exe", @"/c echo test"); // Assert Assert.AreNotEqual(0, process1.Id); Assert.AreNotEqual(0, process2.Id); }
public void AllowAccessInHomeDir() { // Arrange Prison.Init(); Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = CellType.Filesystem; prisonRules.PrisonHomePath = @"C:\Workspace\dea_security\PrisonHome"; prison.Lockdown(prisonRules); // Act string exe = Utilities.CreateExeForPrison( @" File.WriteAllText(Guid.NewGuid().ToString(""N""), Guid.NewGuid().ToString()); ", prison); Process process = prison.Execute(exe); process.WaitForExit(); // Assert Assert.AreEqual(0, process.ExitCode); }
public override void Apply(Prison prison) { if (prison == null) { throw new ArgumentNullException("prison"); } WindowsUsersAndGroups.AddUserToGroup(prison.User.UserName, prisonRestrictionsGroup); if (Directory.Exists(prison.PrisonHomePath)) { prison.User.Profile.UnloadUserProfileUntilReleased(); Directory.Delete(prison.PrisonHomePath, true); } Directory.CreateDirectory(prison.PrisonHomePath); DirectoryInfo deploymentDirInfo = new DirectoryInfo(prison.PrisonHomePath); DirectorySecurity deploymentDirSecurity = deploymentDirInfo.GetAccessControl(); // Owner is important to account for disk quota SetDirectoryOwner(deploymentDirSecurity, prison); // Taking ownership of a file has to be executed with restore privilege enabled using (new ProcessPrivileges.PrivilegeEnabler(Process.GetCurrentProcess(), ProcessPrivileges.Privilege.Restore)) { deploymentDirInfo.SetAccessControl(deploymentDirSecurity); } }
public void PrisonChange(Prison newPrison) { _monAffichage.transform.Find(CurrentPrison.ToString()).gameObject.SetActive(false); _monAffichage.transform.Find(newPrison.ToString()).gameObject.SetActive(true); CurrentPrison = newPrison; }
public void TestExitCode() { // Arrange Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.CellType |= RuleType.Filesystem; prisonRules.PrisonHomePath = String.Format(@"c:\prison_tests\{0}", prison.ID); prison.Lockdown(prisonRules); // Act Process process = prison.Execute( @"c:\windows\system32\cmd.exe", @"/c exit 667"); process.WaitForExit(); prison.Destroy(); // Assert Assert.AreEqual(667, process.ExitCode); }
public void TestMultipleEcho() { // Arrange Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.PrisonHomePath = String.Format(@"c:\prison_tests\{0}", prison.ID); prison.Lockdown(prisonRules); // Act Process process1 = prison.Execute( @"c:\windows\system32\cmd.exe", @"/c echo test"); Process process2 = prison.Execute( @"c:\windows\system32\cmd.exe", @"/c echo test"); // Assert Assert.AreNotEqual(0, process1.Id); Assert.AreNotEqual(0, process2.Id); prison.Destroy(); }
public void AssignNewDesktop() { // Arrange Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.WindowStation; prisonRules.PrisonHomePath = String.Format(@"c:\prison_tests\{0}", prison.ID); prison.Lockdown(prisonRules); // Act string exe = Utilities.CreateExeForPrison( string.Format(@" byte[] name = new byte[1024]; uint actualLength; GetUserObjectInformation(GetProcessWindowStation(), UOI_NAME, name, 1024, out actualLength); string workstationName = ASCIIEncoding.ASCII.GetString(name, 0, (int)actualLength - 1); if (workstationName != ""{0}"") {{ return 1; }} return 0; }} [DllImport(""user32.dll"", SetLastError = true)] public static extern bool GetUserObjectInformation(IntPtr hObj, int nIndex, [Out] byte[] pvInfo, uint nLength, out uint lpnLengthNeeded); [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] [DllImport(""user32"", CharSet = CharSet.Unicode, SetLastError = true)] internal static extern IntPtr GetProcessWindowStation(); public const int UOI_FLAGS = 1; public const int UOI_NAME = 2; public const int UOI_TYPE = 3; public const int UOI_USER_SID = 4; public const int UOI_HEAPSIZE = 5; //Windows Server 2003 and Windows XP/2000: This value is not supported. public const int UOI_IO = 6; private static int Dummy() {{ ", prison.User.Username), prison); Process process = prison.Execute(exe, "", false); process.WaitForExit(); prison.Destroy(); // Assert Assert.AreEqual(0, process.ExitCode); }
public void DenyExcesiveMemory() { // Arrange Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.Memory; prisonRules.TotalPrivateMemoryLimitBytes = 50 * 1024 * 1024; prisonRules.PrisonHomePath = @"C:\Workspace\dea_security\PrisonHome"; prison.Lockdown(prisonRules); // Act string exe = Utilities.CreateExeForPrison( @" byte[] memory = new byte[100 * 1024 * 1024]; Random rnd = new Random(); rnd.NextBytes(memory); ", prison); Process process = prison.Execute(exe); process.WaitForExit(); // Assert Assert.AreNotEqual(0, process.ExitCode); }
public void DenyExcesiveDiskUsage() { // Arrange Prison.Init(); Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = CellType.Disk; prisonRules.DiskQuotaBytes = 50 * 1024 * 1024; prisonRules.PrisonHomePath = @"C:\Workspace\dea_security\PrisonHome"; prison.Lockdown(prisonRules); // Act string exe = Utilities.CreateExeForPrison( @" for (int size = 1; size < 100; size++) {{ byte[] content = new byte[1024 * 1024]; File.AppendAllText(Guid.NewGuid().ToString(""N""), ASCIIEncoding.ASCII.GetString(content)); }}", prison); Process process = prison.Execute(exe); process.WaitForExit(); // Assert Assert.AreNotEqual(0, process.ExitCode); }
public async Task <Coin> OutpointToCoinAsync(InputRegistrationRequest request, CancellationToken cancellationToken) { OutPoint input = request.Input; if (Prison.TryGet(input, out var inmate) && (!Config.AllowNotedInputRegistration || inmate.Punishment != Punishment.Noted)) { throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.InputBanned); } var txOutResponse = await Rpc.GetTxOutAsync(input.Hash, (int)input.N, includeMempool : true, cancellationToken).ConfigureAwait(false); if (txOutResponse is null) { throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.InputSpent); } if (txOutResponse.Confirmations == 0) { throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.InputUnconfirmed); } if (txOutResponse.IsCoinBase && txOutResponse.Confirmations <= 100) { throw new WabiSabiProtocolException(WabiSabiProtocolErrorCode.InputImmature); } return(new Coin(input, txOutResponse.TxOut)); }
public override void Lockdown(Prison prison) { Native.SECURITY_ATTRIBUTES secAttributes = new Native.SECURITY_ATTRIBUTES(); secAttributes.nLength = Marshal.SizeOf(secAttributes); IntPtr windowStation = Native.CreateWindowStation(prison.User.Username, 0, Native.WINDOWS_STATION_ACCESS_MASK.WINSTA_NONE, null); IntPtr desktop = IntPtr.Zero; lock (windowStationLock) { IntPtr currentWindowStation = Native.GetProcessWindowStation(); bool setOk = Native.SetProcessWindowStation(windowStation); if (!setOk) { throw new Win32Exception(Marshal.GetLastWin32Error()); } Native.CreateDesktop(prison.User.Username, null, null, 0, Native.ACCESS_MASK.DESKTOP_CREATEWINDOW, null); prison.ProcessStartupInfo.lpDesktop = string.Format(@"{0}\{0}", prison.User.Username); Native.SetProcessWindowStation(currentWindowStation); } }
// Loads the entire Prison with a certain level public void BuildAndLoadPrison() { Debug.Log("BuildAndLoadPrison"); string PrisonLevelLabel = "P" + PrisonSelected + "_L" + LevelSelected + "_"; List<Phase> LevelPhases = new List<Phase>(); bool FoundCurrentTask = false; for(int i = 1; i < 5; i++) // 4 phases in each level { int taskInPhase = LevelTracker.GetNumberOfTasksInPhase (PrisonLevelLabel + "PH" + i + "_TN"); // Get # tasks in phase List<Task> Tasks = new List<Task>(); for (int j = 1; j < taskInPhase + 1; j++) { Task TaskToCheck = new Task(PrisonSelected, LevelSelected, i, j); if(!TaskToCheck.IsTaskCompleted() && !FoundCurrentTask) { CurrentTask = TaskToCheck; FoundCurrentTask = true; } Tasks.Add(TaskToCheck); } LevelPhases.Add (new Phase(PrisonSelected, LevelSelected, i, Tasks)); } Level Level = new Level(PrisonSelected, LevelSelected, LevelPhases); CurrentLevel = Level; List<Level> Levels = new List<Level>(); Prison Prison = new Prison(PrisonSelected, Levels); CurrentPrison = Prison; GameManager.ObjectiveScreen.ResetAll(); // Signal the Task Tracker that everything is ready for action GameManager.TaskTracker.Initialize(); }
public void StopForkBombs() { Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.Memory; // prisonRules.CellType = RuleType.WindowStation; prisonRules.CPUPercentageLimit = 2; prisonRules.TotalPrivateMemoryLimitBytes = 50 * 1024 * 1024; prisonRules.PrisonHomePath = @"c:\prison_tests\p7"; prisonRules.ActiveProcessesLimit = 5; prison.Lockdown(prisonRules); Process process = prison.Execute("", "cmd /c for /L %n in (1,0,10) do ( start cmd /k echo 32 )"); // Wait for the bomb to explode while (true) { if (prison.JobObject.ActiveProcesses >= 4) break; Thread.Sleep(100); } Thread.Sleep(500); Assert.IsTrue(prison.JobObject.ActiveProcesses < 6); prison.Destroy(); }
void miFileOpen_Click(object sender, EventArgs e) { if (openDialog.ShowDialog() == DialogResult.OK) { fileName = openDialog.FileName; using (FileStream fs = File.OpenRead(openDialog.FileName)) { Text = String.Format("Loading {0} | {1}", Path.GetFileName(fileName), AppName); try { prison = new Parser().Load(fs); } catch (Exception ex) { string msg = String.Format("An error occured while loading:{0}{1}{0}{2}", Environment.NewLine, ex.GetType().Name, ex.Message); MessageBox.Show(msg, String.Format("Error loading {0}", Path.GetFileName(fileName)), MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } if (prison.Version != Parser.SupportedVersion) { MessageBox.Show(String.Format(Resources.FileVersionWarning, Parser.SupportedVersion, prison.Version)); } LoadPrisonToGui(); Enabled = true; Text = String.Format("{0} | {1}", Path.GetFileName(fileName), AppName); } } else { if (prison == null) { Close(); } } }
public void TestLockdown() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); string createdUser = null; string userProfileDestination = null; bool saveWasInvoked = false; ShimWindowsUsersAndGroups.CreateUserStringString = (username, password) => { createdUser = username; return; }; ShimPrison.AllInstances.ChangeRegistryUserProfileString = (pris, destination) => { userProfileDestination = destination; return; }; ShimXmlObjectSerializer.AllInstances.WriteObjectStreamObject = (data, writeStream, fakePrison) => { saveWasInvoked = true; return; }; Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); Assert.AreEqual(createdUser, prison.User.Username); Assert.IsTrue(createdUser.Contains(prison.Tag)); // The user profile has to be moved in the prison home dir Assert.IsTrue(userProfileDestination.Contains(prisonRules.PrisonHomePath)); Assert.IsTrue(saveWasInvoked); } }
public void PrisonApplyNetworkAppTest() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); PrisonTestsHelper.ApplyNetworkRuleFakes(); ManagementObject mobj = null; ShimManagementObject.AllInstances.Put = (@this) => { mobj = @this; return new ShimManagementPath(); }; Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.CellType |= RuleType.Network; prisonRules.UrlPortAccess = 56444; prisonRules.AppPortOutboundRateLimitBitsPerSecond = 500; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); Assert.AreEqual(mobj["ThrottleRateAction"].ToString(), 500.ToString()); Assert.IsTrue(mobj["URIMatchCondition"].ToString().Contains(56444.ToString())); } }
public void DenyExcesiveDiskUsage() { // Arrange Prison.Init(); Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.Disk; prisonRules.DiskQuotaBytes = 50 * 1024 * 1024; prisonRules.PrisonHomePath = @"C:\Workspace\dea_security\PrisonHome"; prison.Lockdown(prisonRules); // Act string exe = Utilities.CreateExeForPrison( @" for (int size = 1; size < 100; size++) {{ byte[] content = new byte[1024 * 1024]; File.AppendAllText(Guid.NewGuid().ToString(""N""), ASCIIEncoding.ASCII.GetString(content)); }}", prison); Process process = prison.Execute(exe); process.WaitForExit(); // Assert Assert.AreNotEqual(0, process.ExitCode); }
public void DenyExcesiveMemory() { // Arrange Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = CellType.Memory; prisonRules.TotalPrivateMemoryLimitBytes = 50 * 1024 * 1024; prisonRules.PrisonHomePath = @"C:\Workspace\dea_security\PrisonHome"; prison.Lockdown(prisonRules); // Act string exe = Utilities.CreateExeForPrison( @" byte[] memory = new byte[100 * 1024 * 1024]; Random rnd = new Random(); rnd.NextBytes(memory); ", prison); Process process = prison.Execute(exe); process.WaitForExit(); // Assert Assert.AreNotEqual(0, process.ExitCode); }
public Arena(TimeSpan period, Network network, WabiSabiConfig config, IRPCClient rpc, Prison prison) : base(period) { Network = network; Config = config; Rpc = rpc; Prison = prison; Random = new SecureRandom(); }
public void CreatePrison(Prison prison) { if (prison != null) { _context.Add(prison); _context.SaveChanges(); } }
protected override void Load() { Instance = this; Prison = new Prison(); UnturnedPlayerEvents.OnPlayerDeath += onPlayerDeath; U.Events.OnPlayerConnected += onPlayerConnected; }
public ArenaRequestHandler(WabiSabiConfig config, Prison prison, Arena arena, IRPCClient rpc) { Config = config; Prison = prison; Arena = arena; Rpc = rpc; Network = rpc.Network; }
public override void Apply(Prison prison) { Native.SECURITY_ATTRIBUTES secAttributes = new Native.SECURITY_ATTRIBUTES(); secAttributes.nLength = Marshal.SizeOf(secAttributes); IntPtr windowStation = IntPtr.Zero; windowStation = Native.OpenWindowStation(prison.User.Username, false, Native.WINDOWS_STATION_ACCESS_MASK.WINSTA_CREATEDESKTOP); int openWinStaStatus = Marshal.GetLastWin32Error(); // Error 0x2 is ERROR_FILE_NOT_FOUND // http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx if (windowStation == IntPtr.Zero && openWinStaStatus != 0x2) { throw new Win32Exception(Marshal.GetLastWin32Error()); } if (windowStation == IntPtr.Zero && openWinStaStatus == 0x2) { // TODO SECURITY: change security attributes. the default will give everyone access to the object including other prisons windowStation = Native.CreateWindowStation(prison.User.Username, 0, Native.WINDOWS_STATION_ACCESS_MASK.WINSTA_CREATEDESKTOP, null); if (windowStation == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error()); } } lock (windowStationContextLock) { IntPtr currentWindowStation = Native.GetProcessWindowStation(); try { bool setOk = Native.SetProcessWindowStation(windowStation); if (!setOk) { throw new Win32Exception(Marshal.GetLastWin32Error()); } // TODO SECURITY: change security attributes. the default will give everyone access to the object including other prisons var desktop = Native.CreateDesktop("Default", null, null, 0, Native.ACCESS_MASK.DESKTOP_CREATEWINDOW, null); if (desktop == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error()); } prison.desktopName = string.Format(@"{0}\Default", prison.User.Username); } finally { Native.SetProcessWindowStation(currentWindowStation); } } }
public override void Apply(Prison prison) { Native.SECURITY_ATTRIBUTES secAttributes = new Native.SECURITY_ATTRIBUTES(); secAttributes.nLength = Marshal.SizeOf(secAttributes); IntPtr windowStation = IntPtr.Zero; windowStation = NativeOpenWindowStation(prison.User.Username); int openWinStaStatus = Marshal.GetLastWin32Error(); // Error 0x2 is ERROR_FILE_NOT_FOUND // http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382%28v=vs.85%29.aspx if (windowStation == IntPtr.Zero && openWinStaStatus != 0x2) { throw new Win32Exception(Marshal.GetLastWin32Error()); } if (windowStation == IntPtr.Zero && openWinStaStatus == 0x2) { // TODO SECURITY: change security attributes. the default will give everyone access to the object including other prisons windowStation = NativeCreateWindowStation(prison.User.Username); if (windowStation == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error()); } } lock (windowStationContextLock) { IntPtr currentWindowStation = NativeGetProcessWindowStation(); try { bool setOk = NativeSetProcessWindowStation(windowStation); if (!setOk) { throw new Win32Exception(Marshal.GetLastWin32Error()); } // TODO SECURITY: change security attributes. the default will give everyone access to the object including other prisons var desktop = NativeCreateDesktop(); if (desktop == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error()); } prison.desktopName = string.Format(@"{0}\Default", prison.User.Username); } finally { NativeSetProcessWindowStation(currentWindowStation); } } }
public override void Destroy(Prison prison) { if (prison == null) { throw new ArgumentNullException("prison"); } Httpsys.RemovePortAccess(prison.Configuration.UrlPortAccess, true); }
public void SetProperties() { GameObject gameObject = Selection.activeGameObject; Prison myPrison = gameObject.GetComponent <Prison>(); myPrison.door = gameObject.GetComponentInChildren <Door>(); myPrison.bed = gameObject.transform.GetChild(1).gameObject; myPrison.toilet = gameObject.transform.GetChild(2).gameObject; }
// Schedules all prisoners who match the given predicate for release public static int Release(Prison prison, Predicate <Prisoner> predicate) { int[] idsToRemove = FindPrisoners(prison, predicate); foreach (int id in idsToRemove) { ReleasePrisoner(prison, id); } return(idsToRemove.Length); }
public void PrisonTestCleanup() { if (prison != null) { prison.Destroy(); prison.Dispose(); prison = null; } }
public void EmptyPrison() { var p = new Prison(); Assert.Empty(p.GetInmates()); Assert.Equal(0, p.CountInmates().noted); Assert.Equal(0, p.CountInmates().banned); Assert.False(p.TryGet(BitcoinFactory.CreateOutPoint(), out _)); }
public override void Destroy(Prison prison) { if (prison == null) { throw new ArgumentNullException("prison"); } Network.RemoveOutboundThrottlePolicy(prison.User.UserName); Network.RemoveOutboundThrottlePolicy(PrisonUser.GlobalPrefix + PrisonUser.Separator + prison.Configuration.UrlPortAccess.ToString(CultureInfo.InvariantCulture)); }
public Container(Prison prison) { if (prison == null) { throw new ArgumentNullException("prison"); } this.prison = prison; this.Id = prison.Id.ToString(); }
public void SavePrison() { // Arrange // Act Prison prison = new Prison(); // Assert Assert.IsTrue(Prison.Load().Any(p => p.ID == prison.ID)); }
private void Start() { normalSpeed = 10; speed = normalSpeed; FastForwardSpeedMultiplier = 2; SprintMuliplier = 1.5f; rb = GetComponent <Rigidbody>(); pPrison = PrisonArchive.instance.GetFreePrison(); this.transform.position = pPrison.transform.position; }
public override void Apply(Prison prison) { if (prison == null) { throw new ArgumentNullException("prison"); } Httpsys.RemovePortAccess(prison.Configuration.UrlPortAccess, true); Httpsys.AddPortAccess(prison.Configuration.UrlPortAccess, prison.User.UserName); }
public int ExecuteProcess(Prison prison, string filename, string arguments, Dictionary<string, string> extraEnvironmentVariables) { // To debug the service uncomment the following line: // Debugger.Launch(); prison.Reattach(); var p = prison.InitializeProcess(filename, arguments, false, extraEnvironmentVariables); return p.Id; }
public override void Apply(Prison prison) { Network.CreateOutboundThrottlePolicy(prison.User.Username, prison.User.Username, prison.Rules.NetworkOutboundRateLimitBitsPerSecond); if (prison.Rules.UrlPortAccess > 0) { Network.RemoveOutboundThrottlePolicy(PrisonUser.GlobalPrefix + PrisonUser.Separator + prison.Rules.UrlPortAccess.ToString()); Network.CreateOutboundThrottlePolicy(PrisonUser.GlobalPrefix + PrisonUser.Separator + prison.Rules.UrlPortAccess.ToString(), prison.Rules.UrlPortAccess, prison.Rules.AppPortOutboundRateLimitBitsPerSecond); } }
public void TestSimpleEcho() { using (ShimsContext.Create()) { // shim Prison.Lockdown PrisonTestsHelper.PrisonLockdownFakes(); Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); // shim Prison.Execute Native.PROCESS_INFORMATION processInfo = new Native.PROCESS_INFORMATION { hProcess = new IntPtr(2400), hThread = new IntPtr(2416), dwProcessId = 5400, dwThreadId = 4544 }; PrisonTestsHelper.PrisonCreateProcessAsUserFakes(processInfo); ShimPrison.GetCurrentSessionId = () => { return 0; }; var shimedProcess = new ShimProcess(); shimedProcess.IdGet = () => { return processInfo.dwProcessId; }; var raisingEventsChangedTo = false; shimedProcess.EnableRaisingEventsSetBoolean = (value) => { raisingEventsChangedTo = value; }; ShimProcess.GetProcessByIdInt32 = (id) => { return (Process)shimedProcess; }; Process procAddedToJob = null; ShimJobObject.AllInstances.AddProcessProcess = (jobObject, proc) => { procAddedToJob = proc; return; }; ShimPrison.AllInstances.AddProcessToGuardJobObjectProcess = (fakePrison, proc) => { return; }; var processIdResumed = 0; ShimPrison.AllInstances.ResumeProcessProcess = (fakePrison, pProcess) => { processIdResumed = pProcess.Id; }; // Act Process process = prison.Execute( @"c:\windows\system32\cmd.exe", @"/c echo test"); // Assert Assert.AreEqual(processInfo.dwProcessId, process.Id); Assert.AreEqual(processInfo.dwProcessId, processIdResumed); Assert.AreEqual(procAddedToJob.Id, process.Id); Assert.AreEqual(true, raisingEventsChangedTo); } }
public void PrisonInitIISGroupTest() { using (ShimsContext.Create()) { PrisonTestsHelper.InitFilesystemRuleFakes(); Prison prison = new Prison(); prison.Tag = "uhtst"; Prison.Init(); } }
public override void Lockdown(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; }
public override void Apply(Prison prison) { if (prison == null) { throw new ArgumentNullException("prison"); } Network.CreateOutboundThrottlePolicy(prison.User.UserName, prison.User.UserName, prison.Configuration.NetworkOutboundRateLimitBitsPerSecond); if (prison.Configuration.UrlPortAccess > 0) { Network.RemoveOutboundThrottlePolicy(PrisonUser.GlobalPrefix + PrisonUser.Separator + prison.Configuration.UrlPortAccess.ToString(CultureInfo.InvariantCulture)); Network.CreateOutboundThrottlePolicy(PrisonUser.GlobalPrefix + PrisonUser.Separator + prison.Configuration.UrlPortAccess.ToString(CultureInfo.InvariantCulture), prison.Configuration.UrlPortAccess, prison.Configuration.AppPortOutboundRateLimitBitsPerSecond); } }
public override void Apply(Prison prison) { if (prison == null) { throw new ArgumentNullException("prison"); } if (WindowsUsersAndGroups.ExistsGroup(IISGroupName)) { WindowsUsersAndGroups.AddUserToGroup(prison.User.UserName, IISGroupName); } else { Logger.Warning("Prison {0} not added to IIS Users group {1}. The group was not found.", prison.Id, IISGroupName); } }
public void PrisonApplyWindowStationTest() { using (ShimsContext.Create()) { int winStationPtr = 2658; PrisonTestsHelper.PrisonLockdownFakes(); PrisonTestsHelper.ApplyWindowStationRuleFakes(winStationPtr); string username = null; ShimWindowStation.NativeOpenWindowStationString = (user) => { username = user; return new IntPtr(winStationPtr); }; ShimWindowStation.NativeCreateWindowStationString = (user) => { username = user; return new IntPtr(winStationPtr); }; Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.CellType |= RuleType.WindowStation; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); Native.PROCESS_INFORMATION processInfo = new Native.PROCESS_INFORMATION { hProcess = new IntPtr(2400), hThread = new IntPtr(2416), dwProcessId = 5400, dwThreadId = 4544 }; PrisonTestsHelper.PrisonCreateProcessAsUserFakes(processInfo); ShimPrison.GetCurrentSessionId = () => { return 0; }; ShimProcess.GetProcessByIdInt32 = (id) => { return new Process(); }; ShimJobObject.AllInstances.AddProcessProcess = (jobObject, proc) => { return; }; ShimPrison.AllInstances.AddProcessToGuardJobObjectProcess = (fakePrison, proc) => { return; }; ShimPrison.AllInstances.ResumeProcessProcess = (fakePrison, pProcess) => { }; Process process = prison.Execute( @"c:\windows\system32\cmd.exe", @"/c echo test"); Assert.AreEqual(prison.desktopName, string.Format(@"{0}\Default", username)); } }
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); }
public void PrisonApplyIISGroupTest() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); PrisonTestsHelper.ApplyIISGroupFakes(); Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.CellType |= RuleType.IISGroup; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); } }
public void PrisonReattachFilesystemTest() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); PrisonTestsHelper.ApplyFilesystemFakes(); Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.CellType |= RuleType.Filesystem; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); prison.Reattach(); } }