Adding documentation to the methods in the post exploitation library. Will eventually generate an rdoc file and a post exploitation How To.

unstable
Stephen Haywood 2012-09-04 22:21:47 -04:00
parent b6d64b770a
commit 8f142c74e5
5 changed files with 77 additions and 1 deletions

View File

@ -51,6 +51,9 @@ module Msf::Post::File
end end
end end
#
# Expand any environment variables to return the full path specified by +path+.
#
def expand_path(path) def expand_path(path)
if session.type == "meterpreter" if session.type == "meterpreter"
return session.fs.file.expand_path(path) return session.fs.file.expand_path(path)
@ -429,6 +432,9 @@ protected
true true
end end
#
# Calculate the maximum line length for a unix shell.
#
def _unix_max_line_length def _unix_max_line_length
# Based on autoconf's arg_max calculator, see # Based on autoconf's arg_max calculator, see
# http://www.in-ulm.de/~mascheck/various/argmax/autoconf_check.html # http://www.in-ulm.de/~mascheck/various/argmax/autoconf_check.html

View File

@ -12,6 +12,11 @@ module CliParse
#Msf::Post::Windows::CliParse::ParseError #Msf::Post::Windows::CliParse::ParseError
class ParseError < ArgumentError class ParseError < ArgumentError
#
# Create a new ParseError object. Expects a method name, an error
# message, an error code, and the command that caused the error.
#
def initialize(method, einfo='', ecode=nil, clicmd=nil) def initialize(method, einfo='', ecode=nil, clicmd=nil)
@method = method @method = method
@info = einfo @info = einfo
@ -20,6 +25,9 @@ module CliParse
@clicmd = clicmd || "Unknown shell command" @clicmd = clicmd || "Unknown shell command"
end end
#
# Convert a ParseError to a string.
#
def to_s def to_s
"#{@method}: Operation failed: #{@info}:#{@code} while running #{@clicmd}" "#{@method}: Operation failed: #{@info}:#{@code} while running #{@clicmd}"
end end

View File

@ -78,6 +78,9 @@ module Priv
return uac return uac
end end
#
# Return true if the session has extended capabilities (ie meterpreter)
#
def session_has_ext def session_has_ext
begin begin
return !!(session.railgun and session.sys.config) return !!(session.railgun and session.sys.config)

View File

@ -12,10 +12,17 @@ module ShadowCopy
include Msf::Post::Windows::WindowsServices include Msf::Post::Windows::WindowsServices
#
# Get the device name for the shadow copy, which is used when accessing
# files on the volume.
#
def get_vss_device(id) def get_vss_device(id)
result = get_sc_param(id,'DeviceObject') result = get_sc_param(id,'DeviceObject')
end end
#
# Returns a list of volume shadow copies.
#
def vss_list def vss_list
ids = vss_get_ids ids = vss_get_ids
shadow_copies = [] shadow_copies = []
@ -26,12 +33,18 @@ module ShadowCopy
return shadow_copies return shadow_copies
end end
#
# Use WMIC to get a list of volume shadow copy IDs.
#
def vss_get_ids def vss_get_ids
result = wmicexec('shadowcopy get id') result = wmicexec('shadowcopy get id')
ids = result.scan(/\{\w{8}-\w{4}-\w{4}-\w{4}-\w{12}\}/) ids = result.scan(/\{\w{8}-\w{4}-\w{4}-\w{4}-\w{12}\}/)
return ids return ids
end end
#
# Get volume shadow storage parameters.
#
def vss_get_storage def vss_get_storage
storage={} storage={}
storage['AllocatedSpace'] = vss_get_storage_param('AllocatedSpace') storage['AllocatedSpace'] = vss_get_storage_param('AllocatedSpace')
@ -40,6 +53,9 @@ module ShadowCopy
return storage return storage
end end
#
# Get detailed information about the volume shadow copy specified by +id+
#
def get_sc_details(id) def get_sc_details(id)
shadowcopy={} shadowcopy={}
shadowcopy['ID'] = id shadowcopy['ID'] = id
@ -67,18 +83,29 @@ module ShadowCopy
return shadowcopy return shadowcopy
end end
#
# Return the value of the +param_name+ for the volume shadow copy
# specified by +id+
#
def get_sc_param(id,param_name) def get_sc_param(id,param_name)
result = wmicexec("shadowcopy where(id=#{id}) get #{param_name}") result = wmicexec("shadowcopy where(id=#{id}) get #{param_name}")
result.gsub!(param_name,'') result.gsub!(param_name,'')
result.gsub!(/\s/,'') result.gsub!(/\s/,'')
end end
#
# Return the value of the shadowstorage parameter specified by
# +param_name+
#
def vss_get_storage_param(param_name) def vss_get_storage_param(param_name)
result = wmicexec("shadowstorage get #{param_name}") result = wmicexec("shadowstorage get #{param_name}")
result.gsub!(param_name,'') result.gsub!(param_name,'')
result.gsub!(/\s/,'') result.gsub!(/\s/,'')
end end
#
# Set the shadowstorage MaxSpace parameter to +bytes+ size
#
def vss_set_storage(bytes) def vss_set_storage(bytes)
result = wmicexec("shadowstorage set MaxSpace=\"#{bytes}\"") result = wmicexec("shadowstorage set MaxSpace=\"#{bytes}\"")
if result.include?("success") if result.include?("success")
@ -88,6 +115,9 @@ module ShadowCopy
end end
end end
#
# Create a new shadow copy of the volume specified by +volume+
#
def create_shadowcopy(volume) def create_shadowcopy(volume)
result = wmicexec("shadowcopy call create \"ClientAccessible\", \"#{volume}\"") result = wmicexec("shadowcopy call create \"ClientAccessible\", \"#{volume}\"")
retval = result.match(/ReturnValue = (\d)/) retval = result.match(/ReturnValue = (\d)/)
@ -126,6 +156,9 @@ module ShadowCopy
return nil return nil
end end
#
# Start the Volume Shadow Service
#
def start_vss def start_vss
vss_state = wmicexec('Service where(name="VSS") get state') vss_state = wmicexec('Service where(name="VSS") get state')
if vss_state=~ /Running/ if vss_state=~ /Running/
@ -158,6 +191,9 @@ module ShadowCopy
return true return true
end end
#
# Execute a WMIC command
#
def wmicexec(wmiccmd) def wmicexec(wmiccmd)
tmpout = '' tmpout = ''
session.response_timeout=120 session.response_timeout=120

