예제 #1
0
        /// <summary>
        /// Create process with a token.
        /// </summary>
        /// <param name="token">The token to create the process with.</param>
        /// <param name="config">The process configuration.</param>
        /// <returns>The created win32 process.</returns>
        public static Win32Process CreateProcessAsUser(NtToken token, Win32ProcessConfig config)
        {
            using (var resources = new DisposableList <IDisposable>())
            {
                PROCESS_INFORMATION proc_info   = new PROCESS_INFORMATION();
                STARTUPINFOEX       start_info  = config.ToStartupInfoEx(resources);
                SECURITY_ATTRIBUTES proc_attr   = config.ProcessSecurityAttributes(resources);
                SECURITY_ATTRIBUTES thread_attr = config.ThreadSecurityAttributes(resources);

                if (!CreateProcessAsUser(token.Handle, config.ApplicationName, config.CommandLine,
                                         proc_attr, thread_attr, config.InheritHandles, config.CreationFlags
                                         | CreateProcessFlags.ExtendedStartupInfoPresent, config.Environment,
                                         config.CurrentDirectory, start_info, out proc_info))
                {
                    if (!CreateProcessWithTokenW(token.Handle, 0, config.ApplicationName, config.CommandLine,
                                                 config.CreationFlags, config.Environment, config.CurrentDirectory,
                                                 ref start_info.StartupInfo, out proc_info))
                    {
                        throw new SafeWin32Exception();
                    }
                }

                return(new Win32Process(proc_info, config.TerminateOnDispose));
            }
        }
        /// <summary>
        /// Create process.
        /// </summary>
        /// <param name="config">The process configuration.</param>
        /// <returns>The created win32 process.</returns>
        public static Win32Process CreateProcess(Win32ProcessConfig config)
        {
            if (config.Token != null)
            {
                return(CreateProcessAsUser(config.Token, config));
            }

            PROCESS_INFORMATION proc_info = new PROCESS_INFORMATION();

            using (var resources = new DisposableList <IDisposable>())
            {
                SECURITY_ATTRIBUTES proc_attr   = config.ProcessSecurityAttributes(resources);
                SECURITY_ATTRIBUTES thread_attr = config.ThreadSecurityAttributes(resources);

                using (var debug_object = config.SetDebugObject())
                {
                    if (!Win32NativeMethods.CreateProcess(config.ApplicationName, config.CommandLine, proc_attr, thread_attr, config.InheritHandles,
                                                          config.CreationFlags | CreateProcessFlags.ExtendedStartupInfoPresent,
                                                          config.Environment, config.CurrentDirectory, config.ToStartupInfoEx(resources), out proc_info))
                    {
                        throw new SafeWin32Exception();
                    }
                }

                return(new Win32Process(proc_info, config.TerminateOnDispose));
            }
        }
예제 #3
0
        /// <summary>
        /// Create process with a token.
        /// </summary>
        /// <param name="token">The token to create the process with.</param>
        /// <param name="application_name">The path to the executable.</param>
        /// <param name="command_line">The process command line.</param>
        /// <param name="flags">Process creation flags.</param>
        /// <param name="desktop">The desktop name.</param>
        /// <returns>The created win32 process.</returns>
        public static Win32Process CreateProcessAsUser(NtToken token, string application_name, string command_line, CreateProcessFlags flags, string desktop)
        {
            Win32ProcessConfig config = new Win32ProcessConfig {
                ApplicationName = application_name,
                CommandLine     = command_line,
                CreationFlags   = flags,
                Desktop         = desktop
            };

            return(CreateProcessAsUser(token, config));
        }
예제 #4
0
        /// <summary>
        /// Create process.
        /// </summary>
        /// <param name="parent">Optional parent process.</param>
        /// <param name="application_name">The path to the executable.</param>
        /// <param name="command_line">The process command line.</param>
        /// <param name="flags">Process creation flags.</param>
        /// <param name="desktop">The desktop name.</param>
        /// <returns>The created win32 process.</returns>
        public static Win32Process CreateProcess(NtProcess parent, string application_name, string command_line, CreateProcessFlags flags, string desktop)
        {
            Win32ProcessConfig config = new Win32ProcessConfig {
                ParentProcess   = parent,
                ApplicationName = application_name,
                CommandLine     = command_line,
                CreationFlags   = flags,
                Desktop         = desktop
            };

            return(CreateProcess(config));
        }
예제 #5
0
        public static Win32Process CreateProcessWithLogin(string username, string domain, string password, CreateProcessLogonFlags logon_flags,
                                                          string application_name, string command_line, CreateProcessFlags flags, string desktop)
        {
            Win32ProcessConfig config = new Win32ProcessConfig {
                ApplicationName = application_name,
                CommandLine     = command_line,
                CreationFlags   = flags,
                Desktop         = desktop
            };

            return(CreateProcessWithLogin(username, domain, password, logon_flags, config));
        }
