Skip to content

Commit 22f5347

Browse files
committed
Merge branch 'landing/4042' into upstream-master
Land rapid7#4042 the commit.
2 parents dbfe398 + 200d640 commit 22f5347

File tree

26 files changed

+50
-45
lines changed

26 files changed

+50
-45
lines changed

lib/msf/core/db_manager/host_tag.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ module Msf::DBManager::HostTag
33
# conditions and return hash as well.
44
def report_host_tag(opts)
55
name = opts.delete(:name)
6-
raise DBImportError.new("Missing required option :name") unless name
6+
raise Msf::DBImportError.new("Missing required option :name") unless name
77
addr = opts.delete(:addr)
8-
raise DBImportError.new("Missing required option :addr") unless addr
8+
raise Msf::DBImportError.new("Missing required option :addr") unless addr
99
wspace = opts.delete(:wspace)
10-
raise DBImportError.new("Missing required option :wspace") unless wspace
10+
raise Msf::DBImportError.new("Missing required option :wspace") unless wspace
1111
::ActiveRecord::Base.connection_pool.with_connection {
1212
if wspace.kind_of? String
1313
wspace = find_workspace(wspace)

lib/msf/core/db_manager/import.rb

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,18 @@ def import_file(args={}, &block)
107107
data = f.read(Metasploit::Credential::Exporter::Pwdump::FILE_ID_STRING.size)
108108
end
109109
if data.nil?
110-
raise DBImportError.new("Zero-length file")
110+
raise Msf::DBImportError.new("Zero-length file")
111111
end
112112

113113
if data.index(Metasploit::Credential::Exporter::Pwdump::FILE_ID_STRING)
114114
data = ::File.open(filename, 'rb')
115115
else
116116
case data[0,4]
117117
when "PK\x03\x04"
118-
data = Zip::File.open(filename)
118+
# When Msf::DBManager::Import::MetasploitFramework is included, it's child namespace of
119+
# Msf::DBManager::Import::MetasploitFramework::Zip becomes resolvable as Zip here, so need to use ::Zip so Zip
120+
# is resolved as one from rubyzip gem.
121+
data = ::Zip::File.open(filename)
119122
when "\xd4\xc3\xb2\xa1", "\xa1\xb2\xc3\xd4"
120123
data = PacketFu::PcapFile.new(:filename => filename)
121124
else
@@ -172,12 +175,14 @@ def import_file(args={}, &block)
172175
#
173176
# If there is no match, an error is raised instead.
174177
#
175-
# @raise DBImportError if the type can't be detected
178+
# @raise [Msf::DBImportError] if the type can't be detected
176179
def import_filetype_detect(data)
177-
178-
if data and data.kind_of? Zip::File
180+
# When Msf::DBManager::Import::MetasploitFramework is included, it's child namespace of
181+
# Msf::DBManager::Import::MetasploitFramework::Zip becomes resolvable as Zip here, so need to use ::Zip so Zip
182+
# is resolved as one from rubyzip gem.
183+
if data and data.kind_of? ::Zip::File
179184
if data.entries.empty?
180-
raise DBImportError.new("The zip file provided is empty.")
185+
raise Msf::DBImportError.new("The zip file provided is empty.")
181186
end
182187

183188
@import_filedata ||= {}
@@ -194,7 +199,7 @@ def import_filetype_detect(data)
194199

195200
# TODO This check for our zip export should be more extensive
196201
if xml_files.empty?
197-
raise DBImportError.new("The zip file provided is not a Metasploit Zip Export")
202+
raise Msf::DBImportError.new("The zip file provided is not a Metasploit Zip Export")
198203
end
199204

200205
@import_filedata[:zip_xml] = xml_files.first
@@ -207,7 +212,7 @@ def import_filetype_detect(data)
207212
# Don't check for emptiness here because unlike other formats, we
208213
# haven't read any actual data in yet, only magic bytes to discover
209214
# that this is indeed a pcap file.
210-
#raise DBImportError.new("The pcap file provided is empty.") if data.body.empty?
215+
#raise Msf::DBImportError.new("The pcap file provided is empty.") if data.body.empty?
211216
@import_filedata ||= {}
212217
@import_filedata[:type] = "Libpcap Packet Capture"
213218
return :libpcap
@@ -222,7 +227,7 @@ def import_filetype_detect(data)
222227
# This is a text string, lets make sure its treated as binary
223228
data = data.unpack("C*").pack("C*")
224229
if data and data.to_s.strip.length == 0
225-
raise DBImportError.new("The data provided to the import function was empty")
230+
raise Msf::DBImportError.new("The data provided to the import function was empty")
226231
end
227232

228233
# Parse the first line or 4k of data from the file
@@ -354,7 +359,7 @@ def import_filetype_detect(data)
354359
return :msf_pwdump
355360
end
356361

357-
raise DBImportError.new("Could not automatically determine file type")
362+
raise Msf::DBImportError.new("Could not automatically determine file type")
358363
end
359364

360365
# Handles timestamps from Metasploit Express/Pro imports.
@@ -440,7 +445,7 @@ def service_name_map(proto)
440445
def validate_import_file(data)
441446
begin
442447
import_filetype_detect(data)
443-
rescue DBImportError
448+
rescue Msf::DBImportError
444449
return false
445450
end
446451
return true

lib/msf/core/db_manager/import/acunetix.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def import_acunetix_xml(args={}, &block)
2727
end
2828
return true
2929
else # Sorry
30-
raise DBImportError.new("Could not import due to missing Nokogiri parser. Try 'gem install nokogiri'.")
30+
raise Msf::DBImportError.new("Could not import due to missing Nokogiri parser. Try 'gem install nokogiri'.")
3131
end
3232
end
3333

lib/msf/core/db_manager/import/amap.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def import_amap_log_file(args={})
4343
when :amap_mlog
4444
import_amap_mlog(args.merge(:data => data))
4545
else
46-
raise DBImportError.new("Could not determine file type")
46+
raise Msf::DBImportError.new("Could not determine file type")
4747
end
4848
end
4949

lib/msf/core/db_manager/import/appscan.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def import_appscan_xml(args={}, &block)
2727
end
2828
return true
2929
else # Sorry
30-
raise DBImportError.new("Could not import due to missing Nokogiri parser. Try 'gem install nokogiri'.")
30+
raise Msf::DBImportError.new("Could not import due to missing Nokogiri parser. Try 'gem install nokogiri'.")
3131
end
3232
end
3333
end

lib/msf/core/db_manager/import/burp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def import_burp_session_xml(args={}, &block)
2828
end
2929
return true
3030
else # Sorry
31-
raise DBImportError.new("Could not import due to missing Nokogiri parser. Try 'gem install nokogiri'.")
31+
raise Msf::DBImportError.new("Could not import due to missing Nokogiri parser. Try 'gem install nokogiri'.")
3232
end
3333
end
3434
end

lib/msf/core/db_manager/import/ci.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def import_ci_xml(args={}, &block)
2727
end
2828
return true
2929
else # Sorry
30-
raise DBImportError.new("Could not import due to missing Nokogiri parser. Try 'gem install nokogiri'.")
30+
raise Msf::DBImportError.new("Could not import due to missing Nokogiri parser. Try 'gem install nokogiri'.")
3131
end
3232
end
3333
end

lib/msf/core/db_manager/import/foundstone.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def import_foundstone_xml(args={}, &block)
2727
end
2828
return true
2929
else # Sorry
30-
raise DBImportError.new("Could not import due to missing Nokogiri parser. Try 'gem install nokogiri'.")
30+
raise Msf::DBImportError.new("Could not import due to missing Nokogiri parser. Try 'gem install nokogiri'.")
3131
end
3232
end
3333
end

lib/msf/core/db_manager/import/ip360/aspl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def import_ip360_aspl_xml(args={}, &block)
1010
bl = validate_ips(args[:blacklist]) ? args[:blacklist].split : []
1111

1212
if not data.index("<ontology")
13-
raise DBImportError.new("The ASPL file does not appear to be valid or may still be compressed")
13+
raise Msf::DBImportError.new("The ASPL file does not appear to be valid or may still be compressed")
1414
end
1515

1616
base = ::File.join(Msf::Config.config_directory, "data", "ncircle")

lib/msf/core/db_manager/import/ip360/v3.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def import_ip360_xml_v3(args={}, &block)
3939
end
4040

4141
if not aspl_path
42-
raise DBImportError.new("The nCircle IP360 ASPL file is not present.\n Download ASPL from nCircle VNE | Administer | Support | Resources, unzip it, and import it first")
42+
raise Msf::DBImportError.new("The nCircle IP360 ASPL file is not present.\n Download ASPL from nCircle VNE | Administer | Support | Resources, unzip it, and import it first")
4343
end
4444

4545
# parse nCircle ASPL file

0 commit comments

Comments
 (0)