适用于 Windows 的网络访问验证算法和示例

本文介绍如何使用 NTLM 协议在网络访问期间观察 Windows 帐户验证是否正常工作。

原始 KB 编号: 103390

总结

下面是一种简化的算法,用于说明如何使用 NTLM 协议在网络访问期间观察 Windows 帐户验证是否正常工作。 它使用通过服务器消息块(SMB)协议进行访问作为示例,但它适用于支持 NTLM 身份验证的所有其他服务器应用程序。 此讨论不包括此过程的内部工作。 利用此信息,可以在确定性条件下预测 Windows 网络登录行为。

当 Kerberos 用于对用户进行身份验证并获取对服务器资源的访问权限时,此过程与 NTLM 的作用不同。

请记住,本地数据库是域数据库,也是域控制器上的唯一数据库。 但在其他服务器和所有计算机上,本地数据库不同于域控制器。

背景信息

当两台基于 Windows 的计算机通过网络通信时,它们使用称为服务器消息块(SMB)的高级协议。 SMB 命令嵌入到传输协议中,例如 TCP/IP 或快速 UDP Internet 连接(QUIC)。 例如,当客户端计算机执行 NET USE 命令时,将发送“SMB 会话设置和 X”帧。

在 Windows 中,使用 NTLM 时,“会话设置”SMB 包括用户帐户、加密密码和登录域的哈希函数。 域控制器将检查所有这些信息,以确定客户端是否有权完成 NET USE 命令。

算法

Windows 客户端计算机将以下命令发送到服务器:

NET USE x: \\server\share

Windows 客户端计算机发送包含其登录域、用户帐户和密码的“会话设置”SMB。

服务器检查 SMB 指定的域名或计算机名称。 如果该名称是服务器自己的名称,则运行以下算法:

    It checks its own domain database or computer database for
        a matching account.
    If it finds a matching account then
        The SMB password is compared to the domain database password or the computer database password.
        If  the password matches then
            The command completed successfully.
        If  the password does NOT match then
            The user is prompted for a password.
                The password is retested as above.
            System error 1326 has occurred. Logon failure: unknown
            user name or bad password.
        End
    If  it does NOT find the account in the domain Security Accounts Manager (SAM) database or computer SAM database then
        Guest permissions are tested.
        If  the guest account is enabled
            The command completed successfully.
        If  the guest account is disabled
            (* See Note a).
            The user is prompted for a password.
            System error 1326 has occurred. Logon failure:
                unknown user name or bad password.
        End

如果 SMB 中指定的域是服务器信任的域,则运行以下算法:

    The server will do pass-through authentication. The
        network logon request will be sent to a server that has a domain controller role in the
        specified trusted domain.

如果未设置安全通道,则运行以下算法:

The trusted domain controller checks its own domain database
        for a matching account.
    If the trusted domain controller finds a matching account, then
       NOT for Windows 2000 and later versions:
    It determines whether the account is a local or global account.
       If the account is local, then
           Guest permissions on the original server are tested.
           If the guest account is enabled
               The command completed successfully.
           If the guest account is disabled
               (* See Note 1) The user is prompted for a password.
               System error 1326 has occurred. Logon failure:
               unknown user name or bad password.
        End
        If the account is global (the only option for Active Directory)
           The SMB password is compared to the domain database
               password.
           If  the password matches, then
               The command completed successfully.
               (* See Note 2)
           If  the password does NOT match, then
               The user is prompted for a password.
                   The password is retested as above.
               System error 1326 has occurred. Logon failure:
               unknown user name or bad password.
       End
    If the trusted domain controller does NOT find the account in the trusted domain controller
           database, then
       Guest permissions are tested on the original server, not the trusted domain.  (* See Note 3)
       If  the guest account is enabled
           The user will have original server guest access.
           The command completed successfully.
       If  the guest account is disabled
           (* See Note 1) The user is prompted for a password.
           System error 1326 has occurred. Logon failure:
           unknown user name or bad password.
    End

