Land #16309, Catch an exception in ssh_login

The ssh_login module would crash when the channel used to execute the
commands to gather the platform information reported that they failed.
This commit is contained in:
Spencer McIntyre 2022-03-17 16:41:47 -04:00
commit ccdc2db9e7
No known key found for this signature in database
GPG Key ID: 58101BA0D0D9C987
2 changed files with 16 additions and 2 deletions

View File

@ -94,7 +94,12 @@ module Metasploit
unless result_options.has_key? :status unless result_options.has_key? :status
if ssh_socket if ssh_socket
proof = gather_proof unless skip_gather_proof begin
proof = gather_proof unless skip_gather_proof
rescue StandardError => e
elog('Failed to gather SSH proof', error: e)
proof = nil
end
result_options.merge!(status: Metasploit::Model::Login::Status::SUCCESSFUL, proof: proof) result_options.merge!(status: Metasploit::Model::Login::Status::SUCCESSFUL, proof: proof)
else else
result_options.merge!(status: Metasploit::Model::Login::Status::INCORRECT, proof: nil) result_options.merge!(status: Metasploit::Model::Login::Status::INCORRECT, proof: nil)

View File

@ -126,7 +126,16 @@ class MetasploitModule < Msf::Auxiliary
credential_core = create_credential(credential_data) credential_core = create_credential(credential_data)
credential_data[:core] = credential_core credential_data[:core] = credential_core
create_credential_login(credential_data) create_credential_login(credential_data)
session_setup(result, scanner) if datastore['CreateSession']
if datastore['CreateSession']
begin
session_setup(result, scanner)
rescue StandardError => e
elog('Failed to setup the session', error: e)
print_brute :level => :error, :ip => ip, :msg => "Failed to setup the session - #{e.class} #{e.message}"
end
end
if datastore['GatherProof'] && scanner.get_platform(result.proof) == 'unknown' if datastore['GatherProof'] && scanner.get_platform(result.proof) == 'unknown'
msg = "While a session may have opened, it may be bugged. If you experience issues with it, re-run this module with" msg = "While a session may have opened, it may be bugged. If you experience issues with it, re-run this module with"
msg << " 'set gatherproof false'. Also consider submitting an issue at github.com/rapid7/metasploit-framework with" msg << " 'set gatherproof false'. Also consider submitting an issue at github.com/rapid7/metasploit-framework with"