I work on a corporate windows network (which I log in to) with a HTTP proxy. When I use Internet Explorer it magically uses the proxy without me needing to type in my password. Certain other programs seem to manage this too, like JavaWebStart has a "use browser settings" option.
However when I use scripts/programs like curl or wget to fetch stuff from http, or do it within my Java code I seem to need to have my password stored somewhere, which obviously isn't best for security.
How can I get the password-less access that internet explorer has in a programmatic way?
I'm arguing this is a stack overflow question because I'm a programmer and I need my programs/scripts to work without typing in the password, though I can see that others might think it belongs on Server Fault/Superuser.
I know about settings like --proxy-ntlm in curl, but this still requires an ntlm username and password.
In the absence of an answer from someone else here is what I have discovered, I hope it is useful for someone else.
Executive Summary:
- Download SSPI enabled curl from http://curl.haxx.se/latest.cgi?curl=win32-ssl changing to Windows, zip, SSL-enabled, SSPI-enabled (7.19.5).
- Install Windows Open-SSL from http://www.slproweb.com/products/Win32OpenSSL.html and make a donation to support his bandwidth cost.
- Install the Visual C++ 2008 redistributables if you need them.
- Use curl to fetch the page:
curl.exe -U : --proxy-ntlm --proxy myproxy.com:8080 http://www.google.com
More detailed explanation
The magic phrase for authentication using the Windows login mechanism is SSPI. This gives a good google search phrase. I still haven't found a good way of using SSPI for HTTP proxy authentication in java or wget though.
However, curl (the download tool) does support SSPI but only in certain builds. Unfortunately the default cygwin build is not one of them. You can find out if your build of curl supports SSPI by getting the verbose version information:
curl -v -V
If SSPI is supported it will be mentioned in the features line.
To get a windows version that supported SSPI I had to go to http://curl.haxx.se/latest.cgi?curl=win32-ssl and then change the download choice to Windows, zip, SSL-enabled, SSPI-enabled (7.19.5). By the time you read this the version number may have changed.
This then silently failed from the command line. When I ran from windows explorer I got a message about a missing libeay32.dll. One way of getting this from windows is from the only link at openssl.org to a windows version. The producer of this requests a donation to cover bandwidth costs. Another way would be to build your own from source.
And after all that curl worked with the following command line:
curl.exe -U : --proxy-ntlm --proxy myproxy.com:8080 http://www.google.com
The -U :
configures no password, the other commandline options set up the proxy. You'll probably have to change your proxy and port settings.
This would all be much easier if only cygwin's curl release supported SSPI. I'm going to go put in a request for that now.
Please note my edit contains an inaccurate assumption about -U and -u. I have submitted a correction, but in the interim note:
curl -U = Authentication to a proxy
curl -u = Authentication to a server
Therefore, the first command should be:
curl.exe -U : --proxy-ntlm --proxy myproxy.com:8080 http://www.google.com
and the second one, in the example for transparent NTLM:
curl -v -u : --ntlm [the redirection URL from Location: header]
Sorry about that!
Might be a bit late but wanted to mention this nonetheless. The original question is generically asking about NTLM proxy auth without passwords on Windows where user has already logged in. No doubt curl can do this but I wanted to give another option.
NTLMAps and Cntlm are proxies that do the NTLM auth as an intermediary proxy. However, they both require the user/pass since they are mostly targeted towards Linux users. I historically used these tools on Windows but was annoyed by the same requirement of having to provide the credentials to them.
As a result, I've authored Px for Windows which is an HTTP proxy like the above two, but uses SSPI to manage the required authentication with the corporate proxy. All you need to configure is the proxy server and port. It helps for existing applications that cannot talk through NTLM proxies such as pip and npm for example.
For developing your own apps, the code should also help figure out how to do this within Python and perhaps languages which have access to SSPI.
来源:https://stackoverflow.com/questions/1276955/ntlm-proxy-without-password