簡體   English   中英

如何在Windows Server 2012 R2上調試NTLM身份驗證

[英]How to debug NTLM authentication on Windows Server 2012 r2

我已經在運行Windows Server 2012 r2的虛擬機上設置了SOAP服務。 我使用NTLM保護它,並設法使用SoapUI從主機訪問它。 到現在為止還挺好...

我現在仍在嘗試從主機訪問我的服務,但是這次使用了golang程序。 我正在使用此庫來執行此操作(我只需要實現GenerateNegotiateMessage()方法,並確保Negotiate標志與SoapUI的標志相同)。

為了確保我做對了,我下載了SoapUI的源代碼,並比較了golang程序和SoapUI的輸出(NegotiateMessage和AuthenticateMessage)。 如果我固定輸入(時間戳和隨機客戶機挑戰),則確實會得到相同的輸出。 但是,當我嘗試連接到服務時,出現“ 401由於無效憑據而拒絕訪問”的提示。 無需說我100%確信憑據正確,因為我能夠使用SoapUI以相同的憑據訪問該服務。 因此我的go代碼中肯定有問題。 但是要弄清楚,我將需要Windows Server上的更多日志。 對我可以開始尋找的地方有任何想法嗎?

以下是我的Soap服務的web.config:

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
    <trace enabled="true" pageOutput="true" requestLimit="40" localOnly="false"/>
  </system.web>
  <system.serviceModel>

    <diagnostics wmiProviderEnabled="true">
      <messageLogging
           logEntireMessage="true"
           logMalformedMessages="true"
           logMessagesAtServiceLevel="true"
           logMessagesAtTransportLevel="true"
           maxMessagesToLog="3000"
       />
    </diagnostics>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <bindings>
      <basicHttpBinding>
        <binding>
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Ntlm" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="All" propagateActivity="true">
        <listeners>
          <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\logs\TextWriterOutput.log"/>
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
</configuration>

非常感謝你的幫助!

我最終設法解決了我的問題。 這是因為我沒有在golang程序中完整讀取HTTP請求的響應正文。 因此,每次我發出請求時,服務器都將其解釋為新連接,但NTLM身份驗證方案要求所有請求均在單個連接中進行。 正是這個答案解決了我的問題。

對於以后的編碼器,如果要重用相同的連接,則應使用以下代碼:

res, _ := client.Do(req)
io.Copy(ioutil.Discard, res.Body)
res.Body.Close()

總而言之,我沒有從Windows日志中獲取太多信息。 使我步入正軌的工具是“失敗請求跟蹤程序”,您可以從IIS管理器和老式的Wireshark中訪問該請求跟蹤程序,以比較我的程序和SoapUI發出的請求。

希望這對某人有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM