Example #1
0
 public static List <string> GetUsersWithPrivilege(string Privilege)
 {
     using (var LSA = new LsaWrapper())
     {
         return(LSA.ReadPrivilege(Privilege));
     }
 }
Example #2
0
        /// <summary>
        /// Sets a privilege for the user.
        /// </summary>
        /// <param name="user">The username as domain\user. if domain is not provide machine name is used</param>
        /// <param name="privilege">The privilege to set. <see cref="LsaWrapper"/></param>
        /// <param name="remoteComputer">Can be used to execute on a remote computer.</param>
        public static void SetPrivilege(string user, string privilege, string remoteComputer = null)
        {
            user = ComputerManager.EnsureDomain(user);
            using (LsaWrapper lsa = new LsaWrapper(remoteComputer))
            {
                Trace.WriteLine(string.Format("Setting Privilege {0} for user {1}", privilege, user));
                lsa.AddPrivileges(user, privilege);
            }

        }
        public override IEnumerable <CommandDTOBase?> Execute(string[] args)
        {
            if (!SecurityUtil.IsHighIntegrity())
            {
                WriteHost("Must be an administrator to enumerate User Right Assignments");
                yield break;
            }

            var        computerName = "localhost";
            string     filter       = null;
            LsaWrapper lsa          = null;

            if (args.Length >= 1)
            {
                computerName = args[0];
            }

            if (args.Length >= 2)
            {
                filter = ".*" + args[1] + ".*";
            }

            try
            {
                lsa = new LsaWrapper(computerName);
            }
            catch (UnauthorizedAccessException)
            {
                WriteError("Insufficient privileges");
                yield break;
            }
            catch (Exception e)
            {
                WriteError("Unhandled exception enumerating user right assignments: " + e);
                yield break;
            }

            var privilegeSet = filter == null ? _defaultPrivileges : _allPrivileges.Where(p => Regex.IsMatch(p, filter, RegexOptions.IgnoreCase)).ToArray();

            foreach (var priv in privilegeSet)
            {
                var principals = lsa.ReadPrivilege(priv);

                yield return(new UserRightAssignmentsDTO()
                {
                    Right = priv,
                    Principals = principals
                });
            }

            if (lsa != null)
            {
                lsa.Dispose();
            }
        }