重要

以下情况讨论客户端使用服务器拥有或知道的不同用户域的方案。 当协商 NTLMv2 身份验证协议时,存在这种不匹配的问题。 v2 上的 NTLM 使用密码盐,并且客户端在此盐中使用用户域。

当服务器获取信息并在本地数据库中查找用户时,服务器将使用 LOCAL 数据库的名称来计算盐和哈希。 因此,如果客户端发送的“源域”为空或未知域,则 salt,因此密码哈希不匹配。 在这些情况下,身份验证尝试将失败并显示“未知用户名或密码错误”(STATUS_LOGON_FAILURE) 错误。 尝试的审核事件将报告“密码不正确”,符号STATUS_WRONG_PASSWORD。

示例事件:

日志名称:安全性
来源:Microsoft-Windows-Security-Auditing
事件 ID:4625
任务类别:登录
级别:信息
关键字:审核失败
计算机:server-computer1
说明:
无法登录帐户。

主题:

安全 ID:NULL SID
帐户名称: -
帐户域: -
登录 ID:0x0

登录类型:3

登录失败的帐户:

安全 ID:NULL SID
帐户名称:ntadmin
帐户域:客户端计算机 1

失败信息:

失败原因:未知用户名或密码错误。
状态:0xc000006d
子状态:0xc000006a
...

详细的身份验证信息:

登录过程:NtLmSsp
身份验证包:NTLM
传输的服务: -
包名称(仅限 NTLM): -
密钥长度:0

若要避免此问题,必须在客户端上显式包含正确的域名。 对于工作组方案的驱动器映射,如下所示:
Net use x: \\server-computer1\data /u:server-computer1\ntadmin *

例如,如果服务器未知 SMB 中指定的域(例如,如果指定了域但服务器无法识别为受信任的域或其域控制器),则运行以下算法:

    It  will check its own account database for
        a matching account
    If  the server finds a matching account, then
        The SMB password is compared to the domain database password or the computer database password.
        If  the password matches, then
            The command completed successfully.
        If  the password does NOT match, then
            The user is prompted for a password.
                The password is retested as above.
            System error 1326 has occurred. Logon failure: unknown
            user name or bad password.
    End
    If  it does NOT find the account in the domain database then
        guest permissions are tested.
        If  the guest account is enabled
            The command completed successfully.
        If  the guest account is disabled
            System error 1326 has occurred. Logon failure:
            unknown user name or bad password.
    End

如果 SMB 中指定的域为 NULL,即未指定域,则运行以下算法:

    The server will treat this as a local network logon. The server
        will test for a matching account in its own database.
    If  it finds a matching account, then
        The SMB password is compared to the SAM database password.
        If  the password matches, then
            The command completed successfully.
        If  the password does NOT match, then
            The user is prompted for a password.
                The password is retested as above.
            System error 1326 has occurred. Logon failure: unknown
            user name or bad password.
    End
    If  it does NOT find the account in the local SAM database AND
      LsaLookupRestrictIsolatedNameLevel=0 AND NeverPing=0, then (* See Note 4)
        The server will simultaneously ask each domain that it trusts whether it has account that
            matches the SMB account.
        The first trusted domain to reply is sent a request to
            perform pass-through authentication of the client
            information.
        The trusted domain will look in its own database.
        If  an account that matches the SMB account is found, then
            The trusted domain determines whether the account is a local or global
                account.           
    If  no trusted domains respond to the request to identify the
        account, then
        Guest permissions are tested on the original server,
            not the trusted server.
        If  the guest account is enabled
            The command completed successfully.
        If  the guest account is disabled
            System error 1326 has occurred. Logon failure:
            unknown user name or bad password.
    End

