Esempio n. 1
0
        public void TestRemoteHostAdministratorUserPrivilege()
        {
            NTHost      host = new NTHost(RemoteHostName);
            NTLocalUser user = GetObjectByName(host.GetLocalUsers(), "Administrator");

            Assert.IsTrue(user.Privilege == UserPrivilege.Admin);
        }
Esempio n. 2
0
        public void TestLocalHost()
        {
            NTHost host = NTHost.CurrentMachine;

            Assert.IsNotNull(host);
            Assert.AreEqual(host.Name.ToUpper(), Environment.MachineName.ToUpper());
        }
Esempio n. 3
0
        public void TestRemoteHost()
        {
            NTHost host = new NTHost(RemoteHostName);

            Assert.IsNotNull(host);
            Assert.AreEqual(RemoteHostName.ToUpper(), host.Name.ToUpper());
        }
Esempio n. 4
0
        public void TestLocalHostAdministratorUserPrivilege()
        {
            NTHost      host = NTHost.CurrentMachine;
            NTLocalUser user = GetObjectByName(host.GetLocalUsers(), "Administrator");

            Assert.IsTrue(user.Privilege == UserPrivilege.Admin);
        }
Esempio n. 5
0
        public void TestLocalUserWithSingleGroup()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            NTLocalUser  user  = null;
            NTLocalGroup group = null;

            try {
                group = host.CreateLocalGroup(GenerateGroupName(host), null);
                user  = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");
                user.AddMembership(group.Name);
                Assert.IsTrue(ContainsObjectByName(user.GetMembership(), group.Name));
            } finally {
                try {
                    if (user != null)
                    {
                        user.Delete();
                    }
                } catch {
                }

                try {
                    if (user != null)
                    {
                        group.Delete();
                    }
                } catch {
                }
            }
        }
Esempio n. 6
0
        public void TestLocalGroupDeleteByName()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            NTLocalUser  user  = null;
            NTLocalGroup group = null;

            try {
                group = host.CreateLocalGroup(GenerateGroupName(host), null);
                user  = host.CreateLocalUser(GenerateUserName(host), "P4ssw0rd123");
                group.AddLocalMember(user.Name);
                Assert.IsTrue(ContainsObjectByName(group.GetLocalMembers(), user.Name));
                group.DeleteLocalMember(user.Name);
                CollectionAssert.IsEmpty(group.GetLocalMembers());
            } finally {
                try {
                    if (user != null)
                    {
                        user.Delete();
                    }
                } catch {
                }

                try {
                    if (user != null)
                    {
                        group.Delete();
                    }
                } catch {
                }
            }
        }
Esempio n. 7
0
        private string GenerateGroupName(NTHost host)
        {
            string groupName = "_TmpGrp";

            while (ContainsObjectByName(host.GetLocalGroups(), groupName))
            {
                groupName = "_TmpGrp" + Guid.NewGuid().ToString().Substring(0, 4);
            }
            return(groupName);
        }
Esempio n. 8
0
        private string GenerateUserName(NTHost host)
        {
            string userName = "******";

            while (ContainsObjectByName(host.GetLocalUsers(), userName))
            {
                userName = "******" + Guid.NewGuid().ToString().Substring(0, 4);
            }
            return(userName);
        }
Esempio n. 9
0
        public void TestLocalHostGetPowerUsersGroup()
        {
            NTHost host = NTHost.CurrentMachine;

            Assert.IsTrue(
                ContainsSid(
                    new SecurityIdentifier(WellKnownSidType.BuiltinPowerUsersSid, null),
                    host.GetLocalGroups()
                    )
                );
        }
Esempio n. 10
0
        public void TestLocalHostGetGuest()
        {
            NTHost host = NTHost.CurrentMachine;

            Assert.IsTrue(
                ContainsSid(
                    new SecurityIdentifier(WellKnownSidType.AccountGuestSid, host.SID),
                    host.GetLocalUsers()
                    )
                );
        }
Esempio n. 11
0
        public void TestRemoteHostGetPowerUsersGroup()
        {
            NTHost host = new NTHost(RemoteHostName);

            Assert.IsTrue(
                ContainsSid(
                    new SecurityIdentifier(WellKnownSidType.BuiltinPowerUsersSid, null),
                    host.GetLocalGroups()
                    )
                );
        }
Esempio n. 12
0
        public void TestRemoteHostGetGuest()
        {
            NTHost host = new NTHost(RemoteHostName);

            Assert.IsTrue(
                ContainsSid(
                    new SecurityIdentifier(WellKnownSidType.AccountGuestSid, host.SID),
                    host.GetLocalUsers()
                    )
                );
        }
Esempio n. 13
0
        public void TestRemoteHostGetAdministratorsGroupMembers()
        {
            NTHost host = new NTHost(RemoteHostName);

            NTLocalGroup[] localGroups = host.GetLocalGroups();
            NTLocalGroup   group       = GetObjectByName(localGroups, "Administrators");

            NTLocalObject[] members = group.GetLocalMembers();
            Assert.IsNotNull(members);
            CollectionAssert.IsNotEmpty(members);
        }
Esempio n. 14
0
        public void TestLocalGroupCreateDelete()
        {
            NTHost       host      = NTHost.CurrentMachine;
            string       groupName = GenerateGroupName(host);
            NTLocalGroup group     = host.CreateLocalGroup(groupName, null);

            Assert.IsNotNull(group);
            Assert.IsTrue(ContainsObjectByName(host.GetLocalGroups(), groupName));
            group.Delete();
            Assert.IsFalse(ContainsObjectByName(host.GetLocalGroups(), groupName));
        }
Esempio n. 15
0
        public void TestLocalPersistUserPassword()
        {
            NTHost host  = NTHost.CurrentMachine;
            string value = "AbCn1122CeF123";
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            user.Password = value;
            user.Update();
            user.Delete();
        }
Esempio n. 16
0
        public void TestLocalUserCreateDelete()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            Assert.IsNotNull(user);
            Assert.IsTrue(ContainsObjectByName(host.GetLocalUsers(), userName));
            user.Delete();
            Assert.IsFalse(ContainsObjectByName(host.GetLocalUsers(), userName));
        }
Esempio n. 17
0
        public void TestClass_NTDanglingObject()
        {
            NTHost host = NTHost.CurrentMachine;

            NTDanglingObject obj = new NTDanglingObject(
                host.Name,
                "Name"
                );

            Assert.AreEqual(host.Name, obj.Host);
            Assert.AreEqual("Name", obj.Name);
            Assert.IsNull(obj.SID);
        }
Esempio n. 18
0
        public void TestLocalUserUpdatePrivilege()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                Assert.AreEqual(user.Privilege, UserPrivilege.Guest);
            } finally {
                user.Delete();
            }
        }
Esempio n. 19
0
        public void TestLocalUserUpdatePasswordAge()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                Assert.IsTrue(0 <= user.PasswordAge.TotalSeconds && user.PasswordAge.TotalSeconds <= 2);
            } finally {
                user.Delete();
            }
        }
Esempio n. 20
0
        public void TestLocalUserUpdateLogonServer()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                Assert.AreEqual("\\\\*", user.LogonServer);
            } finally {
                user.Delete();
            }
        }
Esempio n. 21
0
        public void TestLocalUserSIDContainsHostSID()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                Assert.AreEqual(user.SID.AccountDomainSid, host.SID);
            } finally {
                user.Delete();
            }
        }
Esempio n. 22
0
        public void TestLocalUserUpdateSID()
        {
            NTHost host = NTHost.CurrentMachine;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                Assert.IsNotNull(user.SID);
            } finally {
                user.Delete();
            }
        }
Esempio n. 23
0
        public void TestLocalGroupGetDescription()
        {
            NTHost       host        = NTHost.CurrentMachine;
            string       groupName   = GenerateGroupName(host);
            string       description = "Test description";
            NTLocalGroup group       = host.CreateLocalGroup(groupName, description);

            try {
                group = GetObjectByName(host.GetLocalGroups(), groupName);
                Assert.AreEqual(description, group.Description);
            } finally {
                group.Delete();
            }
        }
Esempio n. 24
0
        public void TestClass_NTDanglingObject2()
        {
            NTHost host = NTHost.CurrentMachine;

            NTDanglingObject obj = new NTDanglingObject(
                host.Name,
                host.SID,
                WinAPI.ADVAPI32.SidNameUse.Invalid
                );

            Assert.AreEqual(host.Name, obj.Host);
            Assert.AreEqual(host.SID, obj.SID);
            Assert.AreEqual(WinAPI.ADVAPI32.SidNameUse.Invalid, obj.NameUse);
            Assert.AreEqual(string.Empty, obj.Name);
        }
Esempio n. 25
0
        public void TestLocalHostGetAdministratorsGroup()
        {
            NTHost host = NTHost.CurrentMachine;

            NTLocalGroup[]     localGroups  = host.GetLocalGroups();
            NTLocalGroup       group        = GetObjectByName(localGroups, "Administrators");
            SecurityIdentifier localHostSid = host.SID;
            SecurityIdentifier adminSid     = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, localHostSid);

            Assert.IsTrue(
                ContainsSid(
                    adminSid,
                    host.GetLocalGroups()
                    )
                );
        }
Esempio n. 26
0
        public void TestLocalUserUpdateLastLogon()
        {
            NTHost   host  = NTHost.CurrentMachine;
            DateTime value = DateTime.MinValue;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                user.Update();
                user = GetObjectByName(host.GetLocalUsers(), userName);
                Assert.AreEqual(value, user.LastLogon);
            } finally {
                user.Delete();
            }
        }
Esempio n. 27
0
        public void TestLocalUserUpdateLogonHours()
        {
            NTHost host = NTHost.CurrentMachine;

            byte[] value = new byte[21] {
                1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1
            };
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            user.LogonHours = value;
            user.Update();
            user = GetObjectByName(host.GetLocalUsers(), userName);
            CollectionAssert.AreEqual(user.LogonHours, value);
            user.Delete();
        }
Esempio n. 28
0
        public void TestLocalUserUpdateScriptPath()
        {
            NTHost host  = NTHost.CurrentMachine;
            string value = Process.GetCurrentProcess().StartInfo.FileName;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                user.ScriptPath = value;
                user.Update();
                user = GetObjectByName(host.GetLocalUsers(), userName);
                Assert.AreEqual(user.ScriptPath, value);
            } finally {
                user.Delete();
            }
        }
Esempio n. 29
0
        public void TestLocalUserUpdateHomeDirectory()
        {
            NTHost host  = NTHost.CurrentMachine;
            string value = "c:\\";
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                user.HomeDirectory = value;
                user.Update();
                user = GetObjectByName(host.GetLocalUsers(), userName);
                Assert.AreEqual(user.HomeDirectory, value);
            } finally {
                user.Delete();
            }
        }
Esempio n. 30
0
        public void TestLocalGetUserUnitsPerWeek()
        {
            NTHost host  = NTHost.CurrentMachine;
            uint   value = 5;
            // find a unique user name
            string      userName = GenerateUserName(host);
            NTLocalUser user     = host.CreateLocalUser(userName, "P4ssw0rd123");

            try {
                user.UnitsPerWeek = value;
                user.Update();
                user = GetObjectByName(host.GetLocalUsers(), userName);
                Assert.AreEqual(user.UnitsPerWeek, value);
            } finally {
                user.Delete();
            }
        }