@@ -400,6 +400,8 @@ type NTLMBindRequest struct {
400400 Username string
401401 // Password is the credentials to bind with
402402 Password string
403+ // Hash is the hex NTLM hash to bind with. Password or hash must be provided
404+ Hash string
403405 // Controls are optional controls to send with the bind request
404406 Controls []Control
405407}
@@ -441,9 +443,20 @@ func (l *Conn) NTLMBind(domain, username, password string) error {
441443 return err
442444}
443445
446+ // NTLMBindWithHash performs an NTLM Bind with an NTLM hash instead of plaintext password (pass-the-hash)
447+ func (l * Conn ) NTLMBindWithHash (domain , username , hash string ) error {
448+ req := & NTLMBindRequest {
449+ Domain : domain ,
450+ Username : username ,
451+ Hash : hash ,
452+ }
453+ _ , err := l .NTLMChallengeBind (req )
454+ return err
455+ }
456+
444457// NTLMChallengeBind performs the NTLMSSP bind operation defined in the given request
445458func (l * Conn ) NTLMChallengeBind (ntlmBindRequest * NTLMBindRequest ) (* NTLMBindResult , error ) {
446- if ntlmBindRequest .Password == "" {
459+ if ntlmBindRequest .Password == "" && ntlmBindRequest . Hash == "" {
447460 return nil , NewError (ErrorEmptyPassword , errors .New ("ldap: empty password not allowed by the client" ))
448461 }
449462
@@ -481,8 +494,16 @@ func (l *Conn) NTLMChallengeBind(ntlmBindRequest *NTLMBindRequest) (*NTLMBindRes
481494 }
482495 }
483496 if ntlmsspChallenge != nil {
484- // generate a response message to the challenge with the given Username/Password
485- responseMessage , err := ntlmssp .ProcessChallenge (ntlmsspChallenge , ntlmBindRequest .Username , ntlmBindRequest .Password )
497+ var err error
498+ var responseMessage []byte
499+ // generate a response message to the challenge with the given Username/Password if password is provided
500+ if ntlmBindRequest .Password != "" {
501+ responseMessage , err = ntlmssp .ProcessChallenge (ntlmsspChallenge , ntlmBindRequest .Username , ntlmBindRequest .Password )
502+ } else if ntlmBindRequest .Hash != "" {
503+ responseMessage , err = ntlmssp .ProcessChallengeWithHash (ntlmsspChallenge , ntlmBindRequest .Username , ntlmBindRequest .Hash )
504+ } else {
505+ err = fmt .Errorf ("need a password or hash to generate reply" )
506+ }
486507 if err != nil {
487508 return result , fmt .Errorf ("parsing ntlm-challenge: %s" , err )
488509 }
0 commit comments