Skip to content

Commit 69c4ae9

Browse files
author
Brent Cook
committed
Land rapid7#8811, fix peer printing with bruteforce modules
2 parents b8f56d1 + 1a4db84 commit 69c4ae9

File tree

2 files changed

+36
-54
lines changed

2 files changed

+36
-54
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: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@ class MetasploitModule < Msf::Auxiliary
1717

1818
def initialize
1919
super(
20-
'Name' => 'SSH Login Check Scanner',
21-
'Description' => %q{
20+
'Name' => 'SSH Login Check Scanner',
21+
'Description' => %q{
2222
This module will test ssh logins on a range of machines and
2323
report successful logins. If you have loaded a database plugin
2424
and connected to a database this module will record successful
2525
logins and hosts so you can track your access.
2626
},
27-
'Author' => ['todb'],
27+
'Author' => ['todb'],
2828
'References' =>
2929
[
3030
[ 'CVE', '1999-0502'] # Weak password
3131
],
32-
'License' => MSF_LICENSE
32+
'License' => MSF_LICENSE,
33+
'DefaultOptions' => {'VERBOSE' => false} # Disable annoying connect errors
3334
)
3435

3536
register_options(
@@ -95,7 +96,6 @@ def session_setup(result, ssh_socket)
9596

9697
def run_host(ip)
9798
@ip = ip
98-
print_brute :ip => ip, :msg => "Starting bruteforce"
9999

100100
cred_collection = Metasploit::Framework::CredentialCollection.new(
101101
blank_passwords: datastore['BLANK_PASSWORDS'],
@@ -138,16 +138,12 @@ def run_host(ip)
138138
session_setup(result, scanner.ssh_socket)
139139
:next_user
140140
when Metasploit::Model::Login::Status::UNABLE_TO_CONNECT
141-
if datastore['VERBOSE']
142-
print_brute :level => :verror, :ip => ip, :msg => "Could not connect: #{result.proof}"
143-
end
141+
vprint_brute :level => :verror, :ip => ip, :msg => "Could not connect: #{result.proof}"
144142
scanner.ssh_socket.close if scanner.ssh_socket && !scanner.ssh_socket.closed?
145143
invalidate_login(credential_data)
146144
:abort
147145
when Metasploit::Model::Login::Status::INCORRECT
148-
if datastore['VERBOSE']
149-
print_brute :level => :verror, :ip => ip, :msg => "Failed: '#{result.credential}'"
150-
end
146+
vprint_brute :level => :verror, :ip => ip, :msg => "Failed: '#{result.credential}'"
151147
invalidate_login(credential_data)
152148
scanner.ssh_socket.close if scanner.ssh_socket && !scanner.ssh_socket.closed?
153149
else

0 commit comments

Comments
 (0)