我的问题主要是curl是否能够成功协商ntlm身份验证。如果没有,还有其他选择吗?我有一个要针对其进行身份验证的Intranet服务器,但似乎失败了。我已经查看了firebug和chrome dev工具跟踪,对话框似乎相似,但有很大的不同。 chrome和firefox响应的授权时间很长:发送到服务器的第二个请求消息中的协商块,而curl没有。 Chrome和firefox都能成功登录,但curl失败。以下是curl的http跟踪。
$ curl http://home.server.com/mice/search.aspx -d "LoggingOn=1&username=myuser&password=pass&OK=1" -v --negotiate --ntlm -u myuser:pass
* About to connect() to home.server.com port 80 (#0)
* Trying 10.208.82.148... connected
* Connected to home.server.com (10.208.82.148) port 80 (#0)
> POST /mice/search.aspx HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: home.server.com
> Accept: */*
> Content-Length: 60
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 401 Unauthorized
< Content-Type: text/html
< Server: Microsoft-IIS/7.5
< WWW-Authenticate: Negotiate
< WWW-Authenticate: NTLM
< X-Powered-By: ASP.NET
< Date: Tue, 23 Oct 2018 09:27:29 GMT
< Content-Length: 1293
<
* Ignoring the response-body
* Connection #0 to host home.server.com left intact
* Issue another request to this URL: 'http://home.server.com/mice/search.aspx'
* Re-using existing connection! (#0) with host home.server.com
* Connected to home.server.com (10.208.82.148) port 80 (#0)
> POST /mice/search.aspx HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: home.server.com
> Accept: */*
> Content-Length: 60
> Content-Type: application/x-www-form-urlencoded
>
< HTTP/1.1 401 Unauthorized
< Content-Type: text/html
< Server: Microsoft-IIS/7.5
* gss_init_sec_context() failed: : Credentials cache file '/tmp/krb5cc_0' not foundWWW-Authenticate: Negotiate
< WWW-Authenticate: NTLM
< X-Powered-By: ASP.NET
< Date: Tue, 23 Oct 2018 09:27:29 GMT
< Content-Length: 1293
<
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>401 - Unauthorized: Access is denied due to invalid credentials.</title>
</head>
<body>
<div id="header"><h1>Server Error</h1></div>
<div id="content">
<div class="content-container"><fieldset>
<h2>401 - Unauthorized: Access is denied due to invalid credentials.</h2>
<h3>You do not have permission to view this directory or page using the credentials that you supplied.</h3>
</fieldset></div>
</div>
</body>
</html>
* Connection #0 to host home.server.com left intact
* Closing connection #0
以下是firebug http跟踪。
> POST /mice/search.aspx HTTP/1.1
> Host: home.server.com
> User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0
> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
> Accept-Language: en-US,en;q=0.5
> Accept-Encoding: gzip, deflate
> Referer: http://home.server.com/mice/search.aspx
> Cookie: ASP.NET_SessionId=4a4aprrcn5pukk55yvfcdt55
> DNT: 1
> Connection: keep-alive
> Upgrade-Insecure-Requests: 1
> POST DATA:
> LoggingOn=1
> username=myuser
> password=pass
> OK=1
< HTTP/1.1 401 Unauthorized
< Content-Type: text/html
< Server: Microsoft-IIS/7.5
< WWW-Authenticate: Negotiate
< NTLM
< X-Powered-By: ASP.NET
< Date: Tue, 23 Oct 2018 08:36:57 GMT
< Content-Length: 1293
> POST /mice/search.aspx HTTP/1.1
> Host: home.server.com
> User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0
> Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
> Accept-Language: en-US,en;q=0.5
> Accept-Encoding: gzip, deflate
> Referer: http://home.server.com/mice/search.aspx
> Cookie: ASP.NET_SessionId=4a4aprrcn5pukk55yvfcdt55
> DNT: 1
> Connection: keep-alive
> Upgrade-Insecure-Requests: 1
> Authorization: Negotiate QUCoIIKCDCCCg << VERY LONG BLOCK >> hwhx
>
> POST DATA:
> LoggingOn=1
> username=myuser
> password=pass
> OK=1
< HTTP/1.1 200 OK
< Cache-Control: private
< Content-Type: text/html; charset=utf-8
< Content-Encoding: gzip
< Expires: Tue, 23 Oct 2018 08:36:57 GMT
< Vary: Accept-Encoding
< Server: Microsoft-IIS/7.5
< X-AspNet-Version: 2.0.50727
< Persistent-Auth: false
< X-Powered-By: ASP.NET
< WWW-Authenticate: Negotiate oYG2MIGzoAMKAQChCwYJKoZIgvcSAQICooGeBIGbYIGYBgkqhkiG9xIBAgICAG+BiDCBhaADAgEFoQMCAQ+ieTB3oAMCARKicARu5ofget0in7K5jGdKYRrIzVFbI4XnaXJyXuL3suqdp4rOlewe21/rB23F4V99Nefx4JYbxsAh9dAx4PaInF11dFZRnTcZdqbUHVTW+SPdSDJKTNqhRAssYiJnmaDiyJUhHoxiHlliv9qYKSD+ptY=
< Date: Tue, 23 Oct 2018 08:36:59 GMT
< Content-Length: 1256