gpt4 book ai didi

c# - Cassini-dev 的 NTLM 身份验证中的 SecurityIdentifiers

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:41 24 4
gpt4 key购买 nike

在 Cassini-dev 的 NTLM 身份验证类中的这段代码中,调用 SECUR32.DLL(通过 Interop)来验证 HTTP 请求的 Authorization< 中的 base64 编码数据 标题。这是有道理的,当 AcceptSecurityContext()QuerySecurityContextToken() 都返回 0 时,客户端已被授权。最后,安全上下文 token 具有从中提取的 SecurityIdentifier(_sid 变量)。 (关于 common Security IDs 的一点点)

这里是 NtlmAuth Class 的相关部分

int num = Interop.AcceptSecurityContext(ref _credentialsHandle, zero,
ref _inputBufferDesc, 20,
0, ref _securityContext, ref _outputBufferDesc,
ref _securityContextAttributes, ref _timestamp);
if (num == 0x90312)
{
securityContextAcquired = true;
_blob = Convert.ToBase64String(inArray, 0, (int) _outputBuffer.cbBuffer);
}
else
{
if (num != 0)
{
return false;
}
IntPtr phToken = IntPtr.Zero;
if (Interop.QuerySecurityContextToken(ref _securityContext, ref phToken) != 0)
{
return false;
}
try
{
using (WindowsIdentity identity = new WindowsIdentity(phToken))
{
_sid = identity.User;
}
}
finally
{
Interop.CloseHandle(phToken);
}
_completed = true;

Request Class ,在使用 NtlmAuth 的 TryNtlmAuthenticate() 方法中,在成功完成 NTLM 身份验证的 3 个步骤之后,在返回最终 403 或完成请求之前,一个正在进行最终检查:

if (_host.GetProcessSid() != auth.SID)
{
_connection.WriteErrorAndClose(0x193);
return false;
}

这里,_host.GetProcessSid() 是 Cassini 进程所有者(我)的 SecurityIndentifierauth.SID 是经过身份验证的用户的 SecurityIdentifier(_sid 来自上面的 NtlmAuth 类)。如果这 2 个 SID 不相同,则返回 403 并停止身份验证,否则请求将提供给浏览器。


我的问题是:

  1. 为什么需要比较 2 个不同用户的 SecurityIndentifiers?当我尝试使用 不是拥有 Cassini 进程的用户的用户/密码进行 NTLM 身份验证时,此操作失败(返回 403)。
  2. 如果这确实是预期的行为,如果 Cassini 要作为 Windows 服务运行,则没有人能够登录,因为主机 SID 将是 S-1-5-18(或根据操作系统版本可能有类似的东西)并且没有人可以作为操作系统登录。这是否只是 Cassini 的 NTLM 身份验证实现的一部分,而我没有正确使用 Cassini?
  3. 如果这显然不是预期的行为,那么 SecurityIndentifiers 在这种情况下扮演什么角色?是否需要进行额外检查以确保主机 SID 需要属于某个类或组才能接受某个类/组的客户端 SID?处理主机/客户端 SID 时是否存在操作系统版本 (XP/Vista/7) 影响?
  4. 或者这里是否没有适用的 SecurityIdentifiers,因为它们既没有被存储也没有被传递,也没有被用来进一步识别用户/客户?

更新: cassinidev 论坛上似乎有人 proposed a patch which removes this SID check (补丁 #6604)早在 2010 年,但仍在评估中。

最佳答案

不是答案,但我只是注意到一个类似的问题,但表现形式略有不同:当托管在 Windows 服务中并且 Cassini-dev 配置为使用 Windows 身份验证时,HttpContext.Current.User 是服务正在运行,而不是发出请求的用户。

对我来说,这似乎是 cassini-dev 中的一个错误。

关于c# - Cassini-dev 的 NTLM 身份验证中的 SecurityIdentifiers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8241320/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com