Skip to content

Commit

Permalink
handle hostnames that are passed in instead of addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent Cook committed Jun 8, 2017
1 parent 08eeb8c commit d04ce63
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/metasploit/credential/creation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'rex/socket'

# Implements a set of "convenience methods" for creating credentials and related portions of the object graph. Creates
# {Metasploit::Credential::Core} objects and their attendant relationships as well as {Metasploit::Credential::Login}
# objects and their attendant `Mdm::Host` and `Mdm::Service` objects.
Expand Down Expand Up @@ -116,6 +118,7 @@ def create_credential(opts={})
else
origin = create_credential_origin(opts)
end
return nil if origin.nil?

core_opts = {
origin: origin,
Expand All @@ -125,7 +128,7 @@ def create_credential(opts={})
if opts.has_key?(:realm_key) && opts.has_key?(:realm_value)
core_opts[:realm] = create_credential_realm(opts)
end

if opts.has_key?(:private_type) && opts.has_key?(:private_data)
core_opts[:private] = create_credential_private(opts)
end
Expand All @@ -140,7 +143,7 @@ def create_credential(opts={})

create_credential_core(core_opts)
end

# This method is responsible for creation {Metasploit::Credential::Core} and
# {Metasploit::Credential::Login}.
# This method is responsible for creating a {Metasploit::Credential::Login} object
Expand Down Expand Up @@ -188,8 +191,6 @@ def create_credential(opts={})
# service_name: 'smb',
# status: status: Metasploit::Model::Login::Status::UNTRIED
# )


def create_credential_and_login(opts={})
return nil unless active_db?

Expand All @@ -205,6 +206,7 @@ def create_credential_and_login(opts={})
login_object = nil
retry_transaction do
service_object = create_credential_service(opts)
return nil if service_object.nil?
login_object = Metasploit::Credential::Login.where(core_id: core.id, service_id: service_object.id).first_or_initialize

if opts[:task_id]
Expand Down Expand Up @@ -297,6 +299,7 @@ def create_credential_login(opts={})
login_object = nil
retry_transaction do
service_object = create_credential_service(opts)
return nil if service_object.nil?
login_object = Metasploit::Credential::Login.where(core_id: core.id, service_id: service_object.id).first_or_initialize

if opts[:task_id]
Expand Down Expand Up @@ -419,13 +422,12 @@ def create_credential_origin_manual(opts={})
def create_credential_origin_service(opts={})
return nil unless active_db?
module_fullname = opts.fetch(:module_fullname)

service_object = create_credential_service(opts)
return nil if service_object.nil?

retry_transaction do
Metasploit::Credential::Origin::Service.where(service_id: service_object.id, module_full_name: module_fullname).first_or_create!
end

end

# This method is responsible for creating {Metasploit::Credential::Origin::Session} objects.
Expand Down Expand Up @@ -547,6 +549,7 @@ def create_credential_realm(opts={})
def create_credential_service(opts={})
return nil unless active_db?
address = opts.fetch(:address)
return nil unless Rex::Socket.is_ipv4?(address) || Rex::Socket.is_ipv6?(address)
port = opts.fetch(:port)
service_name = opts.fetch(:service_name)
protocol = opts.fetch(:protocol)
Expand Down Expand Up @@ -577,6 +580,7 @@ def create_credential_service(opts={})
def invalidate_login(opts = {})
return nil unless active_db?
address = opts.fetch(:address)
return nil unless Rex::Socket.is_ipv4?(address) || Rex::Socket.is_ipv6?(address)
port = opts.fetch(:port)
protocol = opts.fetch(:protocol)
public = opts.fetch(:username, nil)
Expand Down
2 changes: 2 additions & 0 deletions metasploit-credential.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Gem::Specification.new do |s|
# Required for supporting the en masse importation of SSH Keys
s.add_runtime_dependency 'rubyzip'

s.add_runtime_dependency 'rex-socket'

if RUBY_PLATFORM =~ /java/
s.add_runtime_dependency 'jdbc-postgres'
s.add_runtime_dependency 'activerecord-jdbcpostgresql-adapter'
Expand Down

0 comments on commit d04ce63

Please sign in to comment.