Skip to content

Commit 1a4db84

Browse files
committed
Refactor build_brute_message for legacy printing
1 parent 3396afb commit 1a4db84

File tree

2 files changed

+32
-46
lines changed

2 files changed

+32
-46
lines changed

lib/msf/core/auxiliary/auth_brute.rb

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ def load_password_vars(credentials = nil)
362362
# Note, these special username/passwords should get deprecated
363363
# some day. Note2: Don't use with SMB and FTP at the same time!
364364
def translate_proto_datastores
365-
switched = false
366365
['SMBUser','FTPUSER'].each do |u|
367366
if datastore[u] and !datastore[u].empty?
368367
datastore['USERNAME'] = datastore[u]
@@ -547,6 +546,20 @@ def vprint_brute(opts={})
547546
end
548547
end
549548

549+
def vprint_status(msg='')
550+
print_brute :level => :vstatus
551+
end
552+
553+
def vprint_error(msg='')
554+
print_brute :level => :verror
555+
end
556+
557+
alias_method :vprint_bad, :vprint_error
558+
559+
def vprint_good(msg='')
560+
print_brute :level => :vgood
561+
end
562+
550563
# Provides a consistant way to display messages about AuthBrute-mixed modules.
551564
# Acceptable opts are fairly self-explanatory, but :level can be tricky.
552565
#
@@ -568,10 +581,10 @@ def print_brute(opts={})
568581
end
569582
host_ip = opts[:ip] || opts[:rhost] || opts[:host] || (rhost rescue nil) || datastore['RHOST']
570583
host_port = opts[:port] || opts[:rport] || (rport rescue nil) || datastore['RPORT']
571-
msg = opts[:msg] || opts[:message] || opts[:legacy_msg]
584+
msg = opts[:msg] || opts[:message]
572585
proto = opts[:proto] || opts[:protocol] || proto_from_fullname
573586

574-
complete_message = build_brute_message(host_ip,host_port,proto,msg,!!opts[:legacy_msg])
587+
complete_message = build_brute_message(host_ip,host_port,proto,msg)
575588

576589
print_method = "print_#{level}"
577590
if self.respond_to? print_method
@@ -582,34 +595,24 @@ def print_brute(opts={})
582595
end
583596

584597
# Depending on the non-nil elements, build up a standardized
585-
# auth_brute message, but support the old style used by
586-
# vprint_status and friends as well.
587-
def build_brute_message(host_ip,host_port,proto,msg,legacy)
598+
# auth_brute message.
599+
def build_brute_message(host_ip,host_port,proto,msg)
588600
ip = host_ip.to_s.strip if host_ip
589601
port = host_port.to_s.strip if host_port
590602
complete_message = nil
591-
extracted_message = nil
592-
if legacy # TODO: This is all a workaround until I get a chance to get rid of the legacy messages
593-
old_msg = msg.to_s.strip
594-
msg_regex = /(#{ip})(:#{port})?(\s*-?\s*)(#{proto.to_s})?(\s*-?\s*)(.*)/ni
595-
if old_msg.match(msg_regex) and !old_msg.match(msg_regex)[6].to_s.strip.empty?
596-
complete_message = ''
597-
unless ip.blank? && port.blank?
598-
complete_message << "#{ip}:#{rport}"
599-
else
600-
complete_message << (old_msg.match(msg_regex)[4] || proto).to_s
601-
end
602-
603-
complete_message << " - "
604-
progress = tried_over_total(ip,port)
605-
complete_message << progress if progress
606-
complete_message << old_msg.match(msg_regex)[6].to_s.strip
607-
else
608-
complete_message = msg.to_s.strip
609-
end
603+
old_msg = msg.to_s.strip
604+
msg_regex = /(#{ip})(:#{port})?(\s*-?\s*)(#{proto.to_s})?(\s*-?\s*)(.*)/ni
605+
if old_msg.match(msg_regex)
606+
complete_message = msg.to_s.strip
610607
else
611608
complete_message = ''
612-
complete_message << "#{proto.to_s.strip} - " if proto
609+
unless ip.blank? && port.blank?
610+
complete_message << "#{ip}:#{rport}"
611+
else
612+
complete_message << proto || 'Bruteforce'
613+
end
614+
615+
complete_message << " - "
613616
progress = tried_over_total(ip,port)
614617
complete_message << progress if progress
615618
complete_message << msg.to_s.strip
@@ -657,23 +660,6 @@ def proto_from_fullname
657660
File.split(self.fullname).last.match(/^(.*)_(login|auth|identify)/)[1].upcase rescue nil
658661
end
659662

660-
# Legacy vprint
661-
def vprint_status(msg='')
662-
print_brute :level => :vstatus, :legacy_msg => msg
663-
end
664-
665-
# Legacy vprint
666-
def vprint_error(msg='')
667-
print_brute :level => :verror, :legacy_msg => msg
668-
end
669-
670-
alias_method :vprint_bad, :vprint_error
671-
672-
# Legacy vprint
673-
def vprint_good(msg='')
674-
print_brute :level => :vgood, :legacy_msg => msg
675-
end
676-
677663
# This method deletes the dictionary files if requested
678664
def cleanup_files
679665
path = datastore['USERPASS_FILE']

modules/auxiliary/scanner/ssh/ssh_login.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,19 @@ def run_host(ip)
131131
)
132132
case result.status
133133
when Metasploit::Model::Login::Status::SUCCESSFUL
134-
print_brute :level => :good, :ip => ip, :msg => "#{ip}:#{rport} - Success: '#{result.credential}' '#{result.proof.to_s.gsub(/[\r\n\e\b\a]/, ' ')}'"
134+
print_brute :level => :good, :ip => ip, :msg => "Success: '#{result.credential}' '#{result.proof.to_s.gsub(/[\r\n\e\b\a]/, ' ')}'"
135135
credential_core = create_credential(credential_data)
136136
credential_data[:core] = credential_core
137137
create_credential_login(credential_data)
138138
session_setup(result, scanner.ssh_socket)
139139
:next_user
140140
when Metasploit::Model::Login::Status::UNABLE_TO_CONNECT
141-
vprint_brute :level => :verror, :ip => ip, :msg => "#{ip}:#{rport} - Could not connect: #{result.proof}"
141+
vprint_brute :level => :verror, :ip => ip, :msg => "Could not connect: #{result.proof}"
142142
scanner.ssh_socket.close if scanner.ssh_socket && !scanner.ssh_socket.closed?
143143
invalidate_login(credential_data)
144144
:abort
145145
when Metasploit::Model::Login::Status::INCORRECT
146-
vprint_brute :level => :verror, :ip => ip, :msg => "#{ip}:#{rport} - Failed: '#{result.credential}'"
146+
vprint_brute :level => :verror, :ip => ip, :msg => "Failed: '#{result.credential}'"
147147
invalidate_login(credential_data)
148148
scanner.ssh_socket.close if scanner.ssh_socket && !scanner.ssh_socket.closed?
149149
else

0 commit comments

Comments
 (0)