Skip to content

Commit 55c07b1

Browse files
committed
Report credentials with create_credential_login
1 parent 84060bb commit 55c07b1

File tree

1 file changed

+90
-17
lines changed

1 file changed

+90
-17
lines changed

modules/auxiliary/server/capture/http_ntlm.rb

Lines changed: 90 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,11 @@ def html_get_hash(arg = {})
293293
capturedtime = Time.now.to_s
294294
case ntlm_ver
295295
when NTLM_CONST::NTLM_V1_RESPONSE
296-
smb_db_type_hash = "smb_netv1_hash"
297296
capturelogmessage =
298297
"#{capturedtime}\nNTLMv1 Response Captured from #{host} \n" +
299298
"DOMAIN: #{domain} USER: #{user} \n" +
300299
"LMHASH:#{lm_hash_message ? lm_hash_message : "<NULL>"} \nNTHASH:#{nt_hash ? nt_hash : "<NULL>"}\n"
301300
when NTLM_CONST::NTLM_V2_RESPONSE
302-
smb_db_type_hash = "smb_netv2_hash"
303301
capturelogmessage =
304302
"#{capturedtime}\nNTLMv2 Response Captured from #{host} \n" +
305303
"DOMAIN: #{domain} USER: #{user} \n" +
@@ -310,7 +308,6 @@ def html_get_hash(arg = {})
310308
when NTLM_CONST::NTLM_2_SESSION_RESPONSE
311309
# we can consider those as netv1 has they have the same size and i cracked the same way by cain/jtr
312310
# also 'real' netv1 is almost never seen nowadays except with smbmount or msf server capture
313-
smb_db_type_hash = "smb_netv1_hash"
314311
capturelogmessage =
315312
"#{capturedtime}\nNTLM2_SESSION Response Captured from #{host} \n" +
316313
"DOMAIN: #{domain} USER: #{user} \n" +
@@ -326,20 +323,19 @@ def html_get_hash(arg = {})
326323
# DB reporting
327324
# Rem : one report it as a smb_challenge on port 445 has breaking those hashes
328325
# will be mainly use for psexec / smb related exploit
329-
report_auth_info(
330-
:host => ip,
331-
:port => 445,
332-
:sname => 'smb_challenge',
333-
:user => user,
334-
:pass => domain + ":" +
335-
( lm_hash + lm_cli_challenge.to_s ? lm_hash + lm_cli_challenge.to_s : "00" * 24 ) + ":" +
336-
( nt_hash + nt_cli_challenge.to_s ? nt_hash + nt_cli_challenge.to_s : "00" * 24 ) + ":" +
337-
datastore['CHALLENGE'].to_s,
338-
:type => smb_db_type_hash,
339-
:proof => "DOMAIN=#{domain}",
340-
:source_type => "captured",
341-
:active => true
342-
)
326+
opts_report = {
327+
ip: ip,
328+
user: user,
329+
domain: domain,
330+
ntlm_ver: ntlm_ver,
331+
lm_hash: lm_hash,
332+
nt_hash: nt_hash
333+
}
334+
opts_report.merge!(lm_cli_challenge: lm_cli_challenge) if lm_cli_challenge
335+
opts_report.merge!(nt_cli_challenge: nt_cli_challenge) if nt_cli_challenge
336+
337+
report_creds(opts_report)
338+
343339
#if(datastore['LOGFILE'])
344340
# File.open(datastore['LOGFILE'], "ab") {|fd| fd.puts(capturelogmessage + "\n")}
345341
#end
@@ -406,4 +402,81 @@ def html_get_hash(arg = {})
406402
end
407403
end
408404

405+
def report_creds(opts)
406+
ip = opts[:ip] || rhost
407+
user = opts[:user] || nil
408+
domain = opts[:domain] || nil
409+
ntlm_ver = opts[:ntlm_ver] || nil
410+
lm_hash = opts[:lm_hash] || nil
411+
nt_hash = opts[:nt_hash] || nil
412+
lm_cli_challenge = opts[:lm_cli_challenge] || nil
413+
nt_cli_challenge = opts[:nt_cli_challenge] || nil
414+
415+
case ntlm_ver
416+
when NTLM_CONST::NTLM_V1_RESPONSE, NTLM_CONST::NTLM_2_SESSION_RESPONSE
417+
hash = [
418+
user, '',
419+
domain ? domain : 'NULL',
420+
lm_hash ? lm_hash : '0' * 48,
421+
nt_hash ? nt_hash : '0' * 48,
422+
@challenge.unpack('H*')[0]
423+
].join(':').gsub(/\n/, '\\n')
424+
report_hash(ip, user, 'netntlm', hash)
425+
when NTLM_CONST::NTLM_V2_RESPONSE
426+
hash = [
427+
user, '',
428+
domain ? domain : 'NULL',
429+
@challenge.unpack('H*')[0],
430+
lm_hash ? lm_hash : '0' * 32,
431+
lm_cli_challenge ? lm_cli_challenge : '0' * 16
432+
].join(':').gsub(/\n/, '\\n')
433+
report_hash(ip, user, 'netlmv2', hash)
434+
435+
hash = [
436+
user, '',
437+
domain ? domain : 'NULL',
438+
@challenge.unpack('H*')[0],
439+
nt_hash ? nt_hash : '0' * 32,
440+
nt_cli_challenge ? nt_cli_challenge : '0' * 160
441+
].join(':').gsub(/\n/, '\\n')
442+
report_hash(ip, user, 'netntlmv2', hash)
443+
else
444+
hash = domain + ':' +
445+
( lm_hash + lm_cli_challenge.to_s ? lm_hash + lm_cli_challenge.to_s : '00' * 24 ) + ':' +
446+
( nt_hash + nt_cli_challenge.to_s ? nt_hash + nt_cli_challenge.to_s : '00' * 24 ) + ':' +
447+
datastore['CHALLENGE'].to_s
448+
report_hash(ip, user, nil, hash)
449+
end
450+
end
451+
452+
def report_hash(ip, user, type_hash, hash)
453+
service_data = {
454+
address: ip,
455+
port: 445,
456+
service_name: 'smb',
457+
protocol: 'tcp',
458+
workspace_id: myworkspace_id
459+
}
460+
461+
credential_data = {
462+
module_fullname: self.fullname,
463+
origin_type: :service,
464+
private_data: hash,
465+
private_type: :nonreplayable_hash,
466+
username: user
467+
}.merge(service_data)
468+
469+
unless type_hash.nil?
470+
credential_data.merge!(jtr_format: type_hash)
471+
end
472+
473+
login_data = {
474+
core: create_credential(credential_data),
475+
status: Metasploit::Model::Login::Status::UNTRIED
476+
}.merge(service_data)
477+
478+
create_credential_login(login_data)
479+
end
480+
481+
409482
end

0 commit comments

Comments
 (0)