@@ -11,10 +11,13 @@ class MetasploitModule < Msf::Post
11
11
include Msf ::Post ::Windows ::Registry
12
12
include Msf ::Post ::Common
13
13
14
+ OFFICE_REGISTRY_PATH = 'HKCU\\SOFTWARE\\Microsoft\\Office'
15
+ TRUSTED_LOCATIONS_PATH = 'Security\\Trusted Locations'
16
+
14
17
def initialize ( info = { } )
15
18
super ( update_info ( info ,
16
19
'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. ) ,
18
21
'License' => MSF_LICENSE ,
19
22
'Author' => [ 'vysec <vincent.yiu[at]mwrinfosecurity.com>' ] ,
20
23
'Platform' => [ 'win' ] ,
@@ -31,57 +34,49 @@ def print_good(msg='')
31
34
end
32
35
33
36
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?
51
64
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
82
77
end
83
78
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' )
85
80
print_good ( "Results stored in: #{ path } " )
86
81
end
87
82
end
0 commit comments