Skip to content

Commit 67ea2bc

Browse files
committed
Land #16630 Fix duplicate ntlm hash storage
Net-NTLM (v1 and v2) hashes were being duplicated when stored in the database due to the unique data in the challenge dispite being the same. This fixes that issue
2 parents 365efba + 1a7cbe5 commit 67ea2bc

File tree

3 files changed

+28
-10
lines changed
  • documentation/modules/auxiliary/server/capture
  • lib/msf/core/exploit/remote/smb/server
  • modules/auxiliary/server/capture

3 files changed

+28
-10
lines changed

documentation/modules/auxiliary/server/capture/smb.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ A file to store Cain & Abel formatted captured hashes in. Only supports NTLMv1 H
2626

2727
The 8 byte server challenge. If unset or not a valid 16 character hexadecimal pattern, a random challenge is used instead.
2828

29+
The format is `1122334455667788`.
30+
2931
**JOHNPWFILE**
3032

3133
A file to store John the Ripper formatted hashes in. NTLMv1 and NTLMv2 hashes will be stored in separate files.

lib/msf/core/exploit/remote/smb/server/hash_capture.rb

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,7 @@ def report_ntlm_type3(address:, ntlm_type1:, ntlm_type2:, ntlm_type3:)
5656

5757
return if hash_type.nil?
5858

59-
# TODO: write method for mapping +major+ and +minor+ OS values to human-readable OS names.
60-
# client_os_version = ::NTLM::OSVersion.read(type1_msg.os_version)
61-
print_line "[SMB] #{hash_type} Client : #{address}"
62-
# print_line "[SMB] #{hash_type} Client OS : #{client_os_version}"
63-
print_line "[SMB] #{hash_type} Username : #{domain}\\#{user}"
64-
print_line "[SMB] #{hash_type} Hash : #{combined_hash}"
65-
print_line
59+
jtr_format = ntlm_message.ntlm_version == :ntlmv1 ? JTR_NTLMV1 : JTR_NTLMV2
6660

6761
if active_db?
6862
origin = create_credential_origin_service(
@@ -103,9 +97,30 @@ def report_ntlm_type3(address:, ntlm_type1:, ntlm_type2:, ntlm_type3:)
10397
# found_host.os_name = credential_options[:client_os_version]
10498
# found_host.save!
10599

100+
search_options = {
101+
realm: credential_options[:realm_value],
102+
user: credential_options[:username],
103+
hosts: credential_options[:address],
104+
jtr_format: credential_options[:jtr_format],
105+
type: Metasploit::Credential::NonreplayableHash,
106+
workspace: framework.db.workspace
107+
}
108+
if framework.db.creds(search_options).count > 0
109+
vprint_status("Skipping previously captured hash for #{credential_options[:realm_value]}\\#{credential_options[:username]}")
110+
return
111+
end
112+
106113
create_credential(credential_options)
107114
end
108115

116+
# TODO: write method for mapping +major+ and +minor+ OS values to human-readable OS names.
117+
# client_os_version = ::NTLM::OSVersion.read(type1_msg.os_version)
118+
print_line "[SMB] #{hash_type} Client : #{address}"
119+
# print_line "[SMB] #{hash_type} Client OS : #{client_os_version}"
120+
print_line "[SMB] #{hash_type} Username : #{domain}\\#{user}"
121+
print_line "[SMB] #{hash_type} Hash : #{combined_hash}"
122+
print_line
123+
109124
if datastore['JOHNPWFILE']
110125
path = build_jtr_file_name(jtr_format)
111126

modules/auxiliary/server/capture/smb.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ def initialize
1717
'Description' => %q{
1818
This module provides a SMB service that can be used to capture the challenge-response
1919
password NTLMv1 & NTLMv2 hashes used with SMB1, SMB2, or SMB3 client systems.
20-
Responses sent by this service have by default a random 8 byte challenge string
21-
of format `\x11\x22\x33\x44\x55\x66\x77\x88`, allowing for easy cracking using
22-
Cain & Abel (NTLMv1) or John the ripper (with jumbo patch).
20+
Responses sent by this service by default use a random 8 byte challenge string.
21+
A specific value (such as `1122334455667788`) can be set using the CHALLENGE option,
22+
allowing for easy cracking using Cain & Abel (NTLMv1) or John the Ripper
23+
(with jumbo patch).
2324
2425
To exploit this, the target system must try to authenticate to this
2526
module. One way to force an SMB authentication attempt is by embedding

0 commit comments

Comments
 (0)