2011-05-12 20:03:55 +00:00
|
|
|
require 'rex/sync/ref'
|
2005-11-19 16:25:26 +00:00
|
|
|
|
|
|
|
module Msf
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# This module represents an abstract plugin that can be loaded into the
|
|
|
|
# context of a framework instance. Plugins are meant to provide an easy way
|
|
|
|
# to augment the feature set of the framework by being able to load and unload
|
|
|
|
# them during the course of a framework's lifetime. For instance, a plugin
|
|
|
|
# could be loaded to alter the default behavior of new sessions, such as by
|
|
|
|
# scripting meterpreter sessions that are created. The possiblities are
|
2011-11-20 01:10:08 +00:00
|
|
|
# endless!
|
2005-11-19 16:25:26 +00:00
|
|
|
#
|
|
|
|
# All plugins must exist under the Msf::Plugin namespace. Plugins are
|
|
|
|
# reference counted to allow them to be loaded more than once if they're a
|
|
|
|
# singleton.
|
2011-11-20 01:10:08 +00:00
|
|
|
#
|
2005-11-19 16:25:26 +00:00
|
|
|
###
|
|
|
|
class Plugin
|
|
|
|
|
|
|
|
include Framework::Offspring
|
|
|
|
include Rex::Ref
|
|
|
|
|
|
|
|
#
|
|
|
|
# Create an instance of the plugin using the supplied framework instance.
|
|
|
|
# We use create instead of new directly so that singleton plugins can just
|
|
|
|
# return their singleton instance.
|
|
|
|
#
|
2005-11-23 14:02:30 +00:00
|
|
|
def self.create(framework, opts = {})
|
|
|
|
new(framework, opts)
|
2005-11-19 16:25:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Initializes the plugin instance with the supplied framework instance.
|
2005-11-23 14:02:30 +00:00
|
|
|
# The opts parameter is a hash of custom arguments that may be useful for a
|
|
|
|
# plugin. Some of the pre-defined arguments are:
|
2005-11-19 16:25:26 +00:00
|
|
|
#
|
2005-11-23 14:02:30 +00:00
|
|
|
# LocalInput
|
|
|
|
#
|
|
|
|
# The local input handle that implements the Rex::Ui::Text::Input
|
|
|
|
# interface.
|
|
|
|
#
|
|
|
|
# LocalOutput
|
|
|
|
#
|
|
|
|
# The local output handle that implements the Rex::Ui::Output interface.
|
|
|
|
#
|
|
|
|
def initialize(framework, opts = {})
|
2005-11-19 16:25:26 +00:00
|
|
|
self.framework = framework
|
2005-11-23 14:02:30 +00:00
|
|
|
self.opts = opts
|
2005-11-19 16:25:26 +00:00
|
|
|
|
|
|
|
refinit
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Allows the plugin to clean up as it is being unloaded.
|
|
|
|
#
|
|
|
|
def cleanup
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Accessors
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the name of the plugin.
|
|
|
|
#
|
|
|
|
def name
|
|
|
|
"unnamed"
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# A short description of the plugin.
|
|
|
|
#
|
|
|
|
def desc
|
|
|
|
end
|
|
|
|
|
2005-11-23 14:02:30 +00:00
|
|
|
##
|
|
|
|
#
|
|
|
|
# Accessors
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the local output handle if one was passed into the constructor.
|
|
|
|
#
|
|
|
|
def output
|
|
|
|
opts['LocalOutput']
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the local input handle if one was passed into the constructor.
|
|
|
|
#
|
|
|
|
def input
|
|
|
|
opts['LocalInput']
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Output wrappers for the plugin that uses the 'LocalOutput' hash entry
|
|
|
|
# if one was passed into the constructor.
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
#
|
|
|
|
# Prints an error message.
|
|
|
|
#
|
2007-02-11 19:40:33 +00:00
|
|
|
def print_error(msg='')
|
2005-11-23 14:02:30 +00:00
|
|
|
output.print_error(msg) if (output)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Prints a 'good' message.
|
|
|
|
#
|
2007-02-11 19:40:33 +00:00
|
|
|
def print_good(msg='')
|
2005-11-23 14:02:30 +00:00
|
|
|
output.print_good(msg) if (output)
|
|
|
|
end
|
|
|
|
|
2010-02-02 21:03:07 +00:00
|
|
|
#
|
|
|
|
# Prints a 'debug' message.
|
|
|
|
#
|
|
|
|
def print_debug(msg='')
|
|
|
|
output.print_debug(msg) if (output)
|
|
|
|
end
|
|
|
|
|
2005-11-23 14:02:30 +00:00
|
|
|
#
|
|
|
|
# Prints a status line.
|
|
|
|
#
|
2007-02-11 19:40:33 +00:00
|
|
|
def print_status(msg='')
|
2005-11-23 14:02:30 +00:00
|
|
|
output.print_status(msg) if (output)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Prints an undecorated line of information.
|
|
|
|
#
|
2007-02-11 19:40:33 +00:00
|
|
|
def print_line(msg='')
|
2005-11-23 14:02:30 +00:00
|
|
|
output.print_line(msg) if (output)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Prints a message with no decoration.
|
|
|
|
#
|
2007-02-11 19:40:33 +00:00
|
|
|
def print(msg='')
|
2005-11-23 14:02:30 +00:00
|
|
|
output.print(msg) if (output)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Flushes any buffered output.
|
|
|
|
#
|
|
|
|
def flush
|
|
|
|
output.flush(msg) if (output)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
attr_accessor :opts # :nodoc:
|
|
|
|
|
2005-11-23 14:34:11 +00:00
|
|
|
##
|
|
|
|
#
|
|
|
|
# Console command dispatcher helpers.
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
#
|
|
|
|
# Adds the console dispatcher.
|
|
|
|
#
|
|
|
|
def add_console_dispatcher(disp)
|
|
|
|
if (opts['ConsoleDriver'])
|
|
|
|
opts['ConsoleDriver'].append_dispatcher(disp)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Removes the console dispatcher.
|
|
|
|
#
|
|
|
|
def remove_console_dispatcher(name)
|
|
|
|
if (opts['ConsoleDriver'])
|
|
|
|
opts['ConsoleDriver'].remove_dispatcher(name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-19 16:25:26 +00:00
|
|
|
end
|
|
|
|
|
2010-02-02 21:03:07 +00:00
|
|
|
end
|