예제 #6
0
        /// <summary>
        /// Create process with a token.
        /// </summary>
        /// <param name="token">The token to create the process with.</param>
        /// <param name="config">The process configuration.</param>
        /// <returns>The created win32 process.</returns>
        public static Win32Process CreateProcessWithToken(NtToken token, Win32ProcessConfig config)
        {
            using (var resources = new DisposableList()) {
                PROCESS_INFORMATION proc_info   = new PROCESS_INFORMATION();
                STARTUPINFO         start_info  = config.ToStartupInfo();
                SECURITY_ATTRIBUTES proc_attr   = config.ProcessSecurityAttributes(resources);
                SECURITY_ATTRIBUTES thread_attr = config.ThreadSecurityAttributes(resources);

                if (!Win32NativeMethods.CreateProcessWithTokenW(token.Handle, config.LogonFlags,
                                                                config.ApplicationName, config.CommandLine,
                                                                config.CreationFlags, config.Environment, config.CurrentDirectory,
                                                                ref start_info, out proc_info))
                {
                    throw new SafeWin32Exception();
                }

                return(new Win32Process(proc_info, config.TerminateOnDispose));
            }
        }
예제 #7
0
        /// <summary>
        /// Create process with a token from a user logon.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="domain">The user's domain.</param>
        /// <param name="password">The user's password.</param>
        /// <param name="logon_flags">Logon flags.</param>
        /// <param name="config">The process configuration.</param>
        /// <returns>The created win32 process.</returns>
        public static Win32Process CreateProcessWithLogin(string username, string domain, string password,
                                                          CreateProcessLogonFlags logon_flags, Win32ProcessConfig config)
        {
            STARTUPINFO         start_info = config.ToStartupInfo();
            PROCESS_INFORMATION proc_info  = new PROCESS_INFORMATION();

            if (!CreateProcessWithLogonW(username, domain, password, logon_flags,
                                         config.ApplicationName, config.CommandLine, config.CreationFlags,
                                         config.Environment, config.CurrentDirectory, ref start_info, out proc_info))
            {
                throw new SafeWin32Exception();
            }

            return(new Win32Process(proc_info, config.TerminateOnDispose));
        }
 /// <summary>
 /// Create process with a token from a user logon.
 /// </summary>
 /// <param name="username">The username.</param>
 /// <param name="domain">The user's domain.</param>
 /// <param name="password">The user's password.</param>
 /// <param name="logon_flags">Logon flags.</param>
 /// <param name="config">The process configuration.</param>
 /// <returns>The created win32 process.</returns>
 public static Win32Process CreateProcessWithLogon(string username, string domain, string password,
                                                   CreateProcessLogonFlags logon_flags, Win32ProcessConfig config)
 {
     using (var creds = new UserCredentials(username, domain, password))
     {
         return(CreateProcessWithLogon(creds, logon_flags, config));
     }
 }
 /// <summary>
 /// Create process with a token from a user logon.
 /// </summary>
 /// <param name="credentials">The user's credentials.</param>
 /// <param name="logon_flags">Logon flags.</param>
 /// <param name="config">The process configuration.</param>
 /// <returns>The created win32 process.</returns>
 public static Win32Process CreateProcessWithLogon(UserCredentials credentials,
                                                   CreateProcessLogonFlags logon_flags, Win32ProcessConfig config)
 {
     return(CreateProcessWithLogon(credentials, logon_flags, config, true).Result);
 }
        /// <summary>
        /// Create process with a token from a user logon.
        /// </summary>
        /// <param name="credentials">The user's credentials.</param>
        /// <param name="logon_flags">Logon flags.</param>
        /// <param name="config">The process configuration.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The created win32 process.</returns>
        public static NtResult <Win32Process> CreateProcessWithLogon(UserCredentials credentials,
                                                                     CreateProcessLogonFlags logon_flags, Win32ProcessConfig config, bool throw_on_error)
        {
            STARTUPINFO         start_info = config.ToStartupInfo();
            PROCESS_INFORMATION proc_info  = new PROCESS_INFORMATION();

            using (var password = credentials.GetPassword())
            {
                return(Win32NativeMethods.CreateProcessWithLogonW(credentials.UserName, credentials.Domain,
                                                                  password, logon_flags, config.ApplicationName, config.CommandLine, config.CreationFlags,
                                                                  config.Environment, config.CurrentDirectory, ref start_info,
                                                                  out proc_info).CreateWin32Result(throw_on_error, () => new Win32Process(proc_info, config.TerminateOnDispose)));
            }
        }