I have some code acting as an HTTP client which supports basic authentication as well as NTLM authentication. I can easily test that basic authentication works by requiring a username/password to access a file in the .htaccess
on an Apache server. But how can I test NTLM authentication, short of installing IIS? Are there by any chance any public HTTP servers that accept NTLM authentication?
I was looking for the same question ("how to set-up a ntlm proxy dummy server") and found this. So here is my solution, on how to set up a forwarding NTLM authentication for a proxy server, without using IIS server from Microsoft. Instead we will use Apache httpd.exe
Now edit the conf/httpd.conf configure file again, and make these changes:
#Make sure to load at least the modules, and their dependencies:
LoadModule headers_module modules/mod_headers.so
LoadModule info_module modules/mod_info.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule request_module modules/mod_request.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
LoadModule ssl_module modules/mod_ssl.so
LoadModule status_module modules/mod_status.so
#add the new module
LoadModule auth_ntlm_module modules/mod_authn_ntlm.so
Enable the proxy server. Be warned, you may open an open proxy server to the internet...
ProxyVia On
ProxyRequests On
<Proxy "*">
AuthName "Private location"
AuthType SSPI
NTLMAuth On
NTLMAuthoritative On
<RequireAll>
<RequireAny>
Require valid-user
#require sspi-user EMEA\group_name
</RequireAny>
<RequireNone>
Require user "ANONYMOUS LOGON"
Require user "NT-AUTORITÄT\ANONYMOUS-ANMELDUNG"
</RequireNone>
</RequireAll>
</Proxy>
Or, if you just want to secure just one directory, you can copy the code from the mod_authn_ntml config example:
<Location /testDirectory >
AuthName "Private location for testing NTLM authentication"
AuthType SSPI
NTLMAuth On
NTLMAuthoritative On
<RequireAll>
<RequireAny>
Require valid-user
#require sspi-user EMEA\group_name
</RequireAny>
<RequireNone>
Require user "ANONYMOUS LOGON"
Require user "NT-AUTORITÄT\ANONYMOUS-ANMELDUNG"
</RequireNone>
</RequireAll>
# use this to add the authenticated username to you header
# so any backend system can fetch the current user
# rewrite_module needs to be loaded then
RewriteEngine On
RewriteCond %{LA-U:REMOTE_USER} (.+)
RewriteRule . - [E=RU:%1]
RequestHeader set X_ISRW_PROXY_AUTH_USER %{RU}e
</Location>
To capture the local loopback traffic and to debug what's going on, you need to install Wireshark 2.4.4 and then the special npcap-0.97.exe loopback-capture driver. With this you can sniff the traffic between your browser and your local web-server
If you want to use the NTLM authentication for the proxy server, you will need to follow the advice from mod_ntlmn_auth GitHub page and set the flag DisableLoopbackCheck in the registry (see https://support.microsoft.com/en-us/kb/896861 ), otherwise all local authentication requests will silently fail.
Set up your browser to use your local IP address as a proxy server. If everything works, the browser will send your credentials in the background.
To see what's going on, you can now check your Wireshark logs, and the also the Apache logs/access.log shows you the Domain\User that was used for authentication.
Hope that helps someone out there to test their proxy scripts, because a lot of proxy software I encounter can't handle NTLM proxies correctly, which is important in a business environment.
As you have probably already realised, because NTLM is a proprietary authentication protocol (that doesn't have any official public documentation provided by Microsoft), you're going to have to either test against an actual IIS server running on Windows, or you could try and mock the authentication scheme using details gleaned from documentation such as this:
NTLM Authentication Scheme for HTTP
You won't find many public HTTP servers (if any) on the internet that you'll be able to test against. NTLM authentication is generally deployed for corporate use such as authenticating against Active Directory and are most often locked behind company VPN's.
I'd bite the bullet and fire up an instance of Windows (Microsoft let you download plenty of 120 day trials of Windows 2008 etc) in a Virtual Machine and test against that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With