Home All Groups Group Topic Archive Search About
Author
17 Mar 2006 9:04 PM
William Stacey [MVP]
If your a service as say Admin or Local System, can you impersonate other
users without their password (i.e. run a thread with their WindowsIdentity)?
TIA.

--
William Stacey [MVP]

Author
17 Mar 2006 9:37 PM
Joe Kaplan (MVP - ADSI)
It depends.  If the user is a domain user AND your current OS is 2003+ AND
your AD is 2003 native mode, then you can use protocol transition (S4U auth)
to create a WindowsIdentity (using the constructor that takes the UPN) and
you can impersonate that.  In order to access local resources, the caller
must have the TCB privilege, but SYSTEM will have that by default.

Note that an identity created this way can also be used for impersonation to
access remote resources via delegation.  You have to use constrained
delegation here and the calling account needs to be enabled for delegation
with "any protocol".  This setting is also orthogonal to needing the TCB
privilege to access local resources, in that you might be able to delegate
to a remote service without having the rights to access local resources.
However, in my experience, a lot of .NET code will end up accessing at least
one local file or registry key in the process of doing any kind of remote
operation, so you tend to end up needing access to local resources to
perform the call to access remote ones.

Otherwise, there is no way that I'm aware of to do this unless you possibly
write your own SSPI provider.  Ick.

Joe K.

Show quoteHide quote
"William Stacey [MVP]" <william.sta***@gmail.com> wrote in message
news:%23L$tqZgSGHA.5908@TK2MSFTNGP14.phx.gbl...
> If your a service as say Admin or Local System, can you impersonate other
> users without their password (i.e. run a thread with their
> WindowsIdentity)?
> TIA.
>
> --
> William Stacey [MVP]
>
>
>
Author
20 Mar 2006 12:35 AM
William Stacey [MVP]
Thanks Joe.  Any bit of code to get the idea going for me?  Will need file
access with user ACLs, run process with user ACLs, maybe registry.  Do I
need to use something like the AuthentiatedStream class on the server side
to login and get a WindowsIdentity passing a null password or something?  I
could not find any examples in this specific area (i.e. no pwd).

--
William Stacey [MVP]

Show quoteHide quote
"Joe Kaplan (MVP - ADSI)" <joseph.e.kap***@removethis.accenture.com> wrote
in message news:%23bCJCsgSGHA.736@TK2MSFTNGP12.phx.gbl...
| It depends.  If the user is a domain user AND your current OS is 2003+ AND
| your AD is 2003 native mode, then you can use protocol transition (S4U
auth)
| to create a WindowsIdentity (using the constructor that takes the UPN) and
| you can impersonate that.  In order to access local resources, the caller
| must have the TCB privilege, but SYSTEM will have that by default.
|
| Note that an identity created this way can also be used for impersonation
to
| access remote resources via delegation.  You have to use constrained
| delegation here and the calling account needs to be enabled for delegation
| with "any protocol".  This setting is also orthogonal to needing the TCB
| privilege to access local resources, in that you might be able to delegate
| to a remote service without having the rights to access local resources.
| However, in my experience, a lot of .NET code will end up accessing at
least
| one local file or registry key in the process of doing any kind of remote
| operation, so you tend to end up needing access to local resources to
| perform the call to access remote ones.
|
| Otherwise, there is no way that I'm aware of to do this unless you
possibly
| write your own SSPI provider.  Ick.
|
| Joe K.
|
| "William Stacey [MVP]" <william.sta***@gmail.com> wrote in message
| news:%23L$tqZgSGHA.5908@TK2MSFTNGP14.phx.gbl...
| > If your a service as say Admin or Local System, can you impersonate
other
| > users without their password (i.e. run a thread with their
| > WindowsIdentity)?
| > TIA.
| >
| > --
| > William Stacey [MVP]
| >
| >
| >
|
|
Author
20 Mar 2006 2:34 AM
Joe Kaplan (MVP - ADSI)
You just use the WindowsIdentity constructor that takes the user's UPN
(single string parameter).  Once you have that, you just call the
impersonate method.  If all the preconditions I mentioned are true (2003
server, 2003 native AD), then S4U auth will work.  All you need is the
user's UPN.

WindowsIdentity user = new WindowsIdentity("some***@domain.com");
WindowsImpersonationContext wc = null;
try
{
    wc = user.Impersonate();
    //do stuff here
}
finally
{
    if (wc != null)
        wc.Undo();
}

The other thing you can do is use NegotiateStream to authenticate the remote
user and get a token you can impersonate that way.  That is more akin to a
classic Windows client/server RPC type of thing, but that locks your clients
into using Negotiate auth.  Note that in that case, the OS and domain
restrictions are gone as you are not creating the token with S4U.  The
Negotiate SSPI provider does it instead.

