- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
<分区>
早上好
这个问题似乎被问过几次,但我无法确定它是否真的可行。我已在 here 发布
没有回复 - 让我们试着问问这里的人。
我的目标是在当前用户上下文中(仅当他们在本地管理员组中时)从服务启动提升的进程(作为管理员)。
我可以毫无问题地获取当前用户 token ,但我无法获取该帐户的辅助/管理员 token !
我已经阅读了很多论坛,但就是无法让它工作(开始认为它不可行)。
我目前的方法:
WTSGetActiveConsoleSessionId
- 获取事件 session IDWTSQueryUserToken
- 获取 session ID 的用户 token OpenProcess
- 已登录用户的 explorer.exe 进程句柄OpenProcessToken
- 获取访问 token 的句柄LookupPrivilegeValue
- SE_DEBUG 以确认我们可以调整 token 权限DuplicateTokenEx
- 用户 token SetTokenInformation
AdjustTokenPrivileges
CreateEnvironmentBlock
- 运行新进程CreateProcessAsUser
- 希望在提升的用户上下文中生成进程(不会发生 - 标准用户上下文)请参阅下面的代码 - 很抱歉它很乱,需要整理并关闭所有句柄。目前这只是实验代码。
public static bool CreateProcessInConsoleSession(String CommandLine, bool bElevate)
{
PROCESS_INFORMATION pi;
bool isadmin = IsUserAnAdmin();
bool bResult = false;
uint dwSessionId, winlogonPid = 0;
IntPtr hUserToken = IntPtr.Zero, hUserTokenDup = IntPtr.Zero,
hPToken = IntPtr.Zero, hProcess = IntPtr.Zero;
Debug.Print("CreateProcessInConsoleSession");
// Log the client on to the local computer.
dwSessionId = WTSGetActiveConsoleSessionId();
// Find the winlogon process
var procEntry = new PROCESSENTRY32();
uint hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnap == INVALID_HANDLE_VALUE)
{
return false;
}
procEntry.dwSize = (uint)Marshal.SizeOf(procEntry); //sizeof(PROCESSENTRY32);
if (Process32First(hSnap, ref procEntry) == 0)
{
return false;
}
String strCmp = "explorer.exe";
do
{
if (strCmp.IndexOf(procEntry.szExeFile) == 0)
{
// We found a winlogon process...make sure it's running in the console session
uint winlogonSessId = 0;
if (ProcessIdToSessionId(procEntry.th32ProcessID, ref winlogonSessId) &&
winlogonSessId == dwSessionId)
{
winlogonPid = procEntry.th32ProcessID;
break;
}
}
}
while (Process32Next(hSnap, ref procEntry) != 0);
//Get the user token used by DuplicateTokenEx
WTSQueryUserToken(dwSessionId, ref hUserToken);
//Check if the user token is admin
isadmin = CheckIfAdminToken(hUserToken);
var si = new STARTUPINFO();
si.cb = Marshal.SizeOf(si);
si.lpDesktop = "winsta0\\default";
var tp = new TOKEN_PRIVILEGES();
var luid = new LUID();
hProcess = OpenProcess(MAXIMUM_ALLOWED, false, winlogonPid);
TOKEN_INFORMATION_CLASS tokenInfo = new TOKEN_INFORMATION_CLASS();
uint TokenInfLength = 0 ;
if (
!OpenProcessToken(hProcess,
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY
| TOKEN_ADJUST_SESSIONID | TOKEN_READ | TOKEN_WRITE, ref hPToken))
{
Debug.Print(String.Format("CreateProcessInConsoleSession OpenProcessToken error: {0}",
Marshal.GetLastWin32Error()));
}
if (!LookupPrivilegeValue(IntPtr.Zero, SE_DEBUG_NAME, ref luid))
{
Debug.Print(String.Format("CreateProcessInConsoleSession LookupPrivilegeValue error: {0}",
Marshal.GetLastWin32Error()));
}
bool Result;
#region TestToElevate
//http://www.microsoft-questions.com/microsoft/Platform-SDK-Security/35984508/how-to-run-a-process-with-elevated-privileges-run-as-administrat.aspx
// first call gets lenght of TokenInformation
Result = GetTokenInformation(hPToken, TOKEN_INFORMATION_CLASS.TokenUser, IntPtr.Zero , TokenInfLength , out TokenInfLength );
IntPtr TokenInformation = Marshal.AllocHGlobal((int)TokenInfLength);
Result = GetTokenInformation(hPToken, TOKEN_INFORMATION_CLASS.TokenElevation, TokenInformation, TokenInfLength, out TokenInfLength);
if (Result == false)
Result = GetTokenInformation(hPToken, TOKEN_INFORMATION_CLASS.TokenLinkedToken, TokenInformation, TokenInfLength, out TokenInfLength);
isadmin = CheckIfAdminToken(hPToken);
#endregion
var sa = new SECURITY_ATTRIBUTES();
sa.Length = Marshal.SizeOf(sa);
if (!DuplicateTokenEx(hPToken, MAXIMUM_ALLOWED, ref sa,
(int)SECURITY_IMPERSONATION_LEVEL.SecurityIdentification, (int)TOKEN_TYPE.TokenPrimary,
ref hUserTokenDup))
{
Debug.Print(
String.Format(
"CreateProcessInConsoleSession DuplicateTokenEx error: {0} Token does not have the privilege.",
Marshal.GetLastWin32Error()));
CloseHandle(hProcess);
CloseHandle(hUserToken);
CloseHandle(hPToken);
return false;
}
if (bElevate)
{
tp.PrivilegeCount = 1;
tp.Privileges = new int[3];
tp.Privileges[2] = SE_PRIVILEGE_ENABLED;
tp.Privileges[1] = luid.HighPart;
tp.Privileges[0] = luid.LowPart;
//Adjust Token privilege
if (!SetTokenInformation(hUserTokenDup, TOKEN_INFORMATION_CLASS.TokenSessionId, ref dwSessionId, (uint)IntPtr.Size))
{
Debug.Print(
String.Format(
"CreateProcessInConsoleSession SetTokenInformation error: {0} Token does not have the privilege.",
Marshal.GetLastWin32Error()));
CloseHandle(hProcess);
CloseHandle(hUserToken);
CloseHandle(hPToken);
CloseHandle(hUserTokenDup);
return false;
}
if (!AdjustTokenPrivileges(hUserTokenDup, false, ref tp, Marshal.SizeOf(tp), /*(PTOKEN_PRIVILEGES)*/ IntPtr.Zero, IntPtr.Zero))
{
int nErr = Marshal.GetLastWin32Error();
if (nErr == ERROR_NOT_ALL_ASSIGNED)
{
Debug.Print(String.Format(
"CreateProcessInConsoleSession AdjustTokenPrivileges error: {0} Token does not have the privilege.", nErr));
}
else
{
Debug.Print(String.Format("CreateProcessInConsoleSession AdjustTokenPrivileges error: {0}", nErr));
}
}
}
isadmin = CheckIfAdminToken(hUserTokenDup);
//Create Environment
uint dwCreationFlags = NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE;
IntPtr pEnv = IntPtr.Zero;
if (CreateEnvironmentBlock(ref pEnv, hUserTokenDup, true))
{
dwCreationFlags |= CREATE_UNICODE_ENVIRONMENT;
}
else
{
pEnv = IntPtr.Zero;
}
// Launch the process in the client's logon session.
bResult = CreateProcessAsUser(
hUserTokenDup, // client's access token
null, // file to execute
CommandLine, // command line
ref sa, // pointer to process SECURITY_ATTRIBUTES
ref sa, // pointer to thread SECURITY_ATTRIBUTES
false, // handles are not inheritable
(int)dwCreationFlags, // creation flags
pEnv, // pointer to new environment block
null, // name of current directory
ref si, // pointer to STARTUPINFO structure
out pi // receives information about new process
);
// End impersonation of client.
//GetLastError should be 0
int iResultOfCreateProcessAsUser = Marshal.GetLastWin32Error();
//Close handles task
CloseHandle(hProcess);
CloseHandle(hUserToken);
CloseHandle(hUserTokenDup);
CloseHandle(hPToken);
return (iResultOfCreateProcessAsUser == 0) ? true : false;
}
在本教程中,您将通过示例学习 JavaScript。 JavaScript 中的提升是一种在声明之前可以使用函数或变量的行为。例如, // using test before declarin
我正在学习javascript提升功能,发现下面的代码真的很困惑: var a = 1; function b() { a = 10; return; function a()
作为一个JS学习者,我发现了一件很有趣的事情,考虑下面的代码。 this.init = function (e) { var container = e.container;
Quasiquotes 的 Scala 文档在解释 Lifting 时提到了这一点: One can also combine lifting and unquote splicing: scala
我是新来的。到目前为止,我一直在使用 MVC 模型并使用基本的 session 管理模型,即在 session 中存储一个 token 并检查每个请求。 我正在尝试对lift做同样的事情,但我的 se
我当前使用的是Elasticsearch 2.4版,希望根据查询时间的增加或加权,根据我称为“类型”的字段对结果集进行微调。 例如 如果字段“类型”的值为“船”,则将权重或增强值增加4 如果字段“类型
一年多以来,我一直在大量使用 lift、return 以及 EitherT、ReaderT< 等构造函数,等等。我读过《Real World Haskell》、《Learn You a Haskell
我浏览了电梯的MegaProtoUser遇到这种结构:??("Last Name")。谁能解释一下,这是什么意思? 谢谢解答 最佳答案 它是在对象 S 上定义的: def ??(str : Strin
我有一个Solr索引,每个文档都是一个Event的信息。在我的架构中,Schedule 是日期类型的多值字段。我想知道是否可以使用计划日期来增加文档(多值字段中的任何日期)在未来并且最接近当前日期?我
作为测试,我正在尝试使用设计人员友好的模板在 lift 中创建一个表单。我正在使用 Lift 2.5 我已经设法使用 toForm 创建了一个工作表单,但我只是在探索所有可能的方法。 我的 html
如果这个问题已经被问到,我深表歉意。 是否可以清除已经设置的条件变量? 下面是我想要实现的详细信息: void worker_thread { while (wait_for_conditio
尝试学习Js,无法理解为什么DOM元素没有获取到值: var Car = function(loc) { var obj = Object.create(Car.prototype); obj
我想知道吊装。我知道如果全局函数名称与全局变量相同,函数会覆盖变量的名称。是吗? 这是我的代码。 (function() { console.log('console.log#1 ' + glob
这个问题已经有答案了: var functionName = function() {} vs function functionName() {} (41 个回答) 已关闭 7 年前。 在javas
我正在开发 Windows 资源管理器 namespace 扩展。我的应用程序是explorer.exe在某个时候加载和使用的动态库。我需要我的 DLL 在 C:\中创建文件,有时在其他需要提升才能执
背景: GitHub 属于客户。我们团队中有一些新手,他们有时会错过基本的命名约定和其他编码协议(protocol)。所以,如果哪位前辈想在内部review,除了创建PR,别无他法。但是这个 PR 对
我们需要在运行时更改 HKEY_LOCAL_MACHINE 的一些设置。 如果需要在运行时,是否可以提示 uac 提升,或者我是否必须启动第二个提升的进程来完成“肮脏的工作”? 最佳答案 我会以提升的
看着Haskell文档,提升似乎基本上是 fmap 的概括,允许映射具有多个参数的函数。 Wikipedia然而,关于提升的文章给出了不同的观点,根据类别中的态射来定义“提升”,以及它如何与类别中的其
ggplot2 package 很容易成为我用过的最好的绘图系统,除了对于较大的数据集(约 50k 点)性能不是很好。我正在研究通过 Shiny 提供网络分析,使用 ggplot2作为绘图后端,但我对
是否可以提升 powershell 脚本的权限,以便没有管理员权限的用户可以运行该脚本?我们的网络管理员正在尝试寻找更省时的方法来完成某些任务,目前他们必须使用远程桌面...使用 PS 脚本将其自动化
我是一名优秀的程序员,十分优秀!