View File

@ -10,6 +10,11 @@ module UserProfiles
include Msf::Post::Windows::Registry include Msf::Post::Windows::Registry
include Msf::Post::Windows::Accounts include Msf::Post::Windows::Accounts
#
# Load the registry hive for each user on the machine and parse out the
# user profile information. Next, unload the hives we loaded and return
# the user profiles.
#
def grab_user_profiles def grab_user_profiles
hives = load_missing_hives() hives = load_missing_hives()
profiles = parse_profiles(hives) profiles = parse_profiles(hives)
@ -17,6 +22,9 @@ module UserProfiles
return profiles return profiles
end end
#
# Unload any hives we loaded.
#
def unload_our_hives(hives) def unload_our_hives(hives)
hives.each do |hive| hives.each do |hive|
next unless hive['OURS']==true next unless hive['OURS']==true
@ -24,6 +32,9 @@ module UserProfiles
end end
end end
#
# Return a list of user profiles parsed each of the hives in +hives+.
#
def parse_profiles(hives) def parse_profiles(hives)
profiles=[] profiles=[]
hives.each do |hive| hives.each do |hive|
@ -33,6 +44,9 @@ module UserProfiles
return profiles return profiles
end end
#
# Get the user profile information from the hive specified by +hive+
#
def parse_profile(hive) def parse_profile(hive)
profile={} profile={}
sidinf = resolve_sid(hive['SID'].to_s) sidinf = resolve_sid(hive['SID'].to_s)
@ -54,7 +68,9 @@ module UserProfiles
return profile return profile
end end
#
# Load any user hives that are not already loaded.
#
def load_missing_hives def load_missing_hives
hives=[] hives=[]
read_profile_list().each do |hive| read_profile_list().each do |hive|
@ -72,6 +88,10 @@ module UserProfiles
return hives return hives
end end
#
# Read HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList to
# get a list of user profiles on the machine.
#
def read_profile_list def read_profile_list
hives=[] hives=[]
registry_enumkeys('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList').each do |profkey| registry_enumkeys('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList').each do |profkey|
@ -88,6 +108,9 @@ module UserProfiles
return hives return hives
end end
#
# Return a list of loaded registry hives.
#
def loaded_hives def loaded_hives
hives=[] hives=[]
registry_enumkeys('HKU').each do |k| registry_enumkeys('HKU').each do |k|