Impersonation with NTLM

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

  1. #1

    Default Impersonation with NTLM

    I want to use impersonation within a second thread of an httpwebrequest.
    While configuring IIS with basic authentication everything works fine.
    Changing to Intergrated Windows Authentication the thread (which should return a secure web-page) returns the http status code 401.

    My web.config looks like:
    .....
    <identity impersonate="true"/><authentication mode="Windows" />
    .....


    My Testpage looks like:

    dim url as String = "https://server/secure/index.html"
    dim Req as HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)

    Req.Method = "GET"
    Req.ContentType = "application/x-www-form-urlencoded;charset=iso-8859-1"
    Req.PreAuthenticate = true

    if Request.ServerVariables("AUTH_TYPE") = "Basic"
    Req.Credentials = new System.Net.NetworkCredential(Request.ServerVariabl es("AUTH_USER"),Request.ServerVariables("AUTH_PASS WORD"))
    else
    Req.Credentials = CredentialCache.DefaultCredentials
    ' Should impersonate the user in case of NTLM, shouldn't it???
    end if

    dim Resp as HttpWebResponse = DirectCast(req.GetResponse(),HttpWebResponse)
    dim Reader as StreamReader

    Reader = new StreamReader(Resp.GetResponseStream())

    while Reader.Peek() > -1
    strLine = Reader.ReadLine()
    Trace.write(strLine)
    end while

    Reader.Close()
    Resp.Close()

    The included thread should impersonate the logged-on user (NTLM or Basic).

    What did I do wrong?

    Thomas
    Thomas Mueller-Lynch Guest

  2. Similar Questions and Discussions

    1. NTLM API Authentication
      Hi, I'm totally novice when it comes to authentication protocols. Here is what is needed to be done: Create a web service which calls the NTLM API...
    2. NTLM & Load Balancing
      It does not seem to be possible to host an NTLM (or Kerberos) authenticated web service without enabling HTTP Keep-Alives (to enable the...
    3. NTLM Authentication Across Forests
      I have a problem that I've spent a considerable amount of time researching and still haven't quite found the answer. I have an intranet web...
    4. NTLM Login
      Hi, I'm using NTLM/NTFS security for users to login to a site with ASP on W2K. Is there a way I can log a user out with script when he hits a...
    5. NTLM Username?
      sVar = Request.SErvervariables("LOGON_USER") Ray at work "Rob Wiltbank" <wynder@warcry.com> wrote in message...
  3. #2

    Default Re: Impersonation with NTLM

    At a guess, you are trying to do a "double hop" in that, you have used
    windows auth/NTLM to logon to your web app, then that same security token to
    go to another web site on another machine. Using NTLM, you cannot
    impersonate a user, then use that impersonation to authenticate to another
    machine (this is the double hop). Basic works because the credentials are
    propagated in clear text as part of the Http header. NTLM used a security
    token and cannot propagate the same token and be valid.

    Kerberos can do it, but you still need to mark the user account as
    "Delegateable". (Win2000+)
    --
    - Paul Glavich


    "Thomas Mueller-Lynch" <thomas.mueller-lynch(remove)@siemens.com> wrote in
    message news:D73319EC-F94A-4EFF-871A-E3D15F4909A8@microsoft.com...
    > I want to use impersonation within a second thread of an httpwebrequest.
    > While configuring IIS with basic authentication everything works fine.
    > Changing to Intergrated Windows Authentication the thread (which should
    return a secure web-page) returns the http status code 401.
    >
    > My web.config looks like:
    > ...
    > <identity impersonate="true"/><authentication mode="Windows" />
    > ...
    >
    >
    > My Testpage looks like:
    >
    > dim url as String = "https://server/secure/index.html"
    > dim Req as HttpWebRequest = DirectCast(WebRequest.Create(url),
    HttpWebRequest)
    >
    > Req.Method = "GET"
    > Req.ContentType = "application/x-www-form-urlencoded;charset=iso-8859-1"
    > Req.PreAuthenticate = true
    >
    > if Request.ServerVariables("AUTH_TYPE") = "Basic"
    > Req.Credentials = new
    System.Net.NetworkCredential(Request.ServerVariabl es("AUTH_USER"),Request.Se
    rverVariables("AUTH_PASSWORD"))
    > else
    > Req.Credentials = CredentialCache.DefaultCredentials
    > ' Should impersonate the user in case of NTLM, shouldn't it???
    > end if
    >
    > dim Resp as HttpWebResponse =
    DirectCast(req.GetResponse(),HttpWebResponse)
    > dim Reader as StreamReader
    >
    > Reader = new StreamReader(Resp.GetResponseStream())
    >
    > while Reader.Peek() > -1
    > strLine = Reader.ReadLine()
    > Trace.write(strLine)
    > end while
    >
    > Reader.Close()
    > Resp.Close()
    >
    > The included thread should impersonate the logged-on user (NTLM or Basic).
    >
    > What did I do wrong?
    >
    > Thomas

    Paul Glavich Guest

  4. #3

    Default Re: Impersonation with NTLM

    It may still be suffering the "double hop" syndrome if it thinks that the
    page you are trying to access (even though its on the same machine) is on
    another machine. when you specify the "host" part of the URL is it as you
    specified below (ie. [url]https://server/[/url]....) or does it contain periods (eg.
    [url]https://my.server/...)?[/url]

    Also, try it without using SSL (ie. [url]http://server/[/url]....) to see what happens.

    --
    - Paul Glavich


    "Thomas Mueller-Lynch" <thomas.mueller-lynch(remove)@siemens.com> wrote in
    message news:C6C4D26E-9B93-4326-97F3-B78534E7EFA2@microsoft.com...
    > In this case I have only one server.
    > the aspx page which is running on my server is executing another page on
    the same server.
    >
    > Any ideas? Thanks in advance
    >
    > Thomas Mueller-Lynch
    >
    > ----- Paul Glavich wrote: -----
    >
    > At a guess, you are trying to do a "double hop" in that, you have
    used
    > windows auth/NTLM to logon to your web app, then that same security
    token to
    > go to another web site on another machine. Using NTLM, you cannot
    > impersonate a user, then use that impersonation to authenticate to
    another
    > machine (this is the double hop). Basic works because the credentials
    are
    > propagated in clear text as part of the Http header. NTLM used a
    security
    > token and cannot propagate the same token and be valid.
    >
    > Kerberos can do it, but you still need to mark the user account as
    > "Delegateable". (Win2000+)
    > --
    > - Paul Glavich
    >
    >
    > "Thomas Mueller-Lynch" <thomas.mueller-lynch(remove)@siemens.com>
    wrote in
    > message news:D73319EC-F94A-4EFF-871A-E3D15F4909A8@microsoft.com...
    > > I want to use impersonation within a second thread of an
    httpwebrequest.
    > > While configuring IIS with basic authentication everything works
    fine.
    > > Changing to Intergrated Windows Authentication the thread (which
    should
    > return a secure web-page) returns the http status code 401.
    > >> My web.config looks like:
    > > ...
    > ><identity impersonate="true"/><authentication mode="Windows" />> ...
    > >>> My Testpage looks like:
    > >> dim url as String = "https://server/secure/index.html"
    > > dim Req as HttpWebRequest = DirectCast(WebRequest.Create(url),
    > HttpWebRequest)
    > >> Req.Method = "GET"
    > > Req.ContentType =
    "application/x-www-form-urlencoded;charset=iso-8859-1"
    > > Req.PreAuthenticate = true
    > >> if Request.ServerVariables("AUTH_TYPE") = "Basic"
    > > Req.Credentials = new
    >
    System.Net.NetworkCredential(Request.ServerVariabl es("AUTH_USER"),Request.Se
    > rverVariables("AUTH_PASSWORD"))
    > > else
    > > Req.Credentials = CredentialCache.DefaultCredentials
    > > ' Should impersonate the user in case of NTLM, shouldn't it???
    > > end if
    > >> dim Resp as HttpWebResponse =
    > DirectCast(req.GetResponse(),HttpWebResponse)
    > > dim Reader as StreamReader
    > >> Reader = new StreamReader(Resp.GetResponseStream())
    > >> while Reader.Peek() > -1
    > > strLine = Reader.ReadLine()
    > > Trace.write(strLine)
    > > end while
    > >> Reader.Close()
    > > Resp.Close()
    > >> The included thread should impersonate the logged-on user (NTLM or
    Basic).
    > >> What did I do wrong?
    > >> Thomas
    >
    >
    >

    Paul Glavich 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