@@ -2897,28 +2897,26 @@ def import_file(args={}, &block)
2897
2897
2898
2898
data = ""
2899
2899
::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 )
2901
2903
end
2902
2904
if data . nil?
2903
2905
raise DBImportError . new ( "Zero-length file" )
2904
2906
end
2905
2907
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' )
2912
2910
else
2913
2911
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 )
2922
2920
end
2923
2921
end
2924
2922
end
@@ -2929,7 +2927,6 @@ def import_file(args={}, &block)
2929
2927
else
2930
2928
import ( args . merge ( :data => data ) )
2931
2929
end
2932
-
2933
2930
end
2934
2931
2935
2932
# A dispatcher method that figures out the data's file type,
@@ -3539,6 +3536,7 @@ def import_msf_pwdump(args={}, &block)
3539
3536
origin = Metasploit ::Credential ::Origin ::Import . create! ( filename : filename )
3540
3537
importer = Metasploit ::Credential ::Importer ::Pwdump . new ( input : args [ :data ] , workspace : wspace , filename : filename , origin :origin )
3541
3538
importer . import!
3539
+ importer . input . close unless importer . input . closed?
3542
3540
end
3543
3541
3544
3542
# If hex notation is present, turn them into a character.
0 commit comments