So, it really depends on what you need to do.

Joe K.

Show quoteHide quote
"William Stacey [MVP]" <william.sta***@gmail.com> wrote in message
news:OxBf$Y7SGHA.4280@TK2MSFTNGP10.phx.gbl...
> Thanks Joe.  Any bit of code to get the idea going for me?  Will need file
> access with user ACLs, run process with user ACLs, maybe registry.  Do I
> need to use something like the AuthentiatedStream class on the server side
> to login and get a WindowsIdentity passing a null password or something?
> I
> could not find any examples in this specific area (i.e. no pwd).
>
> --
> William Stacey [MVP]
>
Author
20 Mar 2006 5:47 AM
Dominick Baier [DevelopMentor]
> The other thing you can do is use NegotiateStream to authenticate the
> remote user and get a token you can impersonate that way.  That is
> more akin to a classic Windows client/server RPC type of thing, but
> that locks your clients into using Negotiate auth.  Note that in that
> case, the OS and domain restrictions are gone as you are not creating
> the token with S4U.  The Negotiate SSPI provider does it instead.


NegotiateStream requires a password.

---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

Show quoteHide quote
> You just use the WindowsIdentity constructor that takes the user's UPN
> (single string parameter).  Once you have that, you just call the
> impersonate method.  If all the preconditions I mentioned are true
> (2003 server, 2003 native AD), then S4U auth will work.  All you need
> is the user's UPN.
>
> WindowsIdentity user = new WindowsIdentity("some***@domain.com");
> WindowsImpersonationContext wc = null;
> try
> {
> wc = user.Impersonate();
> //do stuff here
> }
> finally
> {
> if (wc != null)
> wc.Undo();
> }
> The other thing you can do is use NegotiateStream to authenticate the
> remote user and get a token you can impersonate that way.  That is
> more akin to a classic Windows client/server RPC type of thing, but
> that locks your clients into using Negotiate auth.  Note that in that
> case, the OS and domain restrictions are gone as you are not creating
> the token with S4U.  The Negotiate SSPI provider does it instead.
>
> So, it really depends on what you need to do.
>
> Joe K.
>
> "William Stacey [MVP]" <william.sta***@gmail.com> wrote in message
> news:OxBf$Y7SGHA.4280@TK2MSFTNGP10.phx.gbl...
>
>> Thanks Joe.  Any bit of code to get the idea going for me?  Will need
>> file
>> access with user ACLs, run process with user ACLs, maybe registry.
>> Do I
>> need to use something like the AuthentiatedStream class on the server
>> side
>> to login and get a WindowsIdentity passing a null password or
>> something?
>> I
>> could not find any examples in this specific area (i.e. no pwd).
>> -- William Stacey [MVP]
>>
Author
21 Mar 2006 5:36 AM
William Stacey [MVP]
Thanks Joe.  So nothing will work (i.e. LogonUser) if AD is not native or no
AD?

--
William Stacey [MVP]

Show quoteHide quote
"Joe Kaplan (MVP - ADSI)" <joseph.e.kap***@removethis.accenture.com> wrote
in message news:OOY7Zb8SGHA.1868@TK2MSFTNGP10.phx.gbl...
| You just use the WindowsIdentity constructor that takes the user's UPN
| (single string parameter).  Once you have that, you just call the
| impersonate method.  If all the preconditions I mentioned are true (2003
| server, 2003 native AD), then S4U auth will work.  All you need is the
| user's UPN.
Author
20 Mar 2006 2:54 PM
Joe Kaplan (MVP - ADSI)
S4U won't work.  That is the only logon method that is exposed in the API if
you don't have a password.

If you can authenticate clients via NegotiateStream, that should work in all
cases as you can authenticate Kerberos and NTLM clients and you don't need a
domain for NTLM for local machine accounts.

Like I said, I think you can write your own SSPI provider too, but I
wouldn't go there.

Joe K.


Show quoteHide quote
"William Stacey [MVP]" <william.sta***@gmail.com> wrote in message
news:%23zpCUi%23SGHA.224@TK2MSFTNGP10.phx.gbl...
> Thanks Joe.  So nothing will work (i.e. LogonUser) if AD is not native or
> no
> AD?
>
> --
> William Stacey [MVP]
>
> "Joe Kaplan (MVP - ADSI)" <joseph.e.kap***@removethis.accenture.com> wrote
> in message news:OOY7Zb8SGHA.1868@TK2MSFTNGP10.phx.gbl...
> | You just use the WindowsIdentity constructor that takes the user's UPN
> | (single string parameter).  Once you have that, you just call the
> | impersonate method.  If all the preconditions I mentioned are true (2003
> | server, 2003 native AD), then S4U auth will work.  All you need is the
> | user's UPN.
>
>