Windows Server 2003、Windows XP 和 Windows 2000 的網路存取驗證演算法和範例

本文說明如何使用 NTLM 通訊協議,觀察 Windows 帳戶驗證在網路存取期間運作。

適用於:Windows 10 - 所有版本,Windows Server 2012 R2
原始 KB 編號: 103390

摘要

下列是簡化的演算法,說明如何使用NTLM通訊協定在網路存取期間觀察到Windows帳戶驗證的運作方式。 它使用透過伺服器消息塊 (SMB) 通訊協定的存取作為範例,但它適用於支援NTLM驗證的所有其他伺服器應用程式。 此討論並未涵蓋此程式的內部運作。 利用這項資訊,您可以在確定性情況下預測 Windows 網路登入行為。

當 Kerberos 用來驗證使用者並取得伺服器資源的存取權時,此程式與 NTLM 的功能不同。

請記住,本機資料庫是網域資料庫,也是域控制器上唯一的資料庫。 但在其他伺服器和所有計算機上,本機資料庫與域控制器不同。

背景資訊

當兩部以 Windows Server 2003 為基礎的 Windows XP 或 Windows 2000 型電腦透過網路通訊時,它們會使用稱為伺服器消息塊 (SMB) 的高階通訊協定。 SMB 命令內嵌在傳輸通訊協定中,例如 NetBIOS 增強型使用者介面 (NetBEUI) 或 TCP/IP。 例如,當用戶端電腦執行 NET USE 命令時,會傳送「SMB 工作階段設定和 X」框架。

在 Windows 中,「會話設定」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 會使用密碼 salt,而用戶端會在此 Salt 中使用使用者網域。

當伺服器取得資訊並在本機資料庫中尋找使用者時,伺服器會使用LOCAL資料庫的名稱來計算Salt和哈希。 因此,如果用戶端所傳送的「來源網域」是空的,或是未知的網域,Salt 和密碼哈希將不會相符。 在這些情況下,驗證嘗試將會失敗,並出現「未知的用戶名稱或不正確的密碼」 (STATUS_LOGON_FAILURE) 錯誤。 嘗試的稽核事件會報告「不正確的密碼」符號STATUS_WRONG_PASSWORD。

範例事件:

記錄檔名稱:安全性
來源:Microsoft-Windows-Security-Auditing
事件標識碼:4625
工作類別:登入
層級:資訊
關鍵詞:稽核失敗
計算機:server-computer1
描述:
帳戶無法登入。

主題:

安全性標識碼:NULL SID
帳戶名稱: -
帳戶網域: -
登入標識碼:0x0

登入類型:3

說明登入失敗的原因:

安全性標識碼:NULL SID
帳戶名稱:ntadmin
帳戶網域:client-computer1

失敗資訊:

失敗原因:未知的使用者名稱或密碼錯誤。
狀態: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.
           Not for Windows 2000 and later versions:
            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
                The user will be prompted for a password.
                Regardless of what password is entered, the user will receive
                    "Error 5: Access has been denied."
            End
            If  the account is global (the only option for Active Directory)
                The password that was specified in the SMB 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  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、使用者標識碼、全域群組成員資格、登入時間、註銷時間、KickOffTime、全名、密碼 LastSet、密碼可以變更旗標、密碼必須變更旗標、使用者腳本、配置檔路徑、主目錄和不正確的密碼計數。

  3. 如果在受信任的網域上找不到任何帳戶,操作系統就必須使用本機來賓帳戶來保證對伺服器進行驗證的一致行為。

  4. 如需如何使用 LsaLookupRestrictIsolatedNameLevel 和 NeverPing 登錄專案來限制受信任網域中隔離名稱的查閱和登入的詳細資訊,請參閱如果您在 Active Directory 域控制器上有許多外部信任,Lsass.exe 程式可能會停止回應

    • 受信任網域上的來賓帳戶永遠無法使用。

    • 實際的內部程式比這裡所述的演算法更複雜。

    • 這些演算法不會討論傳遞驗證的實際機制。 如需詳細資訊,請參閱 Windows 中的 NTLM 用戶驗證

    • 這些演算法不會討論 Windows Server 2003、Windows XP 和 Windows 2000 中使用的密碼加密程式。 衍生自單向密碼哈希的 BLOB) (二進位大型物件會在驗證要求中傳送。 此 BLOB 的內容將取決於為登入選擇的驗證通訊協定。

    • 本文不會討論 Microsoft 驗證模組的內部運作。

    • 這些演算法假設來賓帳戶在啟用時沒有密碼。 根據預設,來賓帳戶在 Windows Server 2003、Windows XP 和 Windows 2000 中沒有密碼。 如果指定來賓帳戶密碼,則SMB中傳送的使用者密碼必須符合該來賓帳戶密碼。

範例

以下是這些演算法的運作範例。

範例 1

您可以使用 SCRATCH-DOMAIN 網域帳戶資料庫中的相同帳戶名稱和密碼登入電腦。 當您 NET USE \\SCRATCH 針對 SCRATCH-DOMAIN 網域執行域控制器的命令時,命令會順利完成。 當您針對信任 SCRATCH-DOMAIN 網域的域控制器執行 NET USE \\NET 命令時,您會收到下列錯誤訊息:

發生系統錯誤 1326。 登入失敗:未知的使用者名稱或密碼錯誤。

\SCRATCH-DOMAIN\USER1 帳戶具有 \\NET 的許可權。

注意事項

此範例假設下列組態。

設定

具有本機安全性授權單位的電腦:

-登入帳戶:USER1
-Password:PSW1
-Login 網域:LOCAL1

Active Directory 域控制器:

-伺服器名稱:NET</WWITEM>
-Domain:NET-DOMAIN</WWITEM>
-Trust:NET-DOMAIN Trust SCRATCH-DOMAIN (因此,
您可以授與 SCRATCH-DOMAIN 上的帳戶許可權
在 NET- DOMAIN) 中。

NET-DOMAIN 網域:

  • NET-DOMAIN 網域的網域帳戶資料庫不包含USER1的帳戶。
  • 來賓帳戶已停用。

Windows Server 2003:

-伺服器名稱:SCRATCH
-Domain:SCRATCH-DOMAIN
-Domain Database 包含帳戶:USER1
-Domain Database 包含密碼:PSW1

在此範例中,計算機會登入其本機網域,而不是計算機網域帳戶所在的 SCRATCH-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: \\SCRATCH\share ,會執行下列步驟:

  1. 電腦會在「工作階段設定」SMB 中傳送下列內容:

    • account = “USER1”
    • password = “PSW1”
    • domain = “LOCAL1”
  2. \\SCRATCH 伺服器會接收 SMB 並檢查帳戶名稱。

  3. 伺服器會檢查其本機網域帳戶資料庫,並尋找相符專案。

  4. 伺服器接著會比較SMB密碼與網域帳戶密碼。

  5. 密碼相符。

因此,會產生「命令成功完成」訊息。 在範例 2 和範例 3 中,無法使用信任關係。 如果計算機已登入 SCRATCH-DOMAIN 網域, NET USE x: \\NET\share 則命令會成功。

理想的解決方案是讓所有計算機都登入網域。 若要登入,用戶必須指定網域、帳戶和密碼。 執行此動作之後,所有NET USE 類型命令都會傳遞正確的網域、帳戶和密碼資訊。 系統管理員應該嘗試避免計算機和多個網域上有重複的帳戶。 Windows Server 2003 型、Windows XP 型和 Windows 2000 型電腦可協助避免此設定,方法是使用網域之間的信任,以及使用可使用網域資料庫的成員。

因應措施

在這些情況下,有一個可用的因應措施。 您可以從電腦執行下列命令:

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

在此命令中,下列專案為 true:

  • \\NET = 要存取之域控制器的計算機名稱。
  • \SHARE = 共用名。
  • /USER:命令行參數,可讓您指定應在「會話設定」SMB 中指定的網域、帳戶和密碼。
  • SCRATCH-DOMAIN = 使用者帳戶所在網域的功能變數名稱。
  • \USER1 = 要驗證的帳戶。
  • PSW1 = 符合網域上帳戶的密碼。

如需此命令的詳細資訊,請在命令提示字元中輸入下列命令:

NET USE /?  

NULL 功能變數名稱

包含在 Windows Server 2003、Windows XP 和 Windows 2000 中的 Microsoft SMB 用戶端會傳送 “Session Setup SMB [x73]” SMB 中的 NULL 功能變數名稱。 Microsoft SMB 用戶端會藉由指定登入功能變數名稱來處理功能變數名稱,並在 NET USE 命令中未指定功能變數名稱時傳送 NULL 字元。 Microsoft SMB 用戶端也會展現範例 1 中所述的行為。

注意事項

  • 預設功能變數名稱是在 「DOMAIN =」 行的 LANMAN.INI 檔案中指定。 參數可以使用 NET LOGON 命令來覆寫/DOMAIN:此專案。
  • SMB 中通常會有兩個 「NULL」 表示法:零長度功能變數名稱,以及由問號字元 (?) 組成的一位元組功能變數名稱。 SMB 伺服器會擷取問號並將它轉譯為 NULL,然後再將它傳遞給本機安全 (LSA) 。

疑難排解

針對網路存取問題進行疑難解答的一個好秘訣是執行下列動作來啟用稽核。

Windows 2000 和更新版本的 Windows 2000 域控制器

  1. 從域控制器上的 [系統管理工具] 開始 Active Directory 使用者和電腦。
  2. 以滑鼠右鍵按兩下 [域控制器 OU],然後按下 [ 屬性]
  3. [群組原則] 索引標籤上,按兩下 [預設域控制器原則]
  4. 在 [原則 編輯器 中,依序按兩下 [計算機設定][Windows 設定]、[安全性設定]、[機原則] 及 [審核策略]
  5. 選取 [ 登入] 和 [帳戶登入成功 ] 選項和 [ 失敗 ] 選項。

Windows 2000 伺服器和成員的網域設定

  1. 從域控制器上的 [系統管理工具] 開始 Active Directory 使用者和電腦。
  2. 以滑鼠右鍵按兩下功能變數名稱,然後按下 [ 屬性]
  3. 在 [群組原則] 索引卷標上,按兩下 [預設網域原則]
  4. 在 [原則 編輯器 中,依序按兩下 [計算機設定][Windows 設定]、[安全性設定]、[機原則] 及 [審核策略]
  5. 選取 [ 登入] 和 [帳戶登入成功 ] 選項和 [ 失敗 ] 選項。

Windows 2000 伺服器和成員的本機設定

  1. 從 [系統管理工具] 啟動 [本機安全策略]。
  2. 開啟 [審核策略]。
  3. 選取 [ 登入] 和 [帳戶登入成功 ] 選項和 [ 失敗 ] 選項。 現在,每當網路使用者從遠端存取此伺服器時,就會在 事件檢視器 記錄稽核線索。 若要在 事件檢視器 中查看這些事件,請按兩下 [記錄] 功能表中的 [安全性]。

For more information about trust relationships, pass-through authentication, user permissions, and domain logins, see the "Technical Overview of Windows Server 2003 Security Services."

其他相關資訊

基本上,相同的網路存取驗證演算法會套用至 Windows Server 2008、Windows Server 2008 R2、Windows Server 2012、Windows Server 2012 R2。

這些操作系統在SMB中有數個新功能。

Windows Server 2008

Windows Server 2012