Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enum_trusted_locations.rb #6966

Merged
merged 7 commits into from
Jun 21, 2016
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
85 changes: 85 additions & 0 deletions modules/post/windows/gather/enum_trusted_locations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

require 'msf/core'
require 'rex'
require 'msf/core/post/common'

class MetasploitModule < Msf::Post
include Msf::Post::Windows::Registry
include Msf::Post::Common

def initialize(info = {})
super(update_info(info,
'Name' => 'Windows Gather Microsoft Office Trusted Locations',
'Description' => %q( This module will enumerate the Microsoft Office trusted locations on the target host.),
'License' => MSF_LICENSE,
'Author' => [ 'vysec <vincent.yiu[at]mwrinfosecurity.com>' ],
'Platform' => [ 'win' ],
'SessionTypes' => [ 'meterpreter' ]
))
end

def print_status(msg='')
super("#{peer} - #{msg}")
end

def print_good(msg='')
super("#{peer} - #{msg}")
end

def run
reg_view = sysinfo['Architecture'] =~ /x64/ ? REGISTRY_VIEW_64_BIT : REGISTRY_VIEW_32_BIT
reg_keys = registry_enumkeys('HKCU\\SOFTWARE\\Microsoft\\Office', reg_view)
if reg_keys.nil?
print_status('Failed to enumerate Office.')
else
print_status('')
print_status('Found Office:')
#find version to use
reg_keys.each do |path|
if not /[0-9][0-9].0/.match(path).nil?
val1 = path
print_status("Version found: #{val1}")
reg_keys2 = registry_enumkeys("HKCU\\SOFTWARE\\Microsoft\\Office\\#{val1}", reg_view)
if reg_keys2.nil?
print_status('Failed to enumerate applications.')
else
print_status('Found applications.')
#find version to use
reg_keys2.each do |path2|
val2 = path2
reg_keys3 = registry_enumkeys("HKCU\\SOFTWARE\\Microsoft\\Office\\#{val1}\\#{val2}\\Security\\Trusted Locations", reg_view)
if not reg_keys3.nil?
print_status('Found trusted locations.')
#find version to use
reg_keys3.each do |path3|
val3 = path3
#print_status(path3)
print_status('')
reg_vals = registry_getvaldata("HKCU\\SOFTWARE\\Microsoft\\Office\\#{val1}\\#{val2}\\Security\\Trusted Locations\\#{val3}", "Description", reg_view)
if not reg_vals.nil?
print_status("Description: #{reg_vals}")
end
reg_vals2 = registry_getvaldata("HKCU\\SOFTWARE\\Microsoft\\Office\\#{val1}\\#{val2}\\Security\\Trusted Locations\\#{val3}", "AllowSubFolders", reg_view)
reg_vals = registry_getvaldata("HKCU\\SOFTWARE\\Microsoft\\Office\\#{val1}\\#{val2}\\Security\\Trusted Locations\\#{val3}", "Path", reg_view)
if not reg_vals.nil?
if not reg_vals2.nil?
print_status("Path: #{reg_vals}, AllowSub: True")
else
print_status("Path: #{reg_vals}, AllowSub: False")
end
end
end
end
end
end
end
end
path = store_loot('host.trusted_locations', 'text/plain', session, reg_keys.join("\r\n"), 'trusted_locations.txt', 'Trusted Locations')
print_good("Results stored in: #{path}")
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the end, beautiful friend / This is the end, my only friend, the end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or hopefully not as I want to write more :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can refactor the level of nesting here. :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my Ruby sucks but any advice hugely appreciated.