Skip to content

Commit 1c35ec4

Browse files
committed
Land rapid7#3585, fix fd leak in pwdump import
Conflicts: db/schema.rb
2 parents f7aa324 + 3e915e5 commit 1c35ec4

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ group :db do
77
# Needed for Msf::DbManager
88
gem 'activerecord', '>= 3.0.0', '< 4.0.0'
99
# Metasploit::Credential database models
10-
gem 'metasploit-credential', '~> 0.7.14', '< 0.8'
10+
gem 'metasploit-credential', '~>0.8.2'
1111
# Database models shared between framework and Pro.
1212
gem 'metasploit_data_models', '~> 0.19'
1313
# Needed for module caching in Mdm::ModuleDetails

Gemfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ GEM
6161
json (1.8.1)
6262
metasploit-concern (0.1.1)
6363
activesupport (~> 3.0, >= 3.0.0)
64-
metasploit-credential (0.7.16)
64+
metasploit-credential (0.8.2)
6565
metasploit-concern (~> 0.1.0)
66-
metasploit-model (>= 0.25.6)
67-
metasploit_data_models (~> 0.19)
66+
metasploit-model (~> 0.26.1)
67+
metasploit_data_models (~> 0.19.4)
6868
pg
6969
rubyntlm
7070
rubyzip (~> 1.1)
@@ -160,7 +160,7 @@ DEPENDENCIES
160160
factory_girl (>= 4.1.0)
161161
factory_girl_rails
162162
fivemat (= 1.2.1)
163-
metasploit-credential (~> 0.7.14, < 0.8)
163+
metasploit-credential (~> 0.8.2)
164164
metasploit-framework!
165165
metasploit_data_models (~> 0.19)
166166
network_interface (~> 0.0.1)

lib/msf/core/db.rb

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2897,28 +2897,26 @@ def import_file(args={}, &block)
28972897

28982898
data = ""
28992899
::File.open(filename, 'rb') do |f|
2900-
data = f.read(4)
2900+
# This check is the largest (byte-wise) that we need to do
2901+
# since the other 4-byte checks will be subsets of this larger one.
2902+
data = f.read(Metasploit::Credential::Exporter::Pwdump::FILE_ID_STRING.size)
29012903
end
29022904
if data.nil?
29032905
raise DBImportError.new("Zero-length file")
29042906
end
29052907

2906-
io = File.open(filename)
2907-
first_line = io.gets
2908-
io.rewind
2909-
2910-
if first_line.index("# Metasploit PWDump Export")
2911-
data = io
2908+
if data.index(Metasploit::Credential::Exporter::Pwdump::FILE_ID_STRING)
2909+
data = ::File.open(filename, 'rb')
29122910
else
29132911
case data[0,4]
2914-
when "PK\x03\x04"
2915-
data = Zip::File.open(filename)
2916-
when "\xd4\xc3\xb2\xa1", "\xa1\xb2\xc3\xd4"
2917-
data = PacketFu::PcapFile.new(:filename => filename)
2918-
else
2919-
::File.open(filename, 'rb') do |f|
2920-
sz = f.stat.size
2921-
data = f.read(sz)
2912+
when "PK\x03\x04"
2913+
data = Zip::File.open(filename)
2914+
when "\xd4\xc3\xb2\xa1", "\xa1\xb2\xc3\xd4"
2915+
data = PacketFu::PcapFile.new(:filename => filename)
2916+
else
2917+
::File.open(filename, 'rb') do |f|
2918+
sz = f.stat.size
2919+
data = f.read(sz)
29222920
end
29232921
end
29242922
end
@@ -2929,7 +2927,6 @@ def import_file(args={}, &block)
29292927
else
29302928
import(args.merge(:data => data))
29312929
end
2932-
29332930
end
29342931

29352932
# A dispatcher method that figures out the data's file type,
@@ -3539,6 +3536,7 @@ def import_msf_pwdump(args={}, &block)
35393536
origin = Metasploit::Credential::Origin::Import.create!(filename: filename)
35403537
importer = Metasploit::Credential::Importer::Pwdump.new(input: args[:data], workspace: wspace, filename: filename, origin:origin)
35413538
importer.import!
3539+
importer.input.close unless importer.input.closed?
35423540
end
35433541

35443542
# If hex notation is present, turn them into a character.

0 commit comments

Comments
 (0)