Framework v1.1 & LogonUser workaround

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Framework v1.1 & LogonUser workaround

    Greetings
    I am working on a project that can be configured to use Windows or Forms authentication. Occasionally the process may need to impersonate the calling user

    Using Windows Authentication was fairly easy
    -- ms code snippet -
    System.Security.Principal.WindowsImpersonationCont ext impersonationContext
    impersonationContext = ((System.Security.Principal.WindowsIdentity)User.I dentity).Impersonate()
    ---

    To handle a forms logon
    -- code snippet -
    IntPtr token = IntPtr.Zero
    if(LogonUser(txtUserName.Text, txtDomainName.Text, txtPassword.Text
    LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref token) != 0)

    System.Security.Principal.WindowsImpersonationCont ext impersonationContext
    impersonationContext = System.Security.Principal.WindowsIdentity.Imperson ate(token)


    Of course LogonUser requires that the process have “Act as part of the operating system” permissions, which by default the ASPNET process does not. My confusion comes from reading Microsoft’s patterns and practices, “Building Secure Microsoft ASP.NET Application”. LogonUser is mentioned many times and usually has a warning block stating the above issue and that the .NET Framework v1.1 will work around the issue by having the IIS process perform the logon instead. That doesn’t appear to be the case however. Can anyone confirm if a workaround was in fact implemented

    Thanks
    Bill
    Bill Belliveau Guest

  2. Similar Questions and Discussions

    1. LogonUser from ASP.NET
      Hello everybody, this is rather complicated, but intriguing problem that I have been having. What I want to do is: after user connects to my...
    2. ASP.net & Win32 API (LogonUser) question...
      I am running IIS6 on a Win2k3 server. I have an ASP.Net app (C#) that a user logs into and then I use LogonUser to validate them and log them...
    3. problem with impersonation using LogonUser
      Hello All This is what I am tring to do: I have some folders shared for specific users on network. Now from my web appl I have to access them....
    4. LogonUser API Help
      Hello, I am trying to authenticate a windows user using LogonUser API on our website. I am able to authenticate and impersonate the user just...
    5. Can't get logonuser
      I would like to get user logon from server by USERLog = Request.ServerVariables("LOGON_USER") but it isn't see. i don't know what the...
  3. #2

    Default Re: Framework v1.1 & LogonUser workaround

    In many ways, this is an OS issue. Win2K generally only lets the SYSTEM
    account call LogonUser, as that is the only account by default with the
    SE_TCB_NAME privilege (act as part of the OS), and that is a good thing. In
    WinXP and 2003, LogonUser no longer requires SE_TCB_NAME, so many more
    accounts may call it.

    Framework 1.1 helps with this situation in that there is a nice overload on
    the WindowsIdentity constructor that creates a new WindowsIdentity from
    username/password, but it still doesn't defeat OS security rules.

    The best thing you could do from a security perspective is move to 2K3
    server so that you can call LogonUser without any real issues. On 2000, you
    must run as SYSTEM (or given another account SE_TCB_NAME, essentially making
    it SYSTEM if it wants to be) to do what you want. ASP.NET and IIS let you
    do this, but it is better to avoid it.

    The other thing to do would be to move away from Forms auth. so that you can
    let IIS do the authentication for you, but that doesn't sound like what you
    want.

    I'm not sure if I helped, but hopefully this was useful.

    Joe K.

    "Bill Belliveau" <anonymous@discussions.microsoft.com> wrote in message
    news:24E1DCFE-F4F1-479E-BC13-95B2507E376E@microsoft.com...
    > Greetings.
    > I am working on a project that can be configured to use Windows or Forms
    authentication. Occasionally the process may need to impersonate the
    calling user.
    >
    > Using Windows Authentication was fairly easy:
    > -- ms code snippet --
    > System.Security.Principal.WindowsImpersonationCont ext
    impersonationContext;
    > impersonationContext =
    ((System.Security.Principal.WindowsIdentity)User.I dentity).Impersonate();
    > ----
    >
    > To handle a forms logon:
    > -- code snippet --
    > IntPtr token = IntPtr.Zero;
    > if(LogonUser(txtUserName.Text, txtDomainName.Text, txtPassword.Text,
    > LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref token) != 0)
    > {
    > System.Security.Principal.WindowsImpersonationCont ext
    impersonationContext;
    > impersonationContext =
    System.Security.Principal.WindowsIdentity.Imperson ate(token);
    > }
    >
    > Of course LogonUser requires that the process have "Act as part of the
    operating system" permissions, which by default the ASPNET process does not.
    My confusion comes from reading Microsoft's patterns and practices,
    "Building Secure Microsoft ASP.NET Application". LogonUser is mentioned
    many times and usually has a warning block stating the above issue and that
    the .NET Framework v1.1 will work around the issue by having the IIS process
    perform the logon instead. That doesn't appear to be the case however. Can
    anyone confirm if a workaround was in fact implemented?
    >
    > Thanks,
    > Bill

    Joe Kaplan \(MVP - ADSI\) Guest

  4. #3

    Default Re: Framework v1.1 & LogonUser workaround

    Joe, thanks for the info it does help, mostly to let me know I'm on the right track
    I am curious though, which WindowsIdentity constructor takes a username/password? I didn’t see any constructors or examples. Even though we are targeting 2003, that would seem like a better method rather than calling unmanaged code (even though the same thing happens behind the curtain)

    Bil

    ----- Joe Kaplan (MVP - ADSI) wrote: ----

    In many ways, this is an OS issue. Win2K generally only lets the SYSTE
    account call LogonUser, as that is the only account by default with th
    SE_TCB_NAME privilege (act as part of the OS), and that is a good thing. I
    WinXP and 2003, LogonUser no longer requires SE_TCB_NAME, so many mor
    accounts may call it

    Framework 1.1 helps with this situation in that there is a nice overload o
    the WindowsIdentity constructor that creates a new WindowsIdentity fro
    username/password, but it still doesn't defeat OS security rules

    The best thing you could do from a security perspective is move to 2K
    server so that you can call LogonUser without any real issues. On 2000, yo
    must run as SYSTEM (or given another account SE_TCB_NAME, essentially makin
    it SYSTEM if it wants to be) to do what you want. ASP.NET and IIS let yo
    do this, but it is better to avoid it

    The other thing to do would be to move away from Forms auth. so that you ca
    let IIS do the authentication for you, but that doesn't sound like what yo
    want

    I'm not sure if I helped, but hopefully this was useful

    Joe K.
    Bill Belliveau Guest

  5. #4

    Default Re: Framework v1.1 & LogonUser workaround

    My apologies, but you are right, there is no constructor like that. For
    some reason I remembered seeing that in the reference, but it is fact not
    there at all. I claim temporary insanity!

    I guess it is back to LogonUser. Sorry about that.

    FWIW, there is a nice sample of calling LogonUser via P/Invoke in VB.NET and
    C# here. It is much better than the sample they published for Framework
    1.0:

    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPrincipalWindowsImpersonationCo ntextClassTopic.asp?frame=true[/url]

    Good luck,

    Joe K.

    "Bill Belliveau" <anonymous@discussions.microsoft.com> wrote in message
    news:ADEB1A74-56A1-46DC-995F-4EC005F56C44@microsoft.com...
    > Joe, thanks for the info it does help, mostly to let me know I'm on the
    right track.
    > I am curious though, which WindowsIdentity constructor takes a
    username/password? I didn't see any constructors or examples. Even though
    we are targeting 2003, that would seem like a better method rather than
    calling unmanaged code (even though the same thing happens behind the
    curtain).
    >
    > Bill
    >
    > ----- Joe Kaplan (MVP - ADSI) wrote: -----
    >
    > In many ways, this is an OS issue. Win2K generally only lets the
    SYSTEM
    > account call LogonUser, as that is the only account by default with
    the
    > SE_TCB_NAME privilege (act as part of the OS), and that is a good
    thing. In
    > WinXP and 2003, LogonUser no longer requires SE_TCB_NAME, so many
    more
    > accounts may call it.
    >
    > Framework 1.1 helps with this situation in that there is a nice
    overload on
    > the WindowsIdentity constructor that creates a new WindowsIdentity
    from
    > username/password, but it still doesn't defeat OS security rules.
    >
    > The best thing you could do from a security perspective is move to
    2K3
    > server so that you can call LogonUser without any real issues. On
    2000, you
    > must run as SYSTEM (or given another account SE_TCB_NAME, essentially
    making
    > it SYSTEM if it wants to be) to do what you want. ASP.NET and IIS
    let you
    > do this, but it is better to avoid it.
    >
    > The other thing to do would be to move away from Forms auth. so that
    you can
    > let IIS do the authentication for you, but that doesn't sound like
    what you
    > want.
    >
    > I'm not sure if I helped, but hopefully this was useful.
    >
    > Joe K.

    Joe Kaplan \(MVP - ADSI\) Guest

  6. #5

    Default Re: Framework v1.1 & LogonUser workaround

    Thanks again
    Bill

    ----- Joe Kaplan (MVP - ADSI) wrote: -----

    My apologies, but you are right, there is no constructor like that. For
    some reason I remembered seeing that in the reference, but it is fact not
    there at all. I claim temporary insanity!

    I guess it is back to LogonUser. Sorry about that.

    FWIW, there is a nice sample of calling LogonUser via P/Invoke in VB.NET and
    C# here. It is much better than the sample they published for Framework
    1.0:

    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemSecurityPrincipalWindowsImpersonationCo ntextClassTopic.asp?frame=true[/url]

    Good luck,

    Joe K.
    Bill Belliveau Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139