Skip to content

Commit 8fda4ee

Browse files
committed
Fix fd leak and blind IO#gets in pwdump import
MSP-10715
1 parent 7a49f21 commit 8fda4ee

File tree

4 files changed

+27
-26
lines changed

4 files changed

+27
-26
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.10.pre.core.pre.search', '< 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: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ GEM
4141
i18n (~> 0.6, >= 0.6.4)
4242
multi_json (~> 1.0)
4343
arel (3.0.3)
44-
arel-helpers (2.0.0)
44+
arel-helpers (2.0.1)
4545
activerecord (>= 3.1.0, < 5)
4646
bcrypt (3.1.7)
4747
builder (3.0.4)
@@ -60,21 +60,21 @@ GEM
6060
json (1.8.1)
6161
metasploit-concern (0.1.1)
6262
activesupport (~> 3.0, >= 3.0.0)
63-
metasploit-credential (0.7.10.pre.core.pre.search)
63+
metasploit-credential (0.8.2)
6464
metasploit-concern (~> 0.1.0)
65-
metasploit-model (>= 0.25.6)
66-
metasploit_data_models (~> 0.19)
65+
metasploit-model (~> 0.26.1)
66+
metasploit_data_models (~> 0.19.4)
6767
pg
6868
rubyntlm
6969
rubyzip (~> 1.1)
70-
metasploit-model (0.25.6)
70+
metasploit-model (0.26.1)
7171
activesupport
72-
metasploit_data_models (0.19.0)
72+
metasploit_data_models (0.19.4)
7373
activerecord (>= 3.2.13, < 4.0.0)
7474
activesupport
7575
arel-helpers
7676
metasploit-concern (~> 0.1.0)
77-
metasploit-model (>= 0.25.1, < 0.26)
77+
metasploit-model (~> 0.26.1)
7878
pg
7979
meterpreter_bins (0.0.6)
8080
method_source (0.8.2)
@@ -159,7 +159,7 @@ DEPENDENCIES
159159
factory_girl (>= 4.1.0)
160160
factory_girl_rails
161161
fivemat (= 1.2.1)
162-
metasploit-credential (>= 0.7.10.pre.core.pre.search, < 0.8)
162+
metasploit-credential (~> 0.8.2)
163163
metasploit-framework!
164164
metasploit_data_models (~> 0.19)
165165
network_interface (~> 0.0.1)

db/schema.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended to check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(:version => 20140703144541) do
14+
ActiveRecord::Schema.define(:version => 20140728191933) do
1515

1616
create_table "api_keys", :force => true do |t|
1717
t.text "token"
@@ -193,6 +193,9 @@
193193
add_index "metasploit_credential_cores", ["private_id"], :name => "index_metasploit_credential_cores_on_private_id"
194194
add_index "metasploit_credential_cores", ["public_id"], :name => "index_metasploit_credential_cores_on_public_id"
195195
add_index "metasploit_credential_cores", ["realm_id"], :name => "index_metasploit_credential_cores_on_realm_id"
196+
add_index "metasploit_credential_cores", ["workspace_id", "private_id", "public_id"], :name => "unique_complete_metasploit_credential_cores", :unique => true
197+
add_index "metasploit_credential_cores", ["workspace_id", "private_id"], :name => "unique_private_metasploit_credential_cores", :unique => true
198+
add_index "metasploit_credential_cores", ["workspace_id", "public_id"], :name => "unique_public_metasploit_credential_cores", :unique => true
196199
add_index "metasploit_credential_cores", ["workspace_id"], :name => "index_metasploit_credential_cores_on_workspace_id"
197200

198201
create_table "metasploit_credential_logins", :force => true do |t|

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)