static extern SafeKernelObjectHandle CreateRemoteThread(
     SafeKernelObjectHandle hProcess,
     IntPtr lpThreadAttributes,
     IntPtr dwStackSize,
     IntPtr lpStartAddress,
     IntPtr lpParameter,
     int dwCreationFlags,
     OptionalInt32 lpThreadId
     );
Пример #2
0
 internal static extern Win32Error DsCrackSpn(
     string pszSpn,
     [In, Out] OptionalInt32 pcServiceClass,
     [In, Out] StringBuilder ServiceClass,
     [In, Out] OptionalInt32 pcServiceName,
     [In, Out] StringBuilder ServiceName,
     [In, Out] OptionalInt32 pcInstanceName,
     [In, Out] StringBuilder InstanceName,
     [In, Out] OptionalUInt16 pInstancePort
     );
Пример #3
0
 internal static extern SafeKernelObjectHandle CreateRemoteThreadEx(
     SafeKernelObjectHandle hProcess,
     [In] SECURITY_ATTRIBUTES lpThreadAttributes,
     IntPtr dwStackSize,
     IntPtr lpStartAddress,
     IntPtr lpParameter,
     CreateThreadFlags dwCreationFlags,
     SafeBuffer lpAttributeList,
     OptionalInt32 lpThreadId
     );
 internal static extern bool ChangeServiceConfig(
     SafeServiceHandle hService,
     ServiceType dwServiceType,
     ServiceStartType dwStartType,
     ServiceErrorControl dwErrorControl,
     string lpBinaryPathName,
     string lpLoadOrderGroup,
     [Out] OptionalInt32 lpdwTagId,
     string lpDependencies,
     string lpServiceStartName,
     IntPtr lpPassword,
     string lpDisplayName
     );
 internal static extern SafeServiceHandle CreateService(
     SafeServiceHandle hSCManager,
     string lpServiceName,
     string lpDisplayName,
     ServiceAccessRights dwDesiredAccess,
     ServiceType dwServiceType,
     ServiceStartType dwStartType,
     ServiceErrorControl dwErrorControl,
     string lpBinaryPathName,
     string lpLoadOrderGroup,
     [Out] OptionalInt32 lpdwTagId,
     string lpDependencies,
     string lpServiceStartName,
     IntPtr lpPassword
     );
        /// <summary>
        /// Try and parse an SPN string to a class.
        /// </summary>
        /// <param name="spn">The SPN string.</param>
        /// <param name="result">The result class.</param>
        /// <returns>True if the SPN was parsed successfully.</returns>
        /// <exception cref="FormatException">Thrown in invalid SPN.</exception>
        public static bool TryParse(string spn, out ServicePrincipalName result)
        {
            result = null;

            OptionalInt32  cServiceClass = 1;
            StringBuilder  ServiceClass  = new StringBuilder(1);
            OptionalInt32  cServiceName  = 1;
            StringBuilder  ServiceName   = new StringBuilder(1);
            OptionalInt32  cInstanceName = 1;
            StringBuilder  InstanceName  = new StringBuilder(1);
            OptionalUInt16 InstancePort  = 0;

            var err = SecurityNativeMethods.DsCrackSpn(spn, cServiceClass, ServiceClass,
                                                       cServiceName, ServiceName, cInstanceName, InstanceName, InstancePort);

            if (err != Win32Error.ERROR_BUFFER_OVERFLOW)
            {
                return(false);
            }

            ServiceClass = new StringBuilder(cServiceClass.Value);
            ServiceName  = new StringBuilder(cServiceName.Value);
            InstanceName = new StringBuilder(cInstanceName.Value);

            if (SecurityNativeMethods.DsCrackSpn(spn, cServiceClass, ServiceClass,
                                                 cServiceName, ServiceName, cInstanceName, InstanceName, InstancePort) != Win32Error.SUCCESS)
            {
                return(false);
            }

            result = new ServicePrincipalName()
            {
                ServiceClass = ServiceClass.ToString(),
                ServiceName  = ServiceName.ToString(),
                InstanceName = InstanceName.ToString(),
                InstancePort = InstancePort.Value
            };

            return(true);
        }