* chore: bump follow-redirects to >=1.16.0 * chore: bump @xmldom/xmldom to >=0.8.12 * chore: bump serialize-javascript to >=7.0.5 * chore: bump picomatch to 2.3.2 / 4.0.4 * chore: bump flatted to >=3.4.2 * chore: bump undici to >=7.24.0 * chore: bump svgo to >=4.0.1 * chore: bump minimatch to 3.1.3 / 5.1.8 * build(deps): bump i18next-http-backend in /services/idp Bumps [i18next-http-backend](https://github.com/i18next/i18next-http-backend) from 2.7.3 to 3.0.5. - [Changelog](https://github.com/i18next/i18next-http-backend/blob/master/CHANGELOG.md) - [Commits](https://github.com/i18next/i18next-http-backend/compare/v2.7.3...v3.0.5) --- updated-dependencies: - dependency-name: i18next-http-backend dependency-version: 3.0.5 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump amd64/alpine from 3.23.3 to 3.23.4 in /ocis/docker Bumps amd64/alpine from 3.23.3 to 3.23.4. --- updated-dependencies: - dependency-name: amd64/alpine dependency-version: 3.23.4 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump actions/setup-node from 6.3.0 to 6.4.0 Bumps [actions/setup-node](https://github.com/actions/setup-node) from 6.3.0 to 6.4.0. - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/53b83947a5a98c8d113130e565377fae1a50d02f...48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e) --- updated-dependencies: - dependency-name: actions/setup-node dependency-version: 6.4.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump actions/setup-go from 6.3.0 to 6.4.0 Bumps [actions/setup-go](https://github.com/actions/setup-go) from 6.3.0 to 6.4.0. - [Release notes](https://github.com/actions/setup-go/releases) - [Commits](https://github.com/actions/setup-go/compare/v6.3.0...4a3601121dd01d1626a1e23e37211e3254c1c06c) --- updated-dependencies: - dependency-name: actions/setup-go dependency-version: 6.4.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump aquasecurity/trivy-action from 0.35.0 to 0.36.0 Bumps [aquasecurity/trivy-action](https://github.com/aquasecurity/trivy-action) from 0.35.0 to 0.36.0. - [Release notes](https://github.com/aquasecurity/trivy-action/releases) - [Commits](https://github.com/aquasecurity/trivy-action/compare/57a97c7e7821a5776cebc9bb87c984fa69cba8f1...ed142fd0673e97e23eac54620cfb913e5ce36c25) --- updated-dependencies: - dependency-name: aquasecurity/trivy-action dependency-version: 0.36.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump docker/build-push-action from 7.0.0 to 7.1.0 Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 7.0.0 to 7.1.0. - [Release notes](https://github.com/docker/build-push-action/releases) - [Commits](https://github.com/docker/build-push-action/compare/d08e5c354a6adb9ed34480a06d141179aa583294...bcafcacb16a39f128d818304e6c9c0c18556b85f) --- updated-dependencies: - dependency-name: docker/build-push-action dependency-version: 7.1.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps): bump softprops/action-gh-release from 2.6.1 to 3.0.0 Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 2.6.1 to 3.0.0. - [Release notes](https://github.com/softprops/action-gh-release/releases) - [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md) - [Commits](https://github.com/softprops/action-gh-release/compare/153bb8e04406b158c6c84fc1615b65b24149a1fe...b4309332981a82ec1c5618f44dd2e27cc8bfbfda) --- updated-dependencies: - dependency-name: softprops/action-gh-release dependency-version: 3.0.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * chore: lock file regenerate * chore: bump Azure/go-ntlmssp to v0.1.1 --------- Signed-off-by: dependabot[bot] <support@github.com>
195 lines
6.0 KiB
Go
195 lines
6.0 KiB
Go
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
|
|
package ntlmssp
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/rand"
|
|
"encoding/binary"
|
|
"encoding/hex"
|
|
"errors"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type authenicateMessage struct {
|
|
LmChallengeResponse []byte
|
|
NtChallengeResponse []byte
|
|
|
|
DomainName string
|
|
UserName string
|
|
Workstation string
|
|
|
|
// only set if negotiateFlag_NTLMSSP_NEGOTIATE_KEY_EXCH
|
|
EncryptedRandomSessionKey []byte
|
|
|
|
NegotiateFlags negotiateFlags
|
|
|
|
MIC []byte
|
|
}
|
|
|
|
type authenticateMessageFields struct {
|
|
messageHeader
|
|
LmChallengeResponse varField
|
|
NtChallengeResponse varField
|
|
DomainName varField
|
|
UserName varField
|
|
Workstation varField
|
|
_ [8]byte
|
|
NegotiateFlags negotiateFlags
|
|
}
|
|
|
|
func (m *authenicateMessage) MarshalBinary() ([]byte, error) {
|
|
if !m.NegotiateFlags.Has(negotiateFlagNTLMSSPNEGOTIATEUNICODE) {
|
|
return nil, errors.New("only unicode is supported")
|
|
}
|
|
|
|
domain, user := toUnicode(m.DomainName), toUnicode(m.UserName)
|
|
workstation := toUnicode(m.Workstation)
|
|
|
|
ptr := binary.Size(&authenticateMessageFields{})
|
|
f := authenticateMessageFields{
|
|
messageHeader: newMessageHeader(3),
|
|
NegotiateFlags: m.NegotiateFlags,
|
|
LmChallengeResponse: newVarField(&ptr, len(m.LmChallengeResponse)),
|
|
NtChallengeResponse: newVarField(&ptr, len(m.NtChallengeResponse)),
|
|
DomainName: newVarField(&ptr, len(domain)),
|
|
UserName: newVarField(&ptr, len(user)),
|
|
Workstation: newVarField(&ptr, len(workstation)),
|
|
}
|
|
|
|
f.NegotiateFlags.Unset(negotiateFlagNTLMSSPNEGOTIATEVERSION)
|
|
|
|
b := bytes.Buffer{}
|
|
if err := binary.Write(&b, binary.LittleEndian, &f); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := binary.Write(&b, binary.LittleEndian, &m.LmChallengeResponse); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := binary.Write(&b, binary.LittleEndian, &m.NtChallengeResponse); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := binary.Write(&b, binary.LittleEndian, &domain); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := binary.Write(&b, binary.LittleEndian, &user); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := binary.Write(&b, binary.LittleEndian, &workstation); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return b.Bytes(), nil
|
|
}
|
|
|
|
func splitNameForAuth(username string) (user, domain string) {
|
|
if strings.Contains(username, "\\") {
|
|
ucomponents := strings.SplitN(username, "\\", 2)
|
|
domain = ucomponents[0]
|
|
user = ucomponents[1]
|
|
} else if strings.Contains(username, "@") {
|
|
user = username
|
|
} else {
|
|
user = username
|
|
}
|
|
return user, domain
|
|
}
|
|
|
|
// AuthenticateMessageOptions contains optional parameters for the Authenticate message.
|
|
type AuthenticateMessageOptions struct {
|
|
WorkstationName string
|
|
|
|
// PasswordHashed indicates whether the provided password is already hashed.
|
|
// If true, the password is expected to be in hexadecimal format.
|
|
PasswordHashed bool
|
|
}
|
|
|
|
// NewAuthenticateMessage creates a new AUTHENTICATE message in response to the CHALLENGE message that was received from the server.
|
|
// The options parameter allows specifying additional settings for the message, it can be nil to use defaults.
|
|
func NewAuthenticateMessage(challenge []byte, username, password string, options *AuthenticateMessageOptions) ([]byte, error) {
|
|
if username == "" && password == "" {
|
|
return nil, errors.New("anonymous authentication not supported")
|
|
}
|
|
|
|
var cm challengeMessage
|
|
if err := cm.UnmarshalBinary(challenge); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if cm.NegotiateFlags.Has(negotiateFlagNTLMSSPNEGOTIATELMKEY) {
|
|
return nil, errors.New("only NTLM v2 is supported, but server requested v1 (NTLMSSP_NEGOTIATE_LM_KEY)")
|
|
}
|
|
if cm.NegotiateFlags.Has(negotiateFlagNTLMSSPNEGOTIATEKEYEXCH) {
|
|
return nil, errors.New("key exchange requested but not supported (NTLMSSP_NEGOTIATE_KEY_EXCH)")
|
|
}
|
|
|
|
am := authenicateMessage{
|
|
NegotiateFlags: cm.NegotiateFlags,
|
|
}
|
|
am.UserName, am.DomainName = splitNameForAuth(username)
|
|
if options != nil {
|
|
am.Workstation = options.WorkstationName
|
|
}
|
|
|
|
timestamp := cm.TargetInfo[avIDMsvAvTimestamp]
|
|
if timestamp == nil { // no time sent, take current time
|
|
ft := uint64(time.Now().UnixNano()) / 100
|
|
ft += 116444736000000000 // add time between unix & windows offset
|
|
timestamp = make([]byte, 8)
|
|
binary.LittleEndian.PutUint64(timestamp, ft)
|
|
}
|
|
|
|
clientChallenge := make([]byte, 8)
|
|
if _, err := rand.Reader.Read(clientChallenge); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var ntlmV2Hash []byte
|
|
if options != nil && options.PasswordHashed {
|
|
hashParts := strings.Split(password, ":")
|
|
if len(hashParts) > 1 {
|
|
password = hashParts[1]
|
|
}
|
|
hashBytes, err := hex.DecodeString(password)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ntlmV2Hash = getNtlmV2Hashed(hashBytes, am.UserName, am.DomainName)
|
|
} else {
|
|
ntlmV2Hash = getNtlmV2Hash(password, am.UserName, am.DomainName)
|
|
}
|
|
|
|
am.NtChallengeResponse = computeNtlmV2Response(ntlmV2Hash,
|
|
cm.ServerChallenge[:], clientChallenge, timestamp, cm.TargetInfoRaw)
|
|
|
|
if cm.TargetInfoRaw == nil {
|
|
am.LmChallengeResponse = computeLmV2Response(ntlmV2Hash,
|
|
cm.ServerChallenge[:], clientChallenge)
|
|
}
|
|
return am.MarshalBinary()
|
|
}
|
|
|
|
// ProcessChallenge crafts an AUTHENTICATE message in response to the CHALLENGE message that was received from the server.
|
|
// DomainNeeded is ignored, as the function extracts the domain from the username if needed.
|
|
//
|
|
// Deprecated: Use [NewAuthenticateMessage] instead.
|
|
//
|
|
//go:fix inline
|
|
func ProcessChallenge(challengeMessageData []byte, username, password string, domainNeeded bool) ([]byte, error) {
|
|
return NewAuthenticateMessage(challengeMessageData, username, password, nil)
|
|
}
|
|
|
|
// ProcessChallengeWithHash is like ProcessChallenge but expects the password to be already hashed.
|
|
// The hash should be provided in hexadecimal format.
|
|
//
|
|
// Deprecated: Use [NewAuthenticateMessage] with [AuthenticateMessageOptions.PasswordHashed] instead.
|
|
//
|
|
//go:fix inline
|
|
func ProcessChallengeWithHash(challengeMessageData []byte, username, hash string) ([]byte, error) {
|
|
return NewAuthenticateMessage(challengeMessageData, username, hash, &AuthenticateMessageOptions{
|
|
PasswordHashed: true,
|
|
})
|
|
}
|