繁体   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