Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new Datastore options to ssh_login #17727

Merged
merged 4 commits into from Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/metasploit/framework/login_scanner/base.rb
Expand Up @@ -45,6 +45,20 @@ module Base
# @!attribute bruteforce_speed
# @return [Integer] The desired speed, with 5 being 'fast' and 0 being 'slow.'
attr_accessor :bruteforce_speed
# @!attribute max_consecutive_error_count
# @return [Integer] Maximum consecutive errors allowed
attr_accessor :max_consecutive_error_count
# @!attribute max_error_count
# @return [Integer] Maximum errors allowed
attr_accessor :max_error_count

validates :max_consecutive_error_count,
presence: true,
numericality: {
only_integer: true,
greater_than_or_equal_to: 1,
less_than_or_equal_to: :max_error_count
}

validates :connection_timeout,
presence: true,
Expand Down Expand Up @@ -247,8 +261,8 @@ def scan!
if result.status == Metasploit::Model::Login::Status::UNABLE_TO_CONNECT
consecutive_error_count += 1
total_error_count += 1
break if consecutive_error_count >= 3
break if total_error_count >= 10
break if consecutive_error_count >= max_consecutive_error_count
break if total_error_count >= max_error_count
end
end
end
Expand Down Expand Up @@ -297,6 +311,8 @@ def host_address_must_be_valid
# @return [void]
def set_sane_defaults
self.connection_timeout = 30 if self.connection_timeout.nil?
self.max_consecutive_error_count = 3 if self.max_consecutive_error_count.nil?
self.max_error_count = 10 if self.max_error_count.nil?
end

# This method validates that the credentials supplied
Expand Down
8 changes: 6 additions & 2 deletions modules/auxiliary/scanner/ssh/ssh_login.rb
Expand Up @@ -44,7 +44,9 @@ def initialize
Opt::Proxies,
OptBool.new('SSH_DEBUG', [false, 'Enable SSH debugging output (Extreme verbosity!)', false]),
OptInt.new('SSH_TIMEOUT', [false, 'Specify the maximum time to negotiate a SSH session', 30]),
OptBool.new('GatherProof', [true, 'Gather proof of access via pre-session shell commands', true])
OptBool.new('GatherProof', [true, 'Gather proof of access via pre-session shell commands', true]),
OptInt.new('MaxErrorCount', [true, "Total errors allowed while connecting", 10]),
OptInt.new('MaxConsecutiveErrorCount', [true, "Maximum consecutive errors allowed while connecting", 3])
]
)

Expand Down Expand Up @@ -108,7 +110,9 @@ def run_host(ip)
connection_timeout: datastore['SSH_TIMEOUT'],
framework: framework,
framework_module: self,
skip_gather_proof: !datastore['GatherProof']
skip_gather_proof: !datastore['GatherProof'],
max_consecutive_error_count: datastore['MaxConsecutiveErrorCount'],
max_error_count: datastore['MaxErrorCount']
)

scanner.verbosity = :debug if datastore['SSH_DEBUG']
Expand Down