Skip to content

Commit cdabb71

Browse files
committed
Make code cleanup
1 parent 5f5ca1c commit cdabb71

File tree

1 file changed

+49
-51
lines changed

1 file changed

+49
-51
lines changed

modules/post/windows/gather/enum_muicache.rb

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,59 +17,58 @@ def initialize(info={})
1717
'Name' =>'Windows Gather Enum User MUICache',
1818
'Description' =>
1919
%q{
20-
This module gathers information about the files and file paths that
21-
logged on users have executed on the system and it will also check
22-
if the file still exists on the system in the file path it has been
23-
previously executed. This information is gathered by using information
24-
stored under the MUICache registry key. If the user is logged in when the
25-
module is executed it will collect the MUICache entries by accessing
26-
the registry directly. If the user is not logged in the module will
27-
download users registry hive NTUSER.DAT/UsrClass.dat from the system
28-
and the MUICache contents are parsed from the downloaded hive.
29-
},
30-
'License' => MSF_LICENSE,
31-
'Author' => ['TJ Glad <tjglad[at]cmail.nu>'],
32-
'Platform' => ['win'],
33-
'SessionType' => ['meterpreter']
34-
))
20+
This module gathers information about the files and file paths that logged on users have
21+
executed on the system. It also will check if the file exists on the system still. This
22+
information is gathered by using information stored under the MUICache registry key. If
23+
the user is logged in when the module is executed it will collect the MUICache entries
24+
by accessing the registry directly. If the user is not logged in the module will download
25+
users registry hive NTUSER.DAT/UsrClass.dat from the system and the MUICache contents are
26+
parsed from the downloaded hive.
27+
},
28+
'License' => MSF_LICENSE,
29+
'Author' => ['TJ Glad <tjglad[at]cmail.nu>'],
30+
'Platform' => ['win'],
31+
'SessionType' => ['meterpreter']
32+
))
3533
end
3634

37-
def find_usernames()
35+
def find_user_names()
3836
# This function scrapes usernames, sids and homepaths from the
3937
# registry so that we'll know what user accounts are on the system
4038
# and where we can find those users registry hives.
41-
usernames = Array.new
42-
user_homedir_paths = Array.new
43-
user_sids = Array.new
39+
user_names = []
40+
user_homedir_paths = []
41+
user_sids = []
4442

4543
username_reg_path = "HKLM\\Software\\Microsoft\\Windows\ NT\\CurrentVersion\\ProfileList"
4644
profile_subkeys = registry_enumkeys(username_reg_path)
4745
if profile_subkeys.blank?
4846
print_error("Unable to access ProfileList registry key. Can't continue.")
4947
return nil
50-
else
51-
profile_subkeys.each do |user_sid|
52-
if user_sid.length > 10
53-
user_home_path = registry_getvaldata("#{username_reg_path}\\#{user_sid}", "ProfileImagePath")
54-
unless user_home_path.blank?
55-
full_path = user_home_path.strip
56-
usernames << full_path.split("\\").last
57-
user_homedir_paths << full_path
58-
user_sids << user_sid
59-
else
60-
print_error("Unable to read ProfileImagePath from the registry. Can't continue.")
61-
return nil
62-
end
63-
end
48+
end
49+
50+
profile_subkeys.each do |user_sid|
51+
unless user_sid.length > 10
52+
next
6453
end
54+
user_home_path = registry_getvaldata("#{username_reg_path}\\#{user_sid}", "ProfileImagePath")
55+
if user_home_path.blank?
56+
print_error("Unable to read ProfileImagePath from the registry. Can't continue.")
57+
return nil
58+
end
59+
full_path = user_home_path.strip
60+
user_names << full_path.split("\\").last
61+
user_homedir_paths << full_path
62+
user_sids << user_sid
6563
end
66-
return usernames, user_homedir_paths, user_sids
64+
65+
return user_names, user_homedir_paths, user_sids
6766
end
6867

6968
def enum_muicache_paths(sys_sids, mui_path)
7069
# This function builds full registry muicache paths so that we can
7170
# later enumerate the muicahe registry key contents.
72-
user_mui_paths = Array.new
71+
user_mui_paths = []
7372
hive = "HKU\\"
7473
sys_sids.each do |sid|
7574
full_path = hive + sid + mui_path
@@ -114,13 +113,11 @@ def check_file_exists(key, user, table)
114113
# if it detects the executable but it should be otherwise fairly
115114
# reliable.
116115
program_path = expand_path(key)
117-
program_exists = file_exist?(key)
118-
if program_exists == true
119-
exists = "File found"
116+
if file_exist?(key)
117+
table << [user, program_path, "File found"]
120118
else
121-
exists = "File not found"
119+
table << [user, program_path, "File not found"]
122120
end
123-
table << [user, program_path, exists]
124121
end
125122

126123
def process_hive(sys_path, user, local_hive_copy, table, muicache, hive_file)
@@ -211,10 +208,10 @@ def hive_parser(local_hive_copy, muicache, user, table)
211208
return table
212209
end
213210

214-
def print_usernames(sys_users)
211+
def print_user_names(sys_users)
215212
# This prints usernames pulled from the paths found from the
216213
# registry.
217-
user_list = Array.new
214+
user_list = []
218215
sys_users.each do |user|
219216
user_list << user
220217
end
@@ -232,14 +229,14 @@ def run
232229
# - http://www.irongeek.com/i.php?page=security/windows-forensics-registry-and-file-system-spots
233230

234231
print_status("Starting to enumerate MuiCache registry keys..")
235-
sysnfo = sysinfo['OS']
232+
sys_info = sysinfo['OS']
236233

237-
if sysnfo =~/(Windows XP)/ and is_admin?
238-
print_good("Remote system supported: #{sysnfo}")
234+
if sys_info =~/Windows XP/ && is_admin?
235+
print_good("Remote system supported: #{sys_info}")
239236
muicache = "\\Software\\Microsoft\\Windows\\ShellNoRoam\\MUICache"
240237
hive_file = "\\NTUSER.DAT"
241-
elsif sysnfo =~/(Windows 7)/ and is_admin?
242-
print_good("Remote system supported: #{sysnfo}")
238+
elsif sys_info =~/Windows 7/ && is_admin?
239+
print_good("Remote system supported: #{sys_info}")
243240
muicache = "_Classes\\Local\ Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache"
244241
hive_file = "\\AppData\\Local\\Microsoft\\Windows\\UsrClass.dat"
245242
else
@@ -258,12 +255,13 @@ def run
258255
])
259256

260257
print_status("Phase 1: Searching usernames..")
261-
sys_users, sys_paths, sys_sids = find_usernames()
262-
unless sys_users.blank?
263-
print_usernames(sys_users)
264-
else
258+
sys_users, sys_paths, sys_sids = find_user_names()
259+
260+
if sys_users.blank?
265261
print_error("Was not able to find any user accounts. Unable to continue.")
266262
return nil
263+
else
264+
print_user_names(sys_users)
267265
end
268266

269267
print_status("Phase 2: Searching registry hives..")

0 commit comments

Comments
 (0)