コード例 #1
0
 public TOKEN_SOURCE(string name)
 {
     SourceName = new byte[8];
     Encoding.GetEncoding(1252).GetBytes(name, 0, name.Length, SourceName, 0);
     if (!ADVAPI32.AllocateLocallyUniqueId(out SourceIdentifier))
     {
         throw new Win32Exception();
     }
 }
コード例 #2
0
        public static void CreateNewSession()
        {
            var kli = new KERB_INTERACTIVE_LOGON
            {
                MessageType = KERB_LOGON_SUBMIT_TYPE.KerbInteractiveLogon,
                UserName    = "",
                Password    = ""
            };
            IntPtr pluid;
            IntPtr lsaHan;
            uint   authPackID;
            IntPtr kerbLogInfo;
            var    logonProc = new LSA_STRING
            {
                Buffer        = Marshal.StringToHGlobalAuto("InstaLogon"),
                Length        = (ushort)Marshal.SizeOf(Marshal.StringToHGlobalAuto("InstaLogon")),
                MaximumLength = (ushort)Marshal.SizeOf(Marshal.StringToHGlobalAuto("InstaLogon"))
            };
            var originName = new LSA_STRING
            {
                Buffer        = Marshal.StringToHGlobalAuto("InstaLogon"),
                Length        = (ushort)Marshal.SizeOf(Marshal.StringToHGlobalAuto("InstaLogon")),
                MaximumLength = (ushort)Marshal.SizeOf(Marshal.StringToHGlobalAuto("InstaLogon"))
            };
            var authPackage = new LSA_STRING
            {
                Buffer        = Marshal.StringToHGlobalAuto("MICROSOFT_KERBEROS_NAME_A"),
                Length        = (ushort)Marshal.SizeOf(Marshal.StringToHGlobalAuto("MICROSOFT_KERBEROS_NAME_A")),
                MaximumLength = (ushort)Marshal.SizeOf(Marshal.StringToHGlobalAuto("MICROSOFT_KERBEROS_NAME_A"))
            };
            var hLogonProc = Marshal.AllocHGlobal(Marshal.SizeOf(logonProc));

            Marshal.StructureToPtr(logonProc, hLogonProc, false);
            ADVAPI32.AllocateLocallyUniqueId(out pluid);
            LsaConnectUntrusted(out lsaHan);
            //SECUR32.LsaRegisterLogonProcess(hLogonProc, out lsaHan, out secMode);
            LsaLookupAuthenticationPackage(lsaHan, ref authPackage, out authPackID);

            kerbLogInfo = Marshal.AllocHGlobal(Marshal.SizeOf(kli));
            Marshal.StructureToPtr(kli, kerbLogInfo, false);

            var            ts = new TOKEN_SOURCE("Insta");
            IntPtr         profBuf;
            uint           profBufLen;
            long           logonID;
            IntPtr         logonToken;
            QUOTA_LIMITS   quotas;
            WinStatusCodes subStatus;

            LsaLogonUser(lsaHan, ref originName, SecurityLogonType.Interactive, authPackID, kerbLogInfo,
                         (uint)Marshal.SizeOf(kerbLogInfo), IntPtr.Zero, ref ts, out profBuf, out profBufLen, out logonID,
                         out logonToken, out quotas, out subStatus);
        }