예제 #1
0
 public TOKEN_SOURCE(string name)
 {
     SourceName = new byte[8];
     System.Text.Encoding.GetEncoding(1252).GetBytes(name, 0, name.Length, SourceName, 0);
     if (!ADVAPI32.AllocateLocallyUniqueId(out SourceIdentifier))
     {
         throw new System.ComponentModel.Win32Exception();
     }
 }
예제 #2
0
    public static void CreateNewSession()
    {
        var kli = new SECUR32.KERB_INTERACTIVE_LOGON()
        {
            MessageType = SECUR32.KERB_LOGON_SUBMIT_TYPE.KerbInteractiveLogon,
            UserName    = "",
            Password    = ""
        };
        IntPtr pluid;
        IntPtr lsaHan;
        uint   authPackID;
        IntPtr kerbLogInfo;

        SECUR32.LSA_STRING logonProc = new SECUR32.LSA_STRING()
        {
            Buffer        = Marshal.StringToHGlobalAuto("InstaLogon"),
            Length        = (ushort)Marshal.SizeOf(Marshal.StringToHGlobalAuto("InstaLogon")),
            MaximumLength = (ushort)Marshal.SizeOf(Marshal.StringToHGlobalAuto("InstaLogon"))
        };
        SECUR32.LSA_STRING originName = new SECUR32.LSA_STRING()
        {
            Buffer        = Marshal.StringToHGlobalAuto("InstaLogon"),
            Length        = (ushort)Marshal.SizeOf(Marshal.StringToHGlobalAuto("InstaLogon")),
            MaximumLength = (ushort)Marshal.SizeOf(Marshal.StringToHGlobalAuto("InstaLogon"))
        };
        SECUR32.LSA_STRING authPackage = new SECUR32.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"))
        };
        IntPtr 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);
        SECUR32.LsaLookupAuthenticationPackage(lsaHan, ref authPackage, out authPackID);

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

        var    ts = new SECUR32.TOKEN_SOURCE("Insta");
        IntPtr profBuf;
        uint   profBufLen;
        long   logonID;
        IntPtr logonToken;

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