ntlmv1
import "github.com/TheManticoreProject/Manticore/crypto/ntlmv1"
Index
- func ParityAdjust(key []byte) ([]byte, error)
- func ParityBit(n int) int
- type NTLMv1Ctx
- func NewNTLMv1CtxWithHashes(domain, username string, lmhash [16]byte, nthash [16]byte, serverChallenge [8]byte) (*NTLMv1Ctx, error)
- func NewNTLMv1CtxWithLMHash(domain, username string, lmhash [16]byte, serverChallenge [8]byte) (*NTLMv1Ctx, error)
- func NewNTLMv1CtxWithNTHash(domain, username string, nthash [16]byte, serverChallenge [8]byte) (*NTLMv1Ctx, error)
- func NewNTLMv1CtxWithPassword(domain, username, password string, serverChallenge [8]byte) (*NTLMv1Ctx, error)
- func (n *NTLMv1Ctx) ComputeLmChallengeResponse() ([24]byte, error)
- func (n *NTLMv1Ctx) ComputeNtChallengeResponse() ([24]byte, error)
- func (h *NTLMv1Ctx) ComputeResponse() (*NTLMv1Response, error)
- type NTLMv1Response
- func NewNTLMv1Response(username, domain string, serverChallenge [8]byte, lmChallengeResponse [24]byte, ntChallengeResponse [24]byte) *NTLMv1Response
- func (r *NTLMv1Response) Equal(other *NTLMv1Response) bool
- func (r *NTLMv1Response) GetLmChallengeResponse() [24]byte
- func (r *NTLMv1Response) GetNtChallengeResponse() [24]byte
- func (r *NTLMv1Response) GetServerChallenge() [8]byte
- func (r *NTLMv1Response) HashcatString() (string, error)
- func (r *NTLMv1Response) SetLmChallengeResponse(response [24]byte)
- func (r *NTLMv1Response) SetNtChallengeResponse(response [24]byte)
- func (r *NTLMv1Response) SetServerChallenge(challenge [8]byte)
- func (r *NTLMv1Response) String() string
func ParityAdjust
func ParityAdjust(key []byte) ([]byte, error)
ParityAdjust takes a byte slice as input and adjusts it for DES key parity. For each 7 bits of the input, it adds a parity bit as the 8th bit to ensure odd parity (each byte has an odd number of 1 bits). This is required for DES key generation in NTLM authentication.
The function processes the input in 7-bit chunks, adding a parity bit to each chunk to form 8-bit bytes in the output. If the input length is not a multiple of 7 bits, it pads with zeros.
Returns the parity-adjusted byte slice and any error encountered during processing.
func ParityBit
func ParityBit(n int) int
ParityBit calculates the parity bit for a given integer. It returns 1 if the number of set bits (1s) in the binary representation of the input is even, and 0 if the number is odd. This is used in DES key generation to ensure each byte has odd parity.
type NTLMv1Ctx
NTLMv1Ctx represents the components needed for NTLMv1 authentication. Source: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-nlmp/464551a8-9fc4-428e-b3d3-bc5bfb2e73a5
type NTLMv1Ctx struct {
Username string // Username for authentication
Password string // Password for authentication
Domain string // Domain name
NTHash [16]byte // NT hash of the password
LMHash [16]byte // LM hash of the password
ServerChallenge [8]byte // 8-byte challenge from server
}
func NewNTLMv1CtxWithHashes
func NewNTLMv1CtxWithHashes(domain, username string, lmhash [16]byte, nthash [16]byte, serverChallenge [8]byte) (*NTLMv1Ctx, error)
NewNTLMv1CtxWithHashes creates a new NTLMv1 instance using pre-computed NT and LM hashes.
Parameters:
- domain: The domain name
- username: The username
- lmhash: The pre-computed LM hash
- nthash: The pre-computed NT hash
- serverChallenge: 8-byte challenge from the server
Returns:
- *NTLMv1Ctx: The initialized NTLMv1 context
- error: If server challenge is not 8 bytes
func NewNTLMv1CtxWithLMHash
func NewNTLMv1CtxWithLMHash(domain, username string, lmhash [16]byte, serverChallenge [8]byte) (*NTLMv1Ctx, error)
NewNTLMv1CtxWithLMHash creates a new NTLMv1 instance using a pre-computed LM hash. The NT hash will be computed from an empty password.
Parameters:
- domain: The domain name
- username: The username
- lmhash: The pre-computed LM hash
- serverChallenge: 8-byte challenge from the server
Returns:
- *NTLMv1Ctx: The initialized NTLMv1 context
- error: If server challenge is not 8 bytes
func NewNTLMv1CtxWithNTHash
func NewNTLMv1CtxWithNTHash(domain, username string, nthash [16]byte, serverChallenge [8]byte) (*NTLMv1Ctx, error)
NewNTLMv1CtxWithNTHash creates a new NTLMv1 instance using a pre-computed NT hash. The LM hash will be computed from an empty password.
Parameters:
- domain: The domain name
- username: The username
- nthash: The pre-computed NT hash
- serverChallenge: 8-byte challenge from the server
Returns:
- *NTLMv1Ctx: The initialized NTLMv1 context
- error: If server challenge is not 8 bytes
func NewNTLMv1CtxWithPassword
func NewNTLMv1CtxWithPassword(domain, username, password string, serverChallenge [8]byte) (*NTLMv1Ctx, error)
NewNTLMv1CtxWithPassword creates a new NTLMv1 instance with the provided credentials and challenge. It calculates both the NT and LM hashes from the provided password.
Parameters:
- domain: The domain name
- username: The username
- password: The plaintext password
- serverChallenge: 8-byte challenge from the server
Returns:
- *NTLMv1Ctx: The initialized NTLMv1 context
- error: If server challenge is not 8 bytes
func (*NTLMv1Ctx) ComputeLmChallengeResponse
func (n *NTLMv1Ctx) ComputeLmChallengeResponse() ([24]byte, error)
LmChallengeResponse calculates the LM response for NTLMv1 authentication.
The LM response is calculated by encrypting the server challenge with the LM hash using DES encryption. The LM hash is split into three 7-byte keys, each adjusted for DES parity, and each key is used to encrypt the challenge.
The process: 1. Split the LM hash into three 7-byte keys (padding the last key with zeros) 2. Adjust each key for DES parity 3. Create DES ciphers with each key 4. Encrypt the server challenge with each cipher 5. Concatenate the results
Returns:
- []byte: The 24-byte LM response
- error: If key adjustment or encryption fails
func (*NTLMv1Ctx) ComputeNtChallengeResponse
func (n *NTLMv1Ctx) ComputeNtChallengeResponse() ([24]byte, error)
NtChallengeResponse calculates the NT response for NTLMv1 authentication.
The NT response is calculated by encrypting the server challenge with the NT hash using DES encryption. The NT hash is split into three 7-byte keys, each adjusted for DES parity, and each key is used to encrypt the challenge.
The process: 1. Split the NT hash into three 7-byte keys (padding the last key with zeros) 2. Adjust each key for DES parity 3. Create DES ciphers with each key 4. Encrypt the server challenge with each cipher 5. Concatenate the results
Returns:
- []byte: The 24-byte NT response
- error: If key adjustment or encryption fails
func (*NTLMv1Ctx) ComputeResponse
func (h *NTLMv1Ctx) ComputeResponse() (*NTLMv1Response, error)
ComputeResponse calculates the NTLMv1 response for the given context.
The response is calculated by encrypting the server challenge with the LM and NT hashes using DES encryption. The LM and NT hashes are split into three 7-byte keys, each adjusted for DES parity, and each key is used to encrypt the challenge.
Returns:
- *NTLMv1Response: The NTLMv1 response
- error: If the response cannot be computed
type NTLMv1Response
type NTLMv1Response struct {
Username string // Username for authentication
Domain string // Domain name
ServerChallenge [8]byte // 8-byte challenge from server
LmChallengeResponse [24]byte // 24-byte LM challenge response
NtChallengeResponse [24]byte // 24-byte NT challenge response
}
func NewNTLMv1Response
func NewNTLMv1Response(username, domain string, serverChallenge [8]byte, lmChallengeResponse [24]byte, ntChallengeResponse [24]byte) *NTLMv1Response
func (*NTLMv1Response) Equal
func (r *NTLMv1Response) Equal(other *NTLMv1Response) bool
Equal compares two NTLMv1Response objects for equality
func (*NTLMv1Response) GetLmChallengeResponse
func (r *NTLMv1Response) GetLmChallengeResponse() [24]byte
GetLmChallengeResponse returns the LM challenge response
func (*NTLMv1Response) GetNtChallengeResponse
func (r *NTLMv1Response) GetNtChallengeResponse() [24]byte
GetNtChallengeResponse returns the NT challenge response
func (*NTLMv1Response) GetServerChallenge
func (r *NTLMv1Response) GetServerChallenge() [8]byte
GetServerChallenge returns the server challenge
func (*NTLMv1Response) HashcatString
func (r *NTLMv1Response) HashcatString() (string, error)
HashcatString converts the NTLMv1 response to a Hashcat string
Returns:
- The Hashcat string
- An error if the conversion fails
func (*NTLMv1Response) SetLmChallengeResponse
func (r *NTLMv1Response) SetLmChallengeResponse(response [24]byte)
SetLmChallengeResponse sets the LM challenge response
func (*NTLMv1Response) SetNtChallengeResponse
func (r *NTLMv1Response) SetNtChallengeResponse(response [24]byte)
SetNtChallengeResponse sets the NT challenge response
func (*NTLMv1Response) SetServerChallenge
func (r *NTLMv1Response) SetServerChallenge(challenge [8]byte)
SetServerChallenge sets the server challenge
func (*NTLMv1Response) String
func (r *NTLMv1Response) String() string
String returns the NTLMv1 response as a string
Returns:
- The NTLMv1 response as a string
- An error if the conversion fails