Skip to content

Commit 5111f9e

Browse files
committed
Refactor HashCapture
1 parent 4125b20 commit 5111f9e

10 files changed

Lines changed: 38 additions & 29 deletions

File tree

lib/msf/core/exploit/remote/smb/server/hash_capture.rb renamed to lib/msf/core/exploit/remote/relay/ntlm/hash_capture.rb

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
require 'ruby_smb'
88

99
module Msf
10-
module Exploit::Remote::SMB::Server::HashCapture
10+
module Exploit::Remote::Relay::NTLM::HashCapture
1111

1212
include ::Msf::Auxiliary::Report
1313

@@ -20,7 +20,7 @@ def initialize(info = {})
2020
], self.class)
2121
end
2222

23-
def validate_smb_hash_capture_datastore(datastore, ntlm_provider)
23+
def validate_hash_capture_datastore(datastore, ntlm_provider)
2424
if datastore['CHALLENGE']
2525
# Set challenge for all future server responses
2626

@@ -36,7 +36,7 @@ def validate_smb_hash_capture_datastore(datastore, ntlm_provider)
3636
end
3737
end
3838

39-
def report_ntlm_type3(address:, ntlm_type1:, ntlm_type2:, ntlm_type3:)
39+
def report_ntlm_type3(address:, ntlm_type1:, ntlm_type2:, ntlm_type3:, service_name:)
4040
ntlm_message = ntlm_type3
4141
hash_type = nil
4242

@@ -69,7 +69,7 @@ def report_ntlm_type3(address:, ntlm_type1:, ntlm_type2:, ntlm_type3:)
6969
{
7070
address: address,
7171
port: srvport,
72-
service_name: 'smb',
72+
service_name: service_name.downcase,
7373
protocol: 'tcp',
7474
module_fullname: fullname,
7575
workspace_id: myworkspace_id
@@ -81,7 +81,7 @@ def report_ntlm_type3(address:, ntlm_type1:, ntlm_type2:, ntlm_type3:)
8181
origin_type: :service,
8282
address: address,
8383
port: srvport,
84-
service_name: 'smb',
84+
service_name: service_name.downcase,
8585
username: user,
8686
server_challenge: challenge,
8787
client_hash: client_hash,
@@ -121,10 +121,12 @@ def report_ntlm_type3(address:, ntlm_type1:, ntlm_type2:, ntlm_type3:)
121121

122122
# TODO: write method for mapping +major+ and +minor+ OS values to human-readable OS names.
123123
# client_os_version = ::NTLM::OSVersion.read(type1_msg.os_version)
124-
print_line "[SMB] #{hash_type} Client : #{address}"
125-
# print_line "[SMB] #{hash_type} Client OS : #{client_os_version}"
126-
print_line "[SMB] #{hash_type} Username : #{domain}\\#{user}"
127-
print_line "[SMB] #{hash_type} Hash : #{combined_hash}"
124+
125+
protocol_prefix = service_name.upcase
126+
print_line "[#{protocol_prefix}] #{hash_type} Client : #{address}"
127+
# print_line "[#{protocol_prefix}] #{hash_type} Client OS : #{client_os_version}"
128+
print_line "[#{protocol_prefix}] #{hash_type} Username : #{domain}\\#{user}"
129+
print_line "[#{protocol_prefix}] #{hash_type} Hash : #{combined_hash}"
128130
print_line
129131

130132
if datastore['JOHNPWFILE']
@@ -136,12 +138,13 @@ def report_ntlm_type3(address:, ntlm_type1:, ntlm_type2:, ntlm_type3:)
136138
end
137139
end
138140

139-
def on_ntlm_type3(address:, ntlm_type1:, ntlm_type2:, ntlm_type3:)
141+
def on_ntlm_type3(address:, ntlm_type1:, ntlm_type2:, ntlm_type3:, service_name:)
140142
report_ntlm_type3(
141143
address: address,
142144
ntlm_type1: ntlm_type1,
143145
ntlm_type2: ntlm_type2,
144-
ntlm_type3: ntlm_type3
146+
ntlm_type3: ntlm_type3,
147+
service_name: service_name
145148
)
146149
end
147150

@@ -174,10 +177,11 @@ def bin_to_hex(str)
174177
class HashCaptureNTLMProvider < ::RubySMB::Gss::Provider::NTLM
175178
# @param [::WindowsError::NTStatus] ntlm_type3_status A specific NT Status to return as the response to the NTLM
176179
# type 3 message. If this value is nil, the message will be processed as normal.
177-
def initialize(allow_anonymous: false, allow_guests: false, default_domain: 'WORKGROUP', listener: nil, ntlm_type3_status: ::WindowsError::NTStatus::STATUS_ACCESS_DENIED)
180+
def initialize(allow_anonymous: false, allow_guests: false, default_domain: 'WORKGROUP', listener: nil, ntlm_type3_status: ::WindowsError::NTStatus::STATUS_ACCESS_DENIED, service_name:)
178181
super(allow_anonymous: allow_anonymous, allow_guests: allow_guests, default_domain: default_domain)
179182
@listener = listener
180183
@ntlm_type3_status = ntlm_type3_status
184+
@service_name = service_name
181185
end
182186

183187
# Needs overwritten to ensure our version of Authenticator is returned
@@ -188,7 +192,7 @@ def new_authenticator(server_client)
188192
end
189193

190194
attr_reader :listener
191-
attr_accessor :ntlm_type3_status
195+
attr_accessor :ntlm_type3_status, :service_name
192196
end
193197

194198
class HashCaptureAuthenticator < ::RubySMB::Gss::Provider::NTLM::Authenticator
@@ -208,6 +212,7 @@ def process_ntlm_type3(type3_msg)
208212
ntlm_type1: @ntlm_type1,
209213
ntlm_type2: @ntlm_type2,
210214
ntlm_type3: type3_msg,
215+
service_name: @provider.service_name
211216
)
212217
end
213218

