parent
36dd10e1c2
commit
a613d044f5
|
@ -7,10 +7,20 @@ module Metasploit
|
||||||
|
|
||||||
class Result
|
class Result
|
||||||
|
|
||||||
|
# @!attribute [r] private
|
||||||
|
# @return [String] the private(e.g. password) component
|
||||||
attr_reader :private
|
attr_reader :private
|
||||||
|
# @!attribute [r] proof
|
||||||
|
# @return [String,nil] the proof that the lgoin was successful
|
||||||
attr_reader :proof
|
attr_reader :proof
|
||||||
|
# @!attribute [r] public
|
||||||
|
# @return [String] the public(e.g. username) component
|
||||||
attr_reader :public
|
attr_reader :public
|
||||||
|
# @!attribute [r] realm
|
||||||
|
# @return [String] the realm(e.g. domain name) component
|
||||||
attr_reader :realm
|
attr_reader :realm
|
||||||
|
# @!attribute [r] status
|
||||||
|
# @return [Symbol] the status of the attempt (e.g. success, failed, etc)
|
||||||
attr_reader :status
|
attr_reader :status
|
||||||
|
|
||||||
# @param [Hash] opts The options hash for the initializer
|
# @param [Hash] opts The options hash for the initializer
|
||||||
|
|
|
@ -11,6 +11,17 @@ module Metasploit
|
||||||
class SSH
|
class SSH
|
||||||
include ActiveModel::Validations
|
include ActiveModel::Validations
|
||||||
|
|
||||||
|
#
|
||||||
|
# CONSTANTS
|
||||||
|
#
|
||||||
|
|
||||||
|
VERBOSITIES = [
|
||||||
|
:debug,
|
||||||
|
:info,
|
||||||
|
:warn,
|
||||||
|
:error,
|
||||||
|
:fatal
|
||||||
|
]
|
||||||
|
|
||||||
# @!attribute connection_timeout
|
# @!attribute connection_timeout
|
||||||
# @return [Fixnum] The timeout in seconds for a single SSH connection
|
# @return [Fixnum] The timeout in seconds for a single SSH connection
|
||||||
|
@ -37,9 +48,22 @@ module Metasploit
|
||||||
# @return [Array] Array of results that successfully logged in
|
# @return [Array] Array of results that successfully logged in
|
||||||
attr_accessor :successes
|
attr_accessor :successes
|
||||||
# @!attribute verbosity
|
# @!attribute verbosity
|
||||||
# @return [Symbol] The verbosity level for the SSH client.
|
# The verbosity level for the SSH client.
|
||||||
|
#
|
||||||
|
# @return [Symbol] An element of {VERBOSITIES}.
|
||||||
attr_accessor :verbosity
|
attr_accessor :verbosity
|
||||||
|
|
||||||
|
validates :connection_timeout,
|
||||||
|
presence: true,
|
||||||
|
numericality: {
|
||||||
|
only_integer: true,
|
||||||
|
greater_than_or_equal_to: 1
|
||||||
|
}
|
||||||
|
|
||||||
|
validates :cred_details, presence: true
|
||||||
|
|
||||||
|
validates :host, presence: true
|
||||||
|
|
||||||
validates :port,
|
validates :port,
|
||||||
presence: true,
|
presence: true,
|
||||||
numericality: {
|
numericality: {
|
||||||
|
@ -48,23 +72,12 @@ module Metasploit
|
||||||
less_than_or_equal_to: 65535
|
less_than_or_equal_to: 65535
|
||||||
}
|
}
|
||||||
|
|
||||||
validates :connection_timeout,
|
validates :stop_on_success,
|
||||||
presence: true,
|
inclusion: { in: [true, false] }
|
||||||
numericality: {
|
|
||||||
only_integer: true,
|
|
||||||
greater_than_or_equal_to: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
validates :verbosity,
|
validates :verbosity,
|
||||||
presence: true,
|
presence: true,
|
||||||
inclusion: { in: [:debug, :info, :warn, :error, :fatal] }
|
inclusion: { in: VERBOSITIES }
|
||||||
|
|
||||||
validates :stop_on_success,
|
|
||||||
inclusion: { in: [true, false] }
|
|
||||||
|
|
||||||
validates :host, presence: true
|
|
||||||
|
|
||||||
validates :cred_details, presence: true
|
|
||||||
|
|
||||||
validate :host_address_must_be_valid
|
validate :host_address_must_be_valid
|
||||||
|
|
||||||
|
@ -75,8 +88,8 @@ module Metasploit
|
||||||
attributes.each do |attribute, value|
|
attributes.each do |attribute, value|
|
||||||
public_send("#{attribute}=", value)
|
public_send("#{attribute}=", value)
|
||||||
end
|
end
|
||||||
public_send("successes=", [])
|
self.successes= []
|
||||||
public_send("failures=", [])
|
self.failures=[]
|
||||||
end
|
end
|
||||||
|
|
||||||
def attempt_login(user, pass)
|
def attempt_login(user, pass)
|
||||||
|
@ -90,6 +103,11 @@ module Metasploit
|
||||||
:verbose => verbosity
|
:verbose => verbosity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result_options = {
|
||||||
|
private: pass,
|
||||||
|
public: user,
|
||||||
|
realm: nil
|
||||||
|
}
|
||||||
begin
|
begin
|
||||||
::Timeout.timeout(connection_timeout) do
|
::Timeout.timeout(connection_timeout) do
|
||||||
ssh_socket = Net::SSH.start(
|
ssh_socket = Net::SSH.start(
|
||||||
|
@ -98,43 +116,23 @@ module Metasploit
|
||||||
opt_hash
|
opt_hash
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
rescue Rex::ConnectionError, Rex::AddressInUse, Net::SSH::Disconnect, ::EOFError, ::Timeout::Error
|
rescue ::EOFError, Net::SSH::Disconnect, Rex::AddressInUse, Rex::ConnectionError, ::Timeout::Error
|
||||||
return ::Metasploit::Framework::LoginScanner::Result.new(
|
result_options.merge!( proof: nil, status: :connection_error)
|
||||||
private: pass,
|
|
||||||
proof: nil,
|
|
||||||
public: user,
|
|
||||||
realm: nil,
|
|
||||||
status: :connection_error
|
|
||||||
)
|
|
||||||
rescue Net::SSH::Exception
|
rescue Net::SSH::Exception
|
||||||
return ::Metasploit::Framework::LoginScanner::Result.new(
|
result_options.merge!( proof: nil, status: :failed)
|
||||||
private: pass,
|
|
||||||
proof: nil,
|
|
||||||
public: user,
|
|
||||||
realm: nil,
|
|
||||||
status: :failed
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if ssh_socket
|
unless result_options.has_key? :status
|
||||||
proof = gather_proof
|
if ssh_socket
|
||||||
::Metasploit::Framework::LoginScanner::Result.new(
|
proof = gather_proof
|
||||||
private: pass,
|
result_options.merge!( proof: proof, status: :success)
|
||||||
proof: proof,
|
else
|
||||||
public: user,
|
result_options.merge!( proof: nil, status: :failed)
|
||||||
realm: nil,
|
end
|
||||||
status: :success
|
|
||||||
)
|
|
||||||
else
|
|
||||||
::Metasploit::Framework::LoginScanner::Result.new(
|
|
||||||
private: pass,
|
|
||||||
proof: nil,
|
|
||||||
public: user,
|
|
||||||
realm: nil,
|
|
||||||
status: :failed
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
::Metasploit::Framework::LoginScanner::Result.new(result_options)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def scan!
|
def scan!
|
||||||
|
|
Loading…
Reference in New Issue