session 0隔离

1.背景

    操作系统:win7

    目标:服务程序能够启动一个进程,不能弹出交互式服务检测


2.实现

    使用createProcessAsUser函数,此函数可以穿透session0,启动一个当前运行用户权限的进程


3.实现思路

    获取当前sessionID,WTSGetActiveConsoleSessionId

    获取当前session的用户令牌,WTSQueryUserTlken

    复制令牌,DuplicateTlkenEx

    创建session环境,CreateEnvironmentBlock

    创建进程,CreateProcessAsUser


4.注意

   a)返回错误码1314,是因为父进程权限问题。父进程需要拥有 SE_ASSIGNPRIMARYTOKEN_NAME或

SE_INCREASE_QUOTA_NAME的权限。如果没有这些权限,可以考虑使用CreateProcessWithLogon

    MSDN:Typically, the process that calls the CreateProcessAsUser function must have

 theSE_INCREASE_QUOTA_NAME privilege and may require the SE_ASSIGNPRIMARYTOKEN_NAME

 privilege if the token is not assignable. If this function fails with ERROR_PRIVILEGE_NOT_HELD (1314), 

use theCreateProcessWithLogonW function instead. CreateProcessWithLogonW requires no special

 privileges, but the specified user account must be allowed to log on interactively. Generally, it is best

 to useCreateProcessWithLogonW to create a process with alternate credentials。

    b)CreateProcessAsUser在使用时遇到一个问题,参数lpCurrentDirectory如果为空或为空格时,直接

传入为空的变量则提示错误,123。但是传入NULL则无上述问题,费解,看MSDN也没看出什么,如果有

知道原因的大神可以告知一二。

    c)CreateProcessAsUser参数lpApplicationName如果扩展名为txt、word等非exe时,此函数报错,参数

错误。后举一反三,打开文件使用cmd命令的方式,即使用lpCommandLine,使用cmd命令start 即可打开

任何扩展名的文件。但是需要注意的是,lpApplicationName为空时,需要注意lpCommandLine中不能有

空格,如果有空格。

    如 C:\program files\Test.exe,系统会解析为C:\program.exe。所以需要使用双引号把带有空格的字符串引起

来,即字符串为:“\"C:\program files\Test.exe\"”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值