lib/msf/core/exploit/remote/smb/relay/ntlm/server_client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ def relay_ntlmssp(session, incoming_security_buffer = nil)
249249
address: relayed_connection.target.ip,
250250
ntlm_type1: session.metadata[:incoming_negotiate_message],
251251
ntlm_type2: session.metadata[:relay_target_server_challenge],
252-
ntlm_type3: session.metadata[:incoming_challenge_response]
252+
ntlm_type3: session.metadata[:incoming_challenge_response],
253+
service_name: 'SMB'
253254
)
254255
@listener.on_relay_success(relay_connection: relayed_connection, relay_identity: session.metadata[:identity])
255256
else

lib/msf/core/exploit/remote/smb/relay_server.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Exploit::Remote::SMB
66
module RelayServer
77
include ::Msf::Auxiliary::MultipleTargetHosts
88
include ::Msf::Exploit::Remote::SocketServer
9-
include ::Msf::Exploit::Remote::SMB::Server::HashCapture
9+
include ::Msf::Exploit::Remote::Relay::NTLM::HashCapture
1010

1111
def initialize(info = {})
1212
super
@@ -115,7 +115,7 @@ def start_service(_opts = {})
115115
ntlm_provider.netbios_domain = datastore['SMBDomain']
116116
ntlm_provider.netbios_hostname = datastore['SMBDomain']
117117

118-
validate_smb_hash_capture_datastore(datastore, ntlm_provider)
118+
validate_hash_capture_datastore(datastore, ntlm_provider)
119119

