improvements to code commente and floe

master
Jeffrey Martin 2018-11-12 17:31:43 -06:00
parent 5ba44ff12d
commit d2a78cecd0
No known key found for this signature in database
GPG Key ID: 0CD9BBC2AF15F171
2 changed files with 46 additions and 51 deletions

View File

@ -97,11 +97,11 @@ module Msf::DBManager::Import
self.send "import_#{ftype}".to_sym, args.merge(workspace: wspace.name), &block
# post process the import here for missing default port maps
mrefs, mports, _mservs = Msf::Modules::Metadata::Cache.instance.all_remote_exploit_maps
# the map build above is a little expensive, another options is to do
# the map build above is a little expensive, another option is to do
# a host by ref search for each vuln ref and then check port reported for each module
# IMHO this front loaded cost here is worth it with only a small number of modules
# compared to the vast number of possible references offered by a Vulnerability scanner.
deferred_service_ports = [ 139 ] # I hate special cases, however 139 is not longer a preferred default
deferred_service_ports = [ 139 ] # I hate special cases, however 139 is no longer a preferred default
new_host_ids = Mdm::Host.where(workspace: wspace).map(&:id)
(new_host_ids - existing_host_ids).each do |id|
@ -123,10 +123,7 @@ module Msf::DBManager::Import
# Module names that match this vulnerability
matched = mrefs.values_at(*(vuln.refs.map { |x| x.name.upcase } & mrefs.keys)).map { |x| x.values }.flatten.uniq
next if matched.empty?
match_names = []
matched.each do |mod|
match_names << mod.full_name
end
match_names = matched.map { |mod| mod.full_name }
second_pass_services = []
@ -135,22 +132,20 @@ module Msf::DBManager::Import
second_pass_services << service
next
end
if mports[service.port]
if (match_names - mports[service.port].keys).count < match_names.count
serv = service
break
end
next unless mports[service.port]
if (match_names - mports[service.port].keys).count < match_names.count
serv = service
break
end
end
# post process any deferred services if no match has been found
if serv.nil? && !second_pass_services.empty?
second_pass_services.each do |service|
if mports[service.port]
if (match_names - mports[service.port].keys).count < match_names.count
serv = service
break
end
next unless mports[service.port]
if (match_names - mports[service.port].keys).count < match_names.count
serv = service
break
end
end
end

View File

@ -11,49 +11,49 @@ module Msf::Modules::Metadata::Maps
def all_remote_exploit_maps
unless @mrefs
mrefs = {}
mports = {}
mservs = {}
return @mrefs, @mports, @mservs if @mrefs && !@mrefs.empty?
get_metadata.each do |exploit|
next unless exploit.type == "exploit" && exploit.is_server
fullname = exploit.full_name
exploit.references.each do |reference|
next if reference =~ /^URL/
ref = reference
ref.upcase!
mrefs = {}
mports = {}
mservs = {}
mrefs[ref] ||= {}
mrefs[ref][fullname] = exploit
end
get_metadata.each do |exploit|
next unless exploit.type == "exploit" && exploit.is_server
fullname = exploit.full_name
exploit.references.each do |reference|
next if reference =~ /^URL/
ref = reference
ref.upcase!
if exploit.rport
rport = exploit.rport
mrefs[ref] ||= {}
mrefs[ref][fullname] = exploit
end
if exploit.rport
rport = exploit.rport
mports[rport.to_i] ||= {}
mports[rport.to_i][fullname] = exploit
end
unless exploit.autofilter_ports.nil? || exploit.autofilter_ports.empty?
exploit.autofilter_ports.each do |rport|
next unless port_allowed?(rport)
mports[rport.to_i] ||= {}
mports[rport.to_i][fullname] = exploit
end
unless exploit.autofilter_ports.nil? || exploit.autofilter_ports.empty?
exploit.autofilter_ports.each do |rport|
next unless port_allowed?(rport)
mports[rport.to_i] ||= {}
mports[rport.to_i][fullname] = exploit
end
end
unless exploit.autofilter_services.nil? || exploit.autofilter_services.empty?
exploit.autofilter_services.each do |serv|
mservs[serv] ||= {}
mservs[serv][fullname] = exploit
end
end
end
@mrefs = mrefs
@mports = mports
@mservs = mservs
unless exploit.autofilter_services.nil? || exploit.autofilter_services.empty?
exploit.autofilter_services.each do |serv|
mservs[serv] ||= {}
mservs[serv][fullname] = exploit
end
end
end
@mrefs = mrefs
@mports = mports
@mservs = mservs
return @mrefs, @mports, @mservs
end