curl from PS fails with 407, Squid Proxy configured to use NTLM

Manju 110 Reputation points
2023-05-16T13:28:19.6+00:00

Hi,

I have configured a Squid proxy with ntlm authentication (Ubuntu, with Samba Active Directory Domain Controller). A Windows host which is a domain member is configured to use that proxy. I am able to access internet from a browser. I can see the request going through the proxy (in access.log).

However when I try curl https://google.com from a PowerShell, I get 407, authentication required.

Why is curl failing while browser requests succeed ?

How do I verify if my request through browser is indeed using NTLM authentication and the NTLM authentication is succeeding in this case, any logs I can check ?

Thank you.

Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2023-05-16T19:50:31.6266667+00:00

    Try this.

    Invoke-WebRequest https://google.com -UseDefaultCredentials       
    

    Curl is a Powershell alias for Invoke-WebRequest. If you ran curl.exe then you would execute C:\Windows\System32\curl.exe.

    https://woshub.com/parsing-html-webpages-with-powershell/

    Using Invoke-WebRequest with Authentication

    Some web resources require authentication to access. You can use various types of authentication with the Invoke-WebRequest cmdlet (Basic, NTLM, Kerberos, OAuth, or certificate authentication).

    To perform Basic Authentication (authentication by name and password encoded in base64), you first need to get the username and password:

    $cred = Get-Credential

    wget -Uri 'https://somesite.com' -Credential $cred

    In order to use the current Windows user credentials to perform NTLM or Kerberos authentication, add the -UseDefaultCredentials option:

    Invoke-WebRequest 'https://somesite.com' -UseDefaultCredentials


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.