120120
comm = _determine_server_comm(bindhost)
121121
@service = Rex::ServiceManager.start(

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Exploit::Remote::SMB::Server
77
# live in the root folder "\\".
88
module Share
99
include ::Msf::Exploit::Remote::SMB::Server
10-
include ::Msf::Exploit::Remote::SMB::Server::HashCapture
10+
include ::Msf::Exploit::Remote::Relay::NTLM::HashCapture
1111

1212
# @!attribute share
1313
# @return [String] The share portion of the provided UNC.
@@ -41,11 +41,12 @@ def initialize(info = {})
4141

4242
def start_service(opts = {})
4343
unless opts[:gss_provider]
44-
ntlm_provider = Msf::Exploit::Remote::SMB::Server::HashCapture::HashCaptureNTLMProvider.new(
44+
ntlm_provider = Msf::Exploit::Remote::Relay::NTLM::HashCapture::HashCaptureNTLMProvider.new(
4545
allow_anonymous: true,
4646
allow_guests: true,
4747
listener: self,
48-
ntlm_type3_status: nil
48+
ntlm_type3_status: nil,
49+
service_name: 'SMB'
4950
)
5051

5152
# Set domain name for all future server responses

lib/msf/core/payload/adapter/fetch/server/smb.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
module Msf::Payload::Adapter::Fetch::Server::SMB
22

33
include ::Msf::Exploit::Remote::SMB::LogAdapter
4-
include ::Msf::Exploit::Remote::SMB::Server::HashCapture
4+
include ::Msf::Exploit::Remote::Relay::NTLM::HashCapture
55

66
def start_smb_server(srvport, srvhost)
77
vprint_status("Starting SMB server on #{Rex::Socket.to_authority(srvhost, srvport)}")
88

99
log_device = LogDevice::Framework.new(framework)
1010
logger = Logger.new(self, log_device)
1111

12-
ntlm_provider = Msf::Exploit::Remote::SMB::Server::HashCapture::HashCaptureNTLMProvider.new(
12+
ntlm_provider = Msf::Exploit::Remote::Relay::NTLM::HashCapture::HashCaptureNTLMProvider.new(
1313
allow_anonymous: true,
1414
allow_guests: true,
1515
listener: self,
16-
ntlm_type3_status: nil
16+
ntlm_type3_status: nil,
17+
service_name: 'SMB'
1718
)
1819

1920
fetch_service = Rex::ServiceManager.start(

modules/auxiliary/fileformat/environment_variable_datablock_leak.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class MetasploitModule < Msf::Auxiliary
99

1010
include Msf::Exploit::FILEFORMAT
1111
include Msf::Exploit::Remote::SMB::Server::Share
12-
include Msf::Exploit::Remote::SMB::Server::HashCapture
12+
include Msf::Exploit::Remote::Relay::NTLM::HashCapture
1313

1414
def initialize(info = {})
1515
super(

modules/auxiliary/fileformat/icon_environment_datablock_leak.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class MetasploitModule < Msf::Auxiliary
99

1010
include Msf::Exploit::FILEFORMAT
1111
include Msf::Exploit::Remote::SMB::Server::Share
12-
include Msf::Exploit::Remote::SMB::Server::HashCapture
12+
include Msf::Exploit::Remote::Relay::NTLM::HashCapture
1313

1414
def initialize(info = {})
1515
super(

modules/auxiliary/fileformat/specialfolder_leak.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class MetasploitModule < Msf::Auxiliary
88

99
include Msf::Exploit::FILEFORMAT
1010
include Msf::Exploit::Remote::SMB::Server::Share
11-
include Msf::Exploit::Remote::SMB::Server::HashCapture
11+
include Msf::Exploit::Remote::Relay::NTLM::HashCapture
1212

1313
def initialize(info = {})
1414
super(

modules/auxiliary/server/capture/smb.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class MetasploitModule < Msf::Auxiliary
1010
include ::Msf::Exploit::Remote::SMB::Server
11-
include ::Msf::Exploit::Remote::SMB::Server::HashCapture
11+
include ::Msf::Exploit::Remote::Relay::NTLM::HashCapture
1212

1313
def initialize
1414
super({
@@ -64,15 +64,16 @@ def initialize
6464

6565
def start_service(opts = {})
6666
ntlm_provider = HashCaptureNTLMProvider.new(
67-
listener: self
67+
listener: self,
68+
service_name: 'SMB'
6869
)
6970

7071
# Set domain name for all future server responses
7172
ntlm_provider.dns_domain = datastore['SMBDomain']
7273
ntlm_provider.dns_hostname = datastore['SMBDomain']
7374
ntlm_provider.netbios_domain = datastore['SMBDomain']
7475
ntlm_provider.netbios_hostname = datastore['SMBDomain']
75-
validate_smb_hash_capture_datastore(datastore, ntlm_provider)
76+
validate_hash_capture_datastore(datastore, ntlm_provider)
7677
opts[:gss_provider] = ntlm_provider
7778

7879
super(opts)

modules/exploits/windows/fileformat/unc_url_cve_2025_33053.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class MetasploitModule < Msf::Exploit::Remote
77
Rank = NormalRanking
88

99
include Msf::Exploit::Remote::SMB::Server::Share
10-
include Msf::Exploit::Remote::SMB::Server::HashCapture
10+
include Msf::Exploit::Remote::Relay::NTLM::HashCapture
1111
include Msf::Exploit::FILEFORMAT
1212
include Msf::Exploit::EXE
1313

0 commit comments

Comments
 (0)