Skip to content

Commit 9518090

Browse files
committed
Ignore some error conditions
1 parent cc4fc1a commit 9518090

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

modules/post/windows/gather/file_in_raw_ntfs.rb

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
##
55

66
require 'rex/parser/fs/ntfs'
7-
7+
require 'action_view/helpers/number_helper'
88
class Metasploit3 < Msf::Post
99
include Msf::Post::Windows::Priv
10+
include Msf::Post::Windows::Error
11+
12+
ERROR = Msf::Post::Windows::Error
1013

1114
def initialize(info = {})
1215
super(update_info(info,
@@ -40,10 +43,19 @@ def run
4043

4144
r = client.railgun.kernel32.GetFileAttributesW(file_path)
4245

43-
if r['GetLastError'] != 0
46+
case r['GetLastError']
47+
when ERROR::SUCCESS, ERROR::SHARING_VIOLATION, ERROR::ACCESS_DENIED, ERROR::LOCK_VIOLATION
48+
# Continue, we can bypass these errors as we are performing a raw
49+
# file read.
50+
when ERROR::FILE_NOT_FOUND, ERROR::PATH_NOT_FOUND
4451
fail_with(
4552
Exploit::Failure::BadConfig,
46-
'The file does not exist, use file format C:\\\\Windows\\\\System32\\\\drivers\\\\etc\\\\hosts'
53+
"The file, #{file_path}, does not exist, use file format C:\\\\Windows\\\\System32\\\\drivers\\\\etc\\\\hosts"
54+
)
55+
else
56+
fail_with(
57+
Exploit::Failure::Unknown,
58+
"Unknown error locating #{file_path}. Windows Error Code: #{r['GetLastError']} - #{r['ErrorMessage']}"
4759
)
4860
end
4961

@@ -64,8 +76,9 @@ def run
6476
end
6577

6678
@handle = r['return']
67-
print_status("Successfuly opened #{drive}")
79+
vprint_status("Successfuly opened #{drive}")
6880
begin
81+
@bytes_read = 0
6982
fs = Rex::Parser::NTFS.new(self)
7083
print_status("Trying to gather #{file_path}")
7184
path = file_path[3, file_path.length - 3]
@@ -80,7 +93,7 @@ def run
8093
end
8194

8295
def read(size)
83-
client.railgun.kernel32.ReadFile(@handle, size, size, 4, nil)["lpBuffer"]
96+
client.railgun.kernel32.ReadFile(@handle, size, size, 4, nil)['lpBuffer']
8497
end
8598

8699
def seek(offset)

0 commit comments

Comments
 (0)