Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/windows/manage/vss.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::Windows::FileSystem7include Msf::Post::Windows::Priv8include Msf::Post::Windows::ShadowCopy910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Windows Manage Volume Shadow Copies',15'Description' => %q{16This module will perform management actions for Volume Shadow Copies on the system. This is based on the VSSOwn17Script originally posted by Tim Tomes and Mark Baggett.1819Works on win2k3 and later.20},21'License' => MSF_LICENSE,22'Platform' => ['win'],23'SessionTypes' => ['meterpreter'],24'Author' => ['theLightCosine'],25'References' => [26[ 'URL', 'https://web.archive.org/web/20201111212952/https://securityweekly.com/2011/11/02/safely-dumping-hashes-from-liv/' ]27],28'Actions' => [29[ 'VSS_CREATE', { 'Description' => 'Create a new VSS copy' } ],30[ 'VSS_LIST_COPIES', { 'Description' => 'List VSS copies' } ],31[ 'VSS_MOUNT', { 'Description' => 'Mount a VSS copy' } ],32[ 'VSS_UNMOUNT', { 'Description' => 'Unmount a VSS copy' } ],33[ 'VSS_GET_INFO', { 'Description' => 'Get VSS information' } ],34[ 'VSS_SET_MAX_STORAGE_SIZE', { 'Description' => 'Set the VSS maximum storage size' } ]35],36'DefaultAction' => 'VSS_GET_INFO',37'Compat' => {38'Meterpreter' => {39'Commands' => %w[40stdapi_fs_delete_dir41]42}43},44'Notes' => {45'Stability' => [CRASH_SAFE],46'Reliability' => [],47'SideEffects' => [CONFIG_CHANGES, ARTIFACTS_ON_DISK]48}49)50)5152register_options(53[54OptInt.new('SIZE', [ false, 'Size in bytes to set for max storage.' ], conditions: %w[ACTION == VSS_SET_MAX_STORAGE_SIZE]),55OptString.new('VOLUME', [ false, 'Volume to make a copy of.', 'C:\\' ], conditions: %w[ACTION == VSS_CREATE]),56OptString.new('DEVICE', [ false, 'DeviceObject of the shadow copy to mount.' ], conditions: %w[ACTION == VSS_MOUNT]),57OptString.new('PATH', [ false, 'Path to use for mounting the shadow copy.', 'ShadowCopy' ], conditions: ['ACTION', 'in', %w[VSS_MOUNT VSS_UNMOUNT] ])58]59)60end6162def run63# all conditional options are required when active, make sure none of them are blank64options.each_pair do |name, option|65next if option.conditions.empty?66next unless Msf::OptCondition.show_option(self, option)6768fail_with(Failure::BadConfig, "The #{name} option is required by the #{action.name} action.") if datastore[name].blank?69end7071fail_with(Failure::NoAccess, 'This module requires administrative privileges to run') unless is_admin?72fail_with(Failure::NoAccess, 'This module requires UAC to be bypassed first') if is_uac_enabled?73fail_with(Failure::Unknown, 'Failed to start the necessary VSS services') unless start_vss7475send("action_#{action.name.downcase}")76end7778def action_vss_create79if (id = create_shadowcopy(datastore['VOLUME']))80print_good "Shadow Copy #{id} created!"81end82end8384def action_vss_get_info85return unless (storage_data = vss_get_storage)8687tbl = Rex::Text::Table.new(88'Header' => 'Shadow Copy Storage Data',89'Indent' => 2,90'Columns' => ['Field', 'Value']91)92storage_data.each_pair { |k, v| tbl << [k, v] }93print_good(tbl.to_s)94store_loot('host.shadowstorage', 'text/plain', session, tbl.to_s, 'shadowstorage.txt', 'Shadow Copy Storage Info')95end9697def action_vss_mount98print_status('Creating the symlink...')99device = datastore['DEVICE']100unless device =~ %r{^([/\\])\1\?\1GLOBALROOT\1Device\1([\w\- ]+)\1?$}101fail_with(Failure::BadConfig, 'The DEVICE parameter is incorrect, it should begin with \\\\?\\GLOBALROOT\\Device\\')102end103device << Regexp.last_match(1) unless device.end_with?(Regexp.last_match(1)) # the DEVICE parameter needs to end with / or the link will be created successfully but will not work104105if create_symlink(datastore['PATH'], device, directory: true)106print_good('Mounted successfully')107end108end109110def action_vss_unmount111print_status('Deleting the symlink...')112session.fs.dir.rmdir(datastore['PATH'])113end114115def action_vss_list_copies116shadow_copies = vss_list117return if shadow_copies.empty?118119list = ''120shadow_copies.each do |copy|121tbl = Rex::Text::Table.new(122'Header' => 'Shadow Copy Data',123'Indent' => 2,124'Columns' => ['Field', 'Value']125)126copy.each_pair { |k, v| tbl << [k, v] }127list << " #{tbl} \n\n"128print_good tbl.to_s129end130store_loot('host.shadowcopies', 'text/plain', session, list, 'shadowcopies.txt', 'Shadow Copy Info')131end132133def action_vss_set_max_storage_size134if vss_set_storage(datastore['SIZE'])135print_good('Size updated successfully')136else137print_error('There was a problem updating the storage size')138end139end140end141142143