How can I use NTML hash to login
Closed this issue · 2 comments
PassingFoam commented
I use mimikatz to get my PC's NTML HASH ,but I can't login successed with it . But I can use this Hash to login in impacket and cme.
Ar3h commented
I have same problem
I tried to set hash, but failed
this is my code
package main
import (
"encoding/hex"
"fmt"
"github.com/stacktitan/smb/ntlmssp"
"github.com/stacktitan/smb/smb"
)
func ConnectSmb(Host, Username, Auth, Domain string, HashFlag bool) {
Hash := ""
Password := ""
if HashFlag { // 判断是否是Hash
Hash = Auth
} else {
Password = Auth
}
options := smb.Options{
Host: Host,
Port: 445,
User: Username,
Hash: Hash,
Password: Password,
Domain: Domain,
Workstation: "",
}
session, err := smb.NewSession(options, true)
// 登陆失败会报错
// NT Status Error: Logon failed
if err != nil {
session.Close()
fmt.Println(err.Error())
return
}
fmt.Println("Login success")
// 登陆成功就没有提示
}
func GetLM_NTLMHash(user, pass string) {
ntHash := ntlmssp.Ntowfv2(pass, user, ".\\")
lmHash := ntlmssp.Lmowfv2(pass, user, "")
fmt.Println("NTLM Hash:", hex.EncodeToString(ntHash))
fmt.Println("LM Hash:", hex.EncodeToString(lmHash))
}
func main() {
ConnectSmb("192.168.113.131", "administrator", "123123", "", false) // ✅success
// 579110c49145015c47ecd267657d3174 is NTLM Hash from mimikatz
ConnectSmb("192.168.113.131", "administrator", "579110c49145015c47ecd267657d3174579110c49145015c47ecd267657d3174", "", true) // failure❌
//GetLM_NTLMHash("Administrator", "123123") // the NTLM Hash is 3bcf78752d5dfc2f516a7b63a992fe4f
}
djkottmann commented
You should be calculating the NTLM hash by calling ntlmssp.Ntowfv1(pass). In your example, you're calling Ntowfv2. It will give you the same hash value you got from mimikatz:
func Ntowfv1(pass string) []byte {
hash := md4.New()
hash.Write(encoder.ToUnicode(pass))
return hash.Sum(nil)
}
func main() {
pass := "123123"
ntHash := Ntowfv1(pass)
fmt.Println("NTLM Hash:", hex.EncodeToString(ntHash)) // NTLM Hash: 579110c49145015c47ecd267657d3174
}