Skip to content

Commit 446db78

Browse files
author
jiuweigui
committed
Minor fix to gather_pf_info function
1 parent 2a0b503 commit 446db78

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

modules/post/windows/gather/enum_prefetch.rb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,23 @@ def gather_pf_info(name_offset, hash_offset, runcount_offset, filetime_offset, f
6666
# from the system.
6767

6868
prefetch_file = read_file(filename)
69-
if prefetch_file.empty? or prefetch_file.nil?
69+
if prefetch_file.blank?
7070
print_error("Couldn't read file: #{filename}")
7171
return nil
7272
else
7373
# First we extract the saved filename
74-
pf_filename = prefetch_file[name_offset..name_offset+60]
74+
pf_filename = prefetch_file[name_offset, 60]
7575
idx = pf_filename.index("\x00\x00")
7676
name = Rex::Text.to_ascii(pf_filename.slice(0..idx))
7777

7878
# Then we get the runcount
79-
run_count = prefetch_file[runcount_offset..runcount_offset+4].unpack('L*')[0].to_s
79+
run_count = prefetch_file[runcount_offset, 4].unpack('v')[0]
8080

8181
# Then the filepath hash
82-
path_hash = prefetch_file[hash_offset..hash_offset+4].unpack('h8')[0].reverse.upcase.to_s
82+
path_hash = prefetch_file[hash_offset, 4].unpack('h*')[0].upcase.reverse
8383

8484
# Last we get the latest execution time
85-
filetime_a = prefetch_file[filetime_offset..(filetime_offset+16)].unpack('q*')
85+
filetime_a = prefetch_file[filetime_offset, 16].unpack('q*')
8686
filetime = filetime_a[0] + filetime_a[1]
8787
last_exec = Time.at((filetime - 116444736000000000) / 10000000).utc.to_s
8888

@@ -93,32 +93,32 @@ def gather_pf_info(name_offset, hash_offset, runcount_offset, filetime_offset, f
9393
# First we'll use specific offsets for finding out the location
9494
# and length of the filepath so that we can find it.
9595
filepath = []
96-
fpath_offset = prefetch_file[0x64..0x68].unpack('h4')[0].reverse.to_i(16)
97-
fpath_length = prefetch_file[0x68..0x6C].unpack('h4')[0].reverse.to_i(16)
98-
filepath_data = prefetch_file[fpath_offset..(fpath_offset+fpath_length)]
96+
fpath_offset = prefetch_file[0x64, 2].unpack('v').first
97+
fpath_length = prefetch_file[0x68, 2].unpack('v').first
98+
filepath_data = prefetch_file[fpath_offset, fpath_length]
9999

100100
# This part will extract the filepath so that we can find and
101101
# compare its contents to the filename we found previously. This
102102
# allows us to find the filepath (if it can be found inside the
103103
# prefetch file) used to execute the program
104104
# referenced in the prefetch-file.
105-
106-
if not filepath_data.nil? or not filepath_data.emtpy?
107-
fpath_data_array = filepath_data.split("\x00\x00\x00")
105+
unless filepath_data.blank?
106+
fpath_data_array = filepath_data.split("\\\x00D\x00E\x00V\x00I\x00C\x00E")
108107
fpath_data_array.each do |path|
109-
fpath_entry_data = path.split("\\")
110-
fpath_entry_filename = fpath_entry_data.last
111-
if not fpath_entry_filename.nil?
112-
fpath_name = fpath_entry_filename.gsub(/\0/, '')
113-
if name == fpath_name[0..29]
114-
fpath_path = path.gsub(/\0/, '')
115-
filepath = fpath_path
108+
unless path.blank?
109+
fpath_name = path.split("\\").last.gsub(/\0/, '')
110+
if fpath_name == name
111+
filepath << path
116112
end
117113
end
118114
end
119115
end
120116
end
121-
return [last_exec, path_hash, run_count, name, filepath]
117+
if filepath.blank?
118+
filepath << "*** Filepath not found ***"
119+
end
120+
121+
return [last_exec, path_hash, run_count, name, filepath[0]]
122122
end
123123

124124
def run

0 commit comments

Comments
 (0)