备注

  1. 如果来宾帐户已禁用且用户没有帐户,服务器仍将请求密码。 尽管没有密码满足其要求,但服务器仍将请求密码作为安全措施。 此安全措施可确保未经授权的用户无法区分帐户存在的情况与帐户不存在的情况之间的差异。 无论帐户是否存在,都会提示用户输入密码。

  2. 此时,响应中从受信任的域返回以下信息:域 SID、用户 ID、全局组成员身份、登录时间、注销时间、KickOffTime、全名、密码 LastSet、密码可以更改标志、密码必须更改标志、用户脚本、配置文件路径、主目录和错误的密码计数。

  3. 如果未在受信任的域中找到任何帐户,则操作系统必须使用本地来宾帐户来保证针对服务器进行身份验证的一致行为。

  4. 有关如何使用 LsaLookupRestrictIsolatedNameLevel 和 NeverPing 注册表项限制对受信任域中隔离名称的查找和登录的详细信息,请参阅 “Lsass.exe进程可能会在 Active Directory 域控制器上有许多外部信任时停止响应。 此外,修补程序可用于扩展日志记录,以识别 Windows Server 2008 SP2 中的独立名称查找请求。

    • 受信任域上的来宾帐户永远不会可用。
    • 实际内部过程比此处所述的算法更为复杂。
    • 这些算法不讨论直通身份验证的实际机制。 有关详细信息,请参阅 Windows 中的 NTLM 用户身份验证。
    • 这些算法不讨论在 Windows 中使用的密码加密过程。 从单向密码哈希派生的二进制大型对象(BLOB)作为身份验证请求的一部分发送。 此 BLOB 的内容将取决于为登录选择的身份验证协议。
    • 本文不讨论Microsoft身份验证模块的内部工作。
    • 这些算法假定启用时来宾帐户没有密码。 默认情况下,来宾帐户在 Windows 中没有密码。 如果指定了来宾帐户密码,则 SMB 中发送的用户密码必须与该来宾帐户密码匹配。

示例

下面是这些算法在操作中的示例。

示例 1

使用 CONTOSO-DOMAIN 域帐户数据库中的同一帐户名和密码登录到计算机。 为 CONTOSO-DOMAIN 域的域控制器运行 NET USE \\CONTOSO 命令时,该命令将成功完成。 为信任 CONTOSO 域的域控制器运行 NET USE \\NET 命令时,会收到以下错误消息:

系统错误 1326 已发生。 登录失败: 用户名未知或密码错误。

\CONTOSO-DOMAIN\USER1 帐户对 \\NET 具有权限。

备注

此示例假定以下配置。

配置

具有本地安全机构的计算机:

  • 登录帐户:USER1
  • 密码:PSW1
  • 登录域:LOCAL1

Active Directory 域控制器:

-Server Name: NET
-Domain:NET-DOMAIN
-Trust: NET-DOMAIN Trust CONTOSO-DOMAIN (因此,
可以向 CONTOSO-DOMAIN 上的帐户授予权限
在 NET- DOMAIN 中)。

NET 域:

  • NET-DOMAIN 域的域帐户数据库不包含 USER1 的帐户。
  • 来宾帐户已禁用。

CONTOSO 域:

  • 服务器名称:CONTOSO
  • 域:CONTOSO-DOMAIN
  • 域数据库包含帐户:USER1
  • 域数据库包含密码:PSW1

在此示例中,计算机登录到其本地域,而不是计算机域帐户所在的 CONTOSO-DOMAIN 域。

示例 2

运行 NET USE x: \\NET\share 此命令时,将执行以下步骤:

  1. 计算机在“会话设置”SMB 中发出以下内容:

    • account = “USER1”
    • password = “PSW1”
    • domain = “LOCAL1”
  2. \\NET 服务器接收 SMB 并查看帐户名称。

  3. 服务器会检查其本地域帐户数据库,并且找不到匹配项。

  4. 然后,服务器检查 SMB 域名。

  5. 服务器不信任“LOCAL1”,因此服务器不会检查其受信任的域。

  6. 然后,服务器会检查其来宾帐户。

  7. 来宾帐户已禁用,因此出现“系统错误 1326”。 登录失败:未知用户名或密码错误。“错误消息生成。

示例 3

