Skip to content

Instantly share code, notes, and snippets.

@rusco
Created January 17, 2025 12:33
Show Gist options
  • Save rusco/fd10596bf2c6bde76a4f01227a6bc576 to your computer and use it in GitHub Desktop.
Save rusco/fd10596bf2c6bde76a4f01227a6bc576 to your computer and use it in GitHub Desktop.
IIS10 winauth with go
package main
import (
"crypto/tls"
b64 "encoding/base64"
"fmt"
"io"
"net/http"
"github.com/Azure/go-ntlmssp"
)
const (
usr = "some_usr"
pwd = "pass_in_base64"
url = "https://some_url"
)
var key = func(in string) string {
p, _ := b64.StdEncoding.DecodeString(in)
return string(p)
}
func scrape() {
url, user, password := url, usr, key(pwd)
// http2:
// client := &http.Client{Transport: ntlmssp.Negotiator{RoundTripper: &http.Transport{}}}
// http1:
client := &http.Client{Transport: ntlmssp.Negotiator{RoundTripper: &http.Transport{TLSClientConfig: &tls.Config{MinVersion: tls.VersionTLS12}, ForceAttemptHTTP2: false}}}
req, _ := http.NewRequest("GET", url, nil)
req.SetBasicAuth(user, password)
req.Header.Set("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
}
bodyString := string(bodyBytes)
fmt.Println(bodyString)
}
println("end.")
}
func main() {
scrape()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment