Skip to content

Commit 1e053c1

Browse files
David MaloneyDavid Maloney
authored andcommitted
Merge branch 'master' into feature/rex-cleanup/first-gems
2 parents 69e2d05 + f85e797 commit 1e053c1

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

lib/msf/util/exe.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ def self.read_replace_script_template(filename, hash_sub)
7474
template % hash_sub
7575
end
7676

77+
78+
# Generates a ZIP file.
79+
#
80+
# @param files [Array<Hash>] Items to compress. Each item is a hash that supports these options:
81+
# * :data - The content of the file.
82+
# * :fname - The file path in the ZIP file
83+
# * :comment - A comment
84+
# @example Compressing two files, one in a folder called 'test'
85+
# Msf::Util::EXE.to_zip([{data: 'AAAA', fname: "file1.txt"}, {data: 'data', fname: 'test/file2.txt'}])
86+
# @return [String]
87+
def self.to_zip(files)
88+
zip = Rex::Zip::Archive.new
89+
90+
files.each do |f|
91+
data = f[:data]
92+
fname = f[:fname]
93+
comment = f[:comment] || ''
94+
zip.add_file(fname, data, comment)
95+
end
96+
97+
zip.pack
98+
end
99+
77100
# Executable generators
78101
#
79102
# @param arch [Array<String>] The architecture of the system (i.e :x86, :x64)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
require 'rex'
8+
require 'msf/core/post/common'
9+
10+
class MetasploitModule < Msf::Post
11+
include Msf::Post::Windows::Registry
12+
include Msf::Post::Common
13+
14+
OFFICE_REGISTRY_PATH = 'HKCU\\SOFTWARE\\Microsoft\\Office'
15+
TRUSTED_LOCATIONS_PATH = 'Security\\Trusted Locations'
16+
17+
def initialize(info = {})
18+
super(update_info(info,
19+
'Name' => 'Windows Gather Microsoft Office Trusted Locations',
20+
'Description' => %q( This module will enumerate the Microsoft Office trusted locations on the target host. ),
21+
'License' => MSF_LICENSE,
22+
'Author' => [ 'vysec <vincent.yiu[at]mwrinfosecurity.com>' ],
23+
'Platform' => [ 'win' ],
24+
'SessionTypes' => [ 'meterpreter' ]
25+
))
26+
end
27+
28+
def print_status(msg='')
29+
super("#{peer} - #{msg}")
30+
end
31+
32+
def print_good(msg='')
33+
super("#{peer} - #{msg}")
34+
end
35+
36+
def run
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?
64+
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
77+
end
78+
end
79+
path = store_loot('host.trusted_locations', 'text/plain', session, locations, 'trusted_locations.txt', 'Trusted Locations')
80+
print_good("Results stored in: #{path}")
81+
end
82+
end
83+
end

0 commit comments

Comments
 (0)