Skip to content

Commit 5f3d3a3

Browse files
committed
still buggy
1 parent 4c56d8e commit 5f3d3a3

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

modules/post/windows/gather/enum_prefetch.rb

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -73,41 +73,44 @@ def gather_prefetch_info(name_offset, hash_offset, lastrun_offset, runcount_offs
7373
h = client.railgun.kernel32.CreateFileA(filename, "GENERIC_READ", "FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE", nil, "OPEN_EXISTING", "FILE_ATTRIBUTE_READONLY", nil)
7474

7575
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)
7877
else
7978
handle = h['return']
8079

8180
# Finds the filename from the prefetch file
8281
client.railgun.kernel32.SetFilePointer(handle, name_offset, 0, nil)
8382
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")))
8683

87-
# Finds the run count from the prefetch file
84+
# Finds the run count from the prefetch file
8885
client.railgun.kernel32.SetFilePointer(handle, runcount_offset, 0, nil)
8986
count = client.railgun.kernel32.ReadFile(handle, 4, 4, 4, nil)
90-
prun = count['lpBuffer'].unpack('L*')[0]
9187

92-
# Finds the hash.
88+
# Finds the file path hash from the prefetch file
9389
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)
9691

9792
# 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)
10094

10195
# 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?
104100

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)
108102
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
110112
end
113+
table << [lmod,creat,prun,phash,pname]
111114
client.railgun.kernel32.CloseHandle(handle)
112115
end
113116
end
@@ -188,7 +191,7 @@ def run
188191
# Goes through the files in Prefetch directory, creates file paths for the
189192
# gather_prefetch_info function that enumerates all the pf info
190193

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)
192195
if getfile_prefetch_filenames.empty? or getfile_prefetch_filenames.nil?
193196
print_error("Could not find/access any .pf files. Can't continue.")
194197
return nil

0 commit comments

Comments
 (0)