@@ -73,41 +73,44 @@ def gather_prefetch_info(name_offset, hash_offset, lastrun_offset, runcount_offs
73
73
h = client . railgun . kernel32 . CreateFileA ( filename , "GENERIC_READ" , "FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE" , nil , "OPEN_EXISTING" , "FILE_ATTRIBUTE_READONLY" , nil )
74
74
75
75
if h [ 'GetLastError' ] != 0
76
- print_error ( "Error opening a file handle." )
77
- return nil
76
+ print_error ( "Error opening a file handle on %s." % filename )
78
77
else
79
78
handle = h [ 'return' ]
80
79
81
80
# Finds the filename from the prefetch file
82
81
client . railgun . kernel32 . SetFilePointer ( handle , name_offset , 0 , nil )
83
82
name = client . railgun . kernel32 . ReadFile ( handle , 60 , 60 , 4 , nil )
84
- x = name [ 'lpBuffer' ]
85
- pname = Rex ::Text . to_ascii ( x . slice ( 0 ..x . index ( "\x00 \x00 " ) ) )
86
83
87
- # Finds the run count from the prefetch file
84
+ # Finds the run count from the prefetch file
88
85
client . railgun . kernel32 . SetFilePointer ( handle , runcount_offset , 0 , nil )
89
86
count = client . railgun . kernel32 . ReadFile ( handle , 4 , 4 , 4 , nil )
90
- prun = count [ 'lpBuffer' ] . unpack ( 'L*' ) [ 0 ]
91
87
92
- # Finds the hash.
88
+ # Finds the file path hash from the prefetch file
93
89
client . railgun . kernel32 . SetFilePointer ( handle , hash_offset , 0 , nil )
94
- hh = client . railgun . kernel32 . ReadFile ( handle , 4 , 4 , 4 , nil )
95
- phash = hh [ 'lpBuffer' ] . unpack ( 'h*' ) [ 0 ] . reverse
90
+ hash = client . railgun . kernel32 . ReadFile ( handle , 4 , 4 , 4 , nil )
96
91
97
92
# Finds the LastModified timestamp (MACE)
98
- lm = client . priv . fs . get_file_mace ( filename )
99
- lmod = lm [ 'Modified' ] . utc
93
+ lm = client . priv . fs . get_file_mace ( filename )
100
94
101
95
# Finds the Creation timestamp (MACE)
102
- cr = client . priv . fs . get_file_mace ( filename )
103
- creat = cr [ 'Created' ] . utc
96
+ ct = client . priv . fs . get_file_mace ( filename )
97
+
98
+ # Next we check everything was read successfully and prepare the results
99
+ if name . nil? or name . empty? or count . nil? or hash . nil? or lm . nil? or ct . nil?
104
100
105
- # Saves the results to the table and closes the file handle
106
- if name . nil? or count . nil? or hh . nil? or lm . nil? or cr . nil?
107
- print_error ( "Could not access file: %s." % filename )
101
+ print_error ( "Read failed on file: %s" % filename )
108
102
else
109
- table << [ lmod , creat , prun , phash , pname ]
103
+ # Preparing the values
104
+ x = name [ 'lpBuffer' ]
105
+ pname = Rex ::Text . to_ascii ( x . slice ( 0 ..x . index ( "\x00 \x00 " ) ) )
106
+ #x = Rex::Text.to_ascii(name['lpBuffer'])
107
+ #pname = x.slice(0..x.index(".EXE"))
108
+ prun = count [ 'lpBuffer' ] . unpack ( 'L*' ) [ 0 ]
109
+ phash = hash [ 'lpBuffer' ] . unpack ( 'h*' ) [ 0 ] . reverse
110
+ lmod = lm [ 'Modified' ] . utc
111
+ creat = ct [ 'Created' ] . utc
110
112
end
113
+ table << [ lmod , creat , prun , phash , pname ]
111
114
client . railgun . kernel32 . CloseHandle ( handle )
112
115
end
113
116
end
@@ -188,7 +191,7 @@ def run
188
191
# Goes through the files in Prefetch directory, creates file paths for the
189
192
# gather_prefetch_info function that enumerates all the pf info
190
193
191
- getfile_prefetch_filenames = client . fs . file . search ( full_path , file_type , recurse = false , timeout = - 1 )
194
+ getfile_prefetch_filenames = client . fs . file . search ( full_path , file_type , recurse = false , timeout = 10 )
192
195
if getfile_prefetch_filenames . empty? or getfile_prefetch_filenames . nil?
193
196
print_error ( "Could not find/access any .pf files. Can't continue." )
194
197
return nil
0 commit comments