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\"”