Example #4
0
 /// <summary>
 /// Login as a given user and return the login token
 /// </summary>
 /// <param name="user">The user: domain\user</param>
 /// <param name="password">The password.</param>
 /// <param name="remoteComputer">The remote computer.</param>
 /// <returns></returns>
 internal static IntPtr Login(string user, string password, string remoteComputer = null)
 {
     if (string.IsNullOrWhiteSpace(user) || string.IsNullOrWhiteSpace(password))
         return IntPtr.Zero;
     user = ComputerManager.EnsureDomain(user);
     var domainUser = ComputerManager.SplitUserAndDomain(user);
     Trace.WriteLine(string.Format("Attempting Logon as {0}\\{1}", domainUser.Item1, domainUser.Item2));
     using (LsaWrapper lsa = new LsaWrapper(remoteComputer))
     {
         IntPtr token;
         if (lsa.Logon(domainUser.Item1, domainUser.Item2, password, out token))
             return token;
     }
     return IntPtr.Zero;
 }
        public void Server(string cmd)
        {
            Console.WriteLine("Command received : {0}", cmd);

            Commands command;

            Enum.TryParse(cmd, out command);

            switch (command)
            {
            case Commands.Dashboard:
            {
                Console.WriteLine("Command received in server : {0}", command);
                string jsonData = getDashboard();
                Clients.All.ReceiveDashboardData(jsonData);
                break;
            }

            case Commands.ConfigFiles:
            {
                Console.WriteLine("Command received in server : {0}", command);
                string jsonData = getAllConfigFiles();
                Clients.All.ReceiveConfigFilesData(jsonData);
                break;
            }

            case Commands.Ping:
            {
                Console.WriteLine("Command received in server : {0}", command);
                Clients.All.ReceivePong("Pong");
                Console.WriteLine("Command Sent : Pong");
                break;
            }

            case Commands.SaveConfigFile:
            {
                Console.WriteLine("Command received in server : {0}", command);
                Clients.All.GetConfData("Send file");
                break;
            }

            case Commands.EVTAppLog:
            {
                int    evtLogCount;
                string eventLogName = "Application";
                string sourceName   = "UiPath";
                string machineName  = System.Environment.MachineName;

                EventLog eventLog = new EventLog();
                eventLog.Log         = eventLogName;
                eventLog.Source      = sourceName;
                eventLog.MachineName = machineName;

                var result = (from EventLogEntry elog in eventLog.Entries
                              where (elog.TimeGenerated >= DateTime.Now.AddDays(-5))
                              where (elog.Source.ToString().Equals("UiPath") || elog.Source.ToString().Equals("UiRobotSvc") || elog.Source.ToString().Equals(".NET Runtime") || elog.Source.ToString().Equals("Application Error"))
                              orderby elog.TimeGenerated descending
                              select elog).ToList();

                evtLogCount = result.Count;
                List <string> EVTMSGDetails  = new List <string>();
                List <string> EVTSRCDetails  = new List <string>();
                List <string> EVTTimeDetails = new List <string>();
                List <string> EVTEntryType   = new List <string>();

                for (int i = 0; i < evtLogCount; i++)
                {
                    EVTMSGDetails.Add(result[i].Message);
                    EVTSRCDetails.Add(result[i].Source);
                    EVTTimeDetails.Add(Convert.ToString(result[i].TimeGenerated));
                    EVTEntryType.Add(Convert.ToString(result[i].EntryType));
                }

                var ls = new List <List <string> > {
                    EVTSRCDetails, EVTTimeDetails, EVTEntryType, EVTMSGDetails
                };


                string jsonData = JsonConvert.SerializeObject(ls);
                Clients.All.ReceiveEVTAppLogData(jsonData);
                break;
            }

            case Commands.EVTSecLog:
            {
                int    evtLogCount;
                string machineName = System.Environment.MachineName;

                EventLog eventLog = new EventLog("Security");
                //eventLog.Log = eventLogName;
                eventLog.MachineName = machineName;

                var result = (from EventLogEntry elog in eventLog.Entries
                              where (elog.TimeGenerated >= DateTime.Now.AddDays(-5))
                              orderby elog.TimeGenerated descending
                              select elog).ToList();

                evtLogCount = result.Count;
                List <string> EVTMSGDetails  = new List <string>();
                List <string> EVTSRCDetails  = new List <string>();
                List <string> EVTTimeDetails = new List <string>();
                List <string> EVTEntryType   = new List <string>();

                //int maxRecords = 1000;
                if (evtLogCount > 1000)
                {
                    evtLogCount = 1000;
                }

                for (int i = 0; i < evtLogCount; i++)
                {
                    // Console.WriteLine();
                    // Console.WriteLine(result[i].Message);
                    EVTMSGDetails.Add(result[i].Message);
                    EVTSRCDetails.Add(result[i].Source);
                    EVTTimeDetails.Add(Convert.ToString(result[i].TimeGenerated));
                    EVTEntryType.Add(Convert.ToString(result[i].EntryType));
                }

                var ls = new List <List <string> > {
                    EVTSRCDetails, EVTTimeDetails, EVTEntryType, EVTMSGDetails
                };
                string jsonData = JsonConvert.SerializeObject(ls);
                Clients.All.ReceiveEVTSecLogData(jsonData);
                break;
            }

            case Commands.EnableTrace:
            {
                string path = @"C:\Program Files (x86)\UiPath\Studio";
                string ack  = string.Empty;
                if (Directory.Exists(path))
                {
                    string command1 = "UiRobot.exe --enableLowLevel";
                    try
                    {
                        var proc1 = new ProcessStartInfo();
                        // string anyCommand;
                        proc1.UseShellExecute = true;

                        proc1.WorkingDirectory = @"C:\Program Files (x86)\UiPath\Studio";

                        proc1.FileName    = "cmd.exe";
                        proc1.Verb        = "runas";
                        proc1.Arguments   = "/c " + command1;
                        proc1.WindowStyle = ProcessWindowStyle.Hidden;
                        Process.Start(proc1);
                        ack = "LowLevelEnabled";
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error : Make sure UiPath is installed! : " + ex.Message);
                    }
                }

                string jsonData = JsonConvert.SerializeObject(ack);
                Clients.All.ReceiveENABLEETLData(jsonData);
                break;
            }

            case Commands.DisableTrace:
            {
                string path = @"C:\Program Files (x86)\UiPath\Studio";
                string ack  = string.Empty;
                if (Directory.Exists(path))
                {
                    string command1 = "UiRobot.exe --disableLowLevel";
                    try
                    {
                        var proc1 = new ProcessStartInfo();
                        // string anyCommand;
                        proc1.UseShellExecute = true;

                        proc1.WorkingDirectory = @"C:\Program Files (x86)\UiPath\Studio";

                        proc1.FileName    = "cmd.exe";
                        proc1.Verb        = "runas";
                        proc1.Arguments   = "/c " + command1;
                        proc1.WindowStyle = ProcessWindowStyle.Hidden;
                        Process.Start(proc1);
                        ack = "LowLevelDisabled";
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error : Make sure UiPath is installed! : " + ex.Message);
                    }
                }
                string jsonData = JsonConvert.SerializeObject(ack);
                Clients.All.ReceiveDISABLEETLData(jsonData);
                break;
            }

            case Commands.DiagnosticLog:
            {
                string path = @"C:\Program Files (x86)\UiPath\Studio";
                string ack  = string.Empty;
                if (Directory.Exists(path))
                {
                    string command1 = "UiPath.DiagTool.exe --file=C:\\logs.zip";
                    try
                    {
                        var proc1 = new ProcessStartInfo();
                        // string anyCommand;
                        proc1.UseShellExecute = true;

                        proc1.WorkingDirectory = @"C:\Program Files (x86)\UiPath\Studio";

                        proc1.FileName    = "cmd.exe";
                        proc1.Verb        = "runas";
                        proc1.Arguments   = "/c " + command1;
                        proc1.WindowStyle = ProcessWindowStyle.Hidden;
                        Process.Start(proc1);
                        ack = "DiagToolSuccess";
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error : Make sure UiPath is installed! : " + ex.Message);
                    }
                }
                string jsonData = JsonConvert.SerializeObject(ack);
                Clients.All.ReceiveDIAGTOOLData(jsonData);
                break;
            }

            case Commands.DoNothing:
            {
                Console.WriteLine("Command received in server : {0}", command);
                Clients.All.ReceiveCommand("Command sent to client : " + command);
                break;
            }

            case Commands.Stop:
            {
                Console.WriteLine("Command received in server : {0}", command);
                Clients.All.StopConnection("Command sent to stop connection");
                break;
            }

            case Commands.GroupPolicy:
            {
                Console.WriteLine("Command received in server : {0}", command);
                string[] policyNames = { "Log on as a batch job",
                                         "Deny Log on as a batch job",
                                         "Deny log on locally",
                                         "Deny access to this computer from the network",
                                         "Deny log on through Remote Desktop Services",
                                         "Deny log on as a service",
                                         "Allow Log on locally",
                                         "Access to this computer from the network",
                                         "Allow log on through Remote Desktop Services" };

                Dictionary <string, string> ps = new Dictionary <string, string>();
                LsaWrapper LSA = new LsaWrapper("localhost");
                foreach (string policy in policyNames)
                {
                    string policyName = String.Empty;
                    switch (policy)
                    {
                    case "Log on as a batch job":
                        policyName = "SeBatchLogonRight";
                        break;

                    case "Deny Log on as a batch job":
                        policyName = "SeDenyBatchLogonRight";
                        break;

                    case "Deny log on locally":
                        policyName = "SeDenyInteractiveLogonRight";
                        break;

                    case "Deny access to this computer from the network":
                        policyName = "SeDenyNetworkLogonRight";
                        break;

                    case "Deny log on through Remote Desktop Services":
                        policyName = "SeDenyRemoteInteractiveLogonRight";
                        break;

                    case "Deny log on as a service":
                        policyName = "SeDenyServiceLogonRight";
                        break;

                    case "Allow Log on locally":
                        policyName = "SeInteractiveLogonRight";
                        break;

                    case "Access to this computer from the network":
                        policyName = "SeNetworkLogonRight";
                        break;

                    case "Allow log on through Remote Desktop Services":
                        policyName = "SeRemoteInteractiveLogonRight";
                        break;

                    default: break;
                    }

                    string account = "";

                    List <String> Accounts = LSA.ReadPrivilege(policyName);
                    foreach (string val in Accounts)
                    {
                        account = account + val + ", ";
                    }
                    if (!(account == null) && account != "")
                    {
                        account = account.Substring(0, account.LastIndexOf(','));
                    }
                    if (account == "")
                    {
                        account = "--";
                    }

                    ps.Add(policy, account);
                }
                string jsonData = JsonConvert.SerializeObject(ps);
                Clients.All.ReceiveGroupPolicyData(jsonData);
                break;
            }
            }
        }