ImpersonateNamedPipeClient session winstaion impersonate

ImpersonateNamedPipeClient


from http://msdn.microsoft.com/en-us/library/windows/desktop/aa378618(v=vs.85).aspx

The ImpersonateNamedPipeClient function allows the server end of a named pipe to impersonate the client end. When this function is called, the named-pipe file system changes the thread of the calling process to start impersonating the security context of the last message read from the pipe. Only the server end of the pipe can call this function.

The server can call the RevertToSelf function when the impersonation is complete.

Important If the ImpersonateNamedPipeClient function fails, the client is not impersonated, and all subsequent client requests are made in the security context of the process that called the function. If the calling process is running as a privileged account, it can perform actions that the client would not be allowed to perform. To avoid security risks, the calling process should always check the return value. If the return value indicates that the function call failed, no client requests should be executed.


session winstaion impersonate

70人阅读 评论(0) 收藏 举报

1,一个session中可以拥有多个winstation,一个winstation必然属于某个session,且无法更换。

2,所有winstation的函数,包括OpenWindowStation,CreateWindowStation,EnumWindowStations等等,均仅限于调用Process的primary token的session。

3,一个process仅对应一个session,也即其primary token的session。更简单的方法是ProcessIdToSessionId。当然也可以通过查询primary token的方法获得。一个process的thread可以拥有不同的session id,可以通过修改thread token来实现。但没有看出有什么意义。因为这个token并不能用来实现任何和winstation有关的操作。目前仅看到一个作用是在printer port monitor driver中,用来表明打印客户所在的session信息。

4,process访问同一个session下不同的winstaion是可能的,可以通过SetProcessWinStation来实现。

5,process访问另一个session下的不同winstaion是不可能的(至少我没有找到方法),即使把当前thread的session id设置为目标session id也不行。再说一次,winstation并不与thread的token有关,它与process的primary token有关。

6,还不知道如何才能产生一个新的session,因此也不知道如何才能在此session上启动winlogon.exe。也许LsaLogonUser可以,还未详细测试。

7,Token有2种,primary token和imperanate token。前者仅用于process,后者仅用于thread。2者之间的转换可以用DuplicateTokenEx。

8,要获得impersonate token有很多方法,在primary token基础上DuplicateTokenEx并且修改,或者通过ImpersonateNamedPipeClient等等。

9,NamePipe以及RPC在本地通讯时有一个明显优于socket的地方有2点:1,不需要担心port已经被占用;2,拥有权限机制,例如ImpersonateNamedPipeClient。这可以用于界面程序和服务程序交互时的权限控制。如果已经用了socket,那么WTSQueryUserToken是一个替代方案。可以直接获得界面程序所在的session的用户的token,一般来说和界面进程的token一致。

10,系统提供了大量简化函数以避免反复的调用DuplicateTokenEx。ImpersonateSelf是用于替代如下代码的:

OpenProcessToken();
DuplicateTokenEx();
SetThreadToken();

ImpersonateLoggedonUser是用来替换如下代码的:

any way to get a token for example through
LogonOnUser(); DuplicateTokenEx(); or OpenProcessToken();DuplicationTokenEx();SetTokenInformation();
SetThreadToken();

11,Thread缺省不具有token,因此缺省情况下GetThreadToken会返回ERROR_NO_TOKEN。此种情况下应该判断并调用OpenProcessToken(GetCurentProcess());当Thread被impersonate之后(例如通过SetThreadToken或者ImpersonateSelf,ImpersonateLoggedonUser),GetThreadToken返回当前所设置的Token。

12,服务中在指定Session中启动进程,一切都取决于CreateProcessAsUser的Token。如果使用服务的Token并且使用SetTokenInformation修改session id,那么启动的进程是属于SYSTEM用户的。如果使用WTSQueryUserToken返回的Token,进程是属于该用户的。也可以枚举该Sesssion的explorer.exe的token。

13,已经用于Process的Primary Token是几乎无法用SetTokenInformation修改的。能够修改的仅有权限部分。将要用于CreateProcessAsUser的Primary Token可以任意修改。这意味着无法修改一个Process所属的session。





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值