Skip to content

Commit 674470c

Browse files
authored
Merge pull request #1 from Meatballs1/trusted_locations
Trusted locations cleanup
2 parents 8a68e86 + 0451d4f commit 674470c

File tree

1 file changed

+44
-49
lines changed

1 file changed

+44
-49
lines changed

modules/post/windows/gather/enum_trusted_locations.rb

Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ class MetasploitModule < Msf::Post
1111
include Msf::Post::Windows::Registry
1212
include Msf::Post::Common
1313

14+
OFFICE_REGISTRY_PATH = 'HKCU\\SOFTWARE\\Microsoft\\Office'
15+
TRUSTED_LOCATIONS_PATH = 'Security\\Trusted Locations'
16+
1417
def initialize(info = {})
1518
super(update_info(info,
1619
'Name' => 'Windows Gather Microsoft Office Trusted Locations',
17-
'Description' => %q( This module will enumerate the Microsoft Office trusted locations on the target host.),
20+
'Description' => %q( This module will enumerate the Microsoft Office trusted locations on the target host. ),
1821
'License' => MSF_LICENSE,
1922
'Author' => [ 'vysec <vincent.yiu[at]mwrinfosecurity.com>' ],
2023
'Platform' => [ 'win' ],
@@ -31,57 +34,49 @@ def print_good(msg='')
3134
end
3235

3336
def run
34-
reg_view = sysinfo['Architecture'] =~ /x64/ ? REGISTRY_VIEW_64_BIT : REGISTRY_VIEW_32_BIT
35-
reg_keys = registry_enumkeys('HKCU\\SOFTWARE\\Microsoft\\Office', reg_view)
36-
if reg_keys.nil?
37-
print_status('Failed to enumerate Office.')
38-
else
39-
print_status('')
40-
print_status('Found Office.')
41-
#find version to use
42-
reg_keys.each do |path|
43-
if not /[0-9][0-9].0/.match(path).nil?
44-
val1 = path
45-
print_status("Version found: #{val1}")
46-
reg_keys2 = registry_enumkeys("HKCU\\SOFTWARE\\Microsoft\\Office\\#{val1}", reg_view)
47-
if reg_keys2.nil?
48-
print_status('Failed to enumerate applications.')
49-
else
50-
print_status('Found applications.')
37+
locations = ""
38+
[REGISTRY_VIEW_64_BIT, REGISTRY_VIEW_32_BIT].each do |registry_arch|
39+
arch = registry_arch == REGISTRY_VIEW_64_BIT ? 'x64' : 'x86'
40+
reg_keys = registry_enumkeys(OFFICE_REGISTRY_PATH, registry_arch)
41+
if reg_keys.nil?
42+
print_status("Failed to enumerate Office in #{arch} registry hive.")
43+
return
44+
end
45+
46+
reg_keys.each do |version|
47+
next if /[0-9][0-9].0/.match(version).nil?
48+
49+
print_status("Version found: #{version}")
50+
version_path = "#{OFFICE_REGISTRY_PATH}\\#{version}"
51+
applications = registry_enumkeys(version_path, registry_arch)
52+
53+
if applications.nil?
54+
print_status('Failed to enumerate applications.')
55+
next
56+
end
57+
58+
vprint_status('Found applications.')
59+
#find version to use
60+
applications.each do |application|
61+
trusted_locations_path = "#{version_path}\\#{application}\\#{TRUSTED_LOCATIONS_PATH}"
62+
trusted_locations = registry_enumkeys(trusted_locations_path, registry_arch)
63+
next if trusted_locations.nil?
5164

52-
print_status('')
53-
#find version to use
54-
reg_keys2.each do |path2|
55-
val2 = path2
56-
reg_keys3 = registry_enumkeys("HKCU\\SOFTWARE\\Microsoft\\Office\\#{val1}\\#{val2}\\Security\\Trusted Locations", reg_view)
57-
if not reg_keys3.nil?
58-
print_status('')
59-
print_good("Found trusted locations in #{val2}")
60-
#find version to use
61-
reg_keys3.each do |path3|
62-
val3 = path3
63-
#print_status(path3)
64-
print_status('')
65-
reg_vals = registry_getvaldata("HKCU\\SOFTWARE\\Microsoft\\Office\\#{val1}\\#{val2}\\Security\\Trusted Locations\\#{val3}", "Description", reg_view)
66-
if not reg_vals.nil?
67-
print_status("Description: #{reg_vals}")
68-
end
69-
reg_vals2 = registry_getvaldata("HKCU\\SOFTWARE\\Microsoft\\Office\\#{val1}\\#{val2}\\Security\\Trusted Locations\\#{val3}", "AllowSubFolders", reg_view)
70-
reg_vals = registry_getvaldata("HKCU\\SOFTWARE\\Microsoft\\Office\\#{val1}\\#{val2}\\Security\\Trusted Locations\\#{val3}", "Path", reg_view)
71-
if not reg_vals.nil?
72-
if not reg_vals2.nil?
73-
print_status("Path: #{reg_vals}, AllowSub: True")
74-
else
75-
print_status("Path: #{reg_vals}, AllowSub: False")
76-
end
77-
end
78-
end
79-
end
80-
end
81-
end
65+
print_good("Found trusted locations in #{application}")
66+
#find version to use
67+
trusted_locations.each do |location|
68+
location_path = "#{trusted_locations_path}\\#{location}"
69+
description = registry_getvaldata(location_path, 'Description', registry_arch)
70+
allow_subfolders = registry_getvaldata(location_path, 'AllowSubFolders', registry_arch)
71+
path = registry_getvaldata(location_path, 'Path', registry_arch)
72+
vprint_status("Description: #{description}")
73+
result = "Application: #{application}, Path: #{path}, AllSubFolders: #{!!allow_subfolders}"
74+
locations << "#{result}\n"
75+
print_status(result)
76+
end
8277
end
8378
end
84-
path = store_loot('host.trusted_locations', 'text/plain', session, reg_keys.join("\r\n"), 'trusted_locations.txt', 'Trusted Locations')
79+
path = store_loot('host.trusted_locations', 'text/plain', session, locations, 'trusted_locations.txt', 'Trusted Locations')
8580
print_good("Results stored in: #{path}")
8681
end
8782
end

0 commit comments

Comments
 (0)