Skip to content

Commit d6fb445

Browse files
committed
add begin...ensure block so that the CloseHandle call occurs
1 parent 1205c00 commit d6fb445

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

modules/post/windows/gather/file_in_raw_ntfs.rb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def initialize(info = {})
2525
))
2626
register_options(
2727
[
28-
OptString.new('FILE', [true, 'The FILE to retreive from the Volume raw device', ""])
28+
OptString.new('FILE', [true, 'The FILE to retreive from the Volume raw device', nil])
2929
], self.class)
3030
end
3131

@@ -55,15 +55,20 @@ def run
5555
@handle = r['return']
5656
print_status("Successfuly opened #{drive}")
5757

58-
fs = Rex::Parser::NTFS.new(self)
58+
begin
59+
fs = Rex::Parser::NTFS.new(self)
5960

60-
data = fs.file(file[3, file.length - 3])
61-
file_name = file.split("\\")[-1]
62-
print_status("Saving file #{file_name}")
63-
file_result = ::File.new(file_name, "w")
64-
file_result.syswrite(data)
65-
file_result.close
66-
client.railgun.kernel32.CloseHandle(@handle)
61+
data = fs.file(file[3, file.length - 3])
62+
file_name = file.split("\\")[-1]
63+
print_status("Saving file #{file_name}")
64+
file_result = ::File.new(file_name, "w")
65+
file_result.syswrite(data)
66+
file_result.close
67+
rescue ::Exception => e
68+
print_error("Post failed : #{e.backtrace}")
69+
ensure
70+
client.railgun.kernel32.CloseHandle(@handle)
71+
end
6772
print_status("Post Successfuly")
6873
end
6974

0 commit comments

Comments
 (0)