运行 NET USE x: \\CONTOSO\share 此命令时,将执行以下步骤:

  1. 计算机在“会话设置”SMB 中发出以下内容:

    • account = “USER1”
    • password = “PSW1”
    • domain = “LOCAL1”
  2. \\CONTOSO 服务器接收 SMB 并检查帐户名称。

  3. 服务器检查其本地域帐户数据库并查找匹配项。

  4. 然后,服务器将 SMB 密码与域帐户密码进行比较。

  5. 密码匹配。

因此,将生成“命令成功完成”消息。 在示例 2 和示例 3 中,信任关系不可用。 如果计算机已登录到 CONTOSO-DOMAIN 域,该 NET USE x: \\NET\share 命令将成功。

理想的解决方案是让所有计算机登录到域。 若要登录,用户必须指定域、帐户和密码。 执行此操作后,所有 NET USE -type 命令都将传递正确的域、帐户和密码信息。 管理员应尝试避免计算机和多个域上的重复帐户。 Windows 通过使用域之间的信任和使用可以使用域数据库的成员来帮助避免此配置。

解决方法

在这些情况下可以使用一种解决方法。 在计算机中,可以运行以下命令:

NET USE X: \\NET\SHARE /USER:CONTOSO-DOMAIN\USER1 PSW1

在此命令中,以下命令为 true:

  • \\NET = 正在访问的域控制器的计算机名称。
  • \SHARE = 共享名称。
  • /USER:命令行参数,用于指定应在“会话设置”SMB 中指定的域、帐户和密码。
  • CONTOSO-DOMAIN = 用户帐户所在的域的域名。
  • \USER1 = 要验证的帐户。
  • PSW1 = 与域上的帐户匹配的密码。

有关此命令的详细信息,请在命令提示符处键入以下内容:

NET USE /?  

NULL 域名

Windows 中包含的 Microsoft SMB 客户端在“会话设置 SMB [x73]”SMB 中发送 NULL 域名。 Microsoft SMB 客户端通过指定登录域名,并在 NET USE 命令中未指定域名时发送 NULL 字符来处理域名。 Microsoft SMB 客户端还将展示示例 1 中所述的行为。

备注

SMB 中的“NULL”通常有两种表示形式:长度为零的域名和由问号字符(??)组成的单字节域名。 SMB 服务器捕获问号并将其转换为 NULL,然后再将其传递给本地安全机构(LSA)。

故障排除

排查网络访问问题的一个好提示是通过执行以下操作来启用审核。

Windows 域控制器

  1. 从域控制器上的管理工具开始Active Directory 用户和计算机。
  2. 右键单击 域控制器 OU,然后单击“ 属性”。
  3. “组策略 ”选项卡上,双击“ 默认域控制器策略”。
  4. 在策略编辑器中,依次单击“计算机设置”、“Windows 设置”、“安全设置”、“高级审核策略配置”和“帐户登录”。
  5. 选择“审核凭据验证”选项和“失败”选项。

Windows 2000 的域设置

  1. 从域控制器上的管理工具开始Active Directory 用户和计算机。
  2. 右键单击域名,然后单击“ 属性”。
  3. “组策略 ”选项卡上,双击“ 默认域策略”。
  4. 在策略编辑器中,依次单击“计算机设置”、“Windows 设置”、“安全设置”、“高级审核策略配置”和“帐户登录”。
  5. 选择“审核凭据验证”选项和“失败”选项。

Windows 2000 服务器和成员的本地设置

  1. 在管理工具中,启动本地安全策略。
  2. 打开 高级审核策略配置 - 本地组策略对象
  3. 选择“帐户登录,然后选择“审核凭据验证”选项和“失败”选项。
  4. 现在,每当网络用户远程访问此服务器时,都会事件查看器登录审核线索。 若要查看事件查看器中的这些事件,请单击“日志”菜单中的安全性

有关信任关系、直通身份验证、用户权限和域登录的详细信息,请参阅“Windows Server 2003 安全服务的技术概述”。