2005-04-10 17:08:27 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
|
|
|
module Rex
|
|
|
|
module Post
|
|
|
|
module Meterpreter
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
2005-04-15 06:23:59 +00:00
|
|
|
# Mixin for classes that wish to have object aliases but do not
|
|
|
|
# really need to inherit from the ObjectAliases class.
|
2005-04-10 17:08:27 +00:00
|
|
|
#
|
|
|
|
###
|
2005-04-15 06:23:59 +00:00
|
|
|
module ObjectAliasesContainer
|
2005-04-10 17:08:27 +00:00
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# Initialize the instance's aliases.
|
|
|
|
#
|
2005-04-15 06:23:59 +00:00
|
|
|
def initialize_aliases(aliases = {})
|
|
|
|
self.aliases = aliases
|
2005-04-10 17:08:27 +00:00
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# Pass-thru aliases.
|
|
|
|
#
|
2005-04-10 17:08:27 +00:00
|
|
|
def method_missing(symbol, *args)
|
2005-12-13 05:59:59 +00:00
|
|
|
self.aliases[symbol.to_s]
|
2005-04-10 17:08:27 +00:00
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
2005-04-15 06:23:59 +00:00
|
|
|
# Recursively dumps all of the aliases registered with a class that
|
2005-11-15 05:22:13 +00:00
|
|
|
# is kind_of? ObjectAliases.
|
|
|
|
#
|
2005-04-15 06:23:59 +00:00
|
|
|
def dump_alias_tree(parent_path, current = nil)
|
|
|
|
items = []
|
|
|
|
|
|
|
|
if (current == nil)
|
|
|
|
current = self
|
|
|
|
end
|
|
|
|
|
|
|
|
# If the current object may have object aliases...
|
|
|
|
if (current.kind_of?(Rex::Post::Meterpreter::ObjectAliases))
|
|
|
|
current.aliases.each_key { |x|
|
|
|
|
current_path = parent_path + '.' + x
|
|
|
|
|
|
|
|
items << current_path
|
|
|
|
|
|
|
|
items.concat(dump_alias_tree(current_path,
|
|
|
|
current.aliases[x]))
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
return items
|
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# The hash of aliases.
|
|
|
|
#
|
2005-04-10 17:08:27 +00:00
|
|
|
attr_accessor :aliases
|
|
|
|
end
|
|
|
|
|
2005-04-15 06:23:59 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# Generic object aliases from a class instance referenced symbol to an
|
|
|
|
# associated object of an arbitrary type
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class ObjectAliases
|
|
|
|
include Rex::Post::Meterpreter::ObjectAliasesContainer
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Constructor
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
# An instance
|
|
|
|
def initialize(aliases = {})
|
|
|
|
initialize_aliases(aliases)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2005-04-10 17:08:27 +00:00
|
|
|
end; end; end
|