4
4
##
5
5
6
6
require 'rex/parser/fs/ntfs'
7
-
7
+ require 'action_view/helpers/number_helper'
8
8
class Metasploit3 < Msf ::Post
9
9
include Msf ::Post ::Windows ::Priv
10
+ include Msf ::Post ::Windows ::Error
11
+
12
+ ERROR = Msf ::Post ::Windows ::Error
10
13
11
14
def initialize ( info = { } )
12
15
super ( update_info ( info ,
@@ -40,10 +43,19 @@ def run
40
43
41
44
r = client . railgun . kernel32 . GetFileAttributesW ( file_path )
42
45
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
44
51
fail_with (
45
52
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' ] } "
47
59
)
48
60
end
49
61
@@ -64,8 +76,9 @@ def run
64
76
end
65
77
66
78
@handle = r [ 'return' ]
67
- print_status ( "Successfuly opened #{ drive } " )
79
+ vprint_status ( "Successfuly opened #{ drive } " )
68
80
begin
81
+ @bytes_read = 0
69
82
fs = Rex ::Parser ::NTFS . new ( self )
70
83
print_status ( "Trying to gather #{ file_path } " )
71
84
path = file_path [ 3 , file_path . length - 3 ]
@@ -80,7 +93,7 @@ def run
80
93
end
81
94
82
95
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' ]
84
97
end
85
98
86
99
def seek ( offset )
0 commit comments