From ddb75822ad45402f67cb590db29ab99c28f9e3e4 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Sun, 10 Jul 2005 00:49:12 +0000 Subject: [PATCH] dump dump dump git-svn-id: file:///home/svn/incoming/trunk@2700 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/base/serializer/readable_text.rb | 77 ++++++++++++++----- lib/msf/core/exploit.rb | 4 +- lib/msf/core/module_manager.rb | 10 ++- lib/msf/core/nop.rb | 5 ++ lib/msf/core/option_container.rb | 30 ++++++++ lib/msf/ui/console/command_dispatcher/core.rb | 4 +- 6 files changed, 104 insertions(+), 26 deletions(-) diff --git a/lib/msf/base/serializer/readable_text.rb b/lib/msf/base/serializer/readable_text.rb index 4b8daa888d..6ea76a86b7 100644 --- a/lib/msf/base/serializer/readable_text.rb +++ b/lib/msf/base/serializer/readable_text.rb @@ -17,26 +17,26 @@ class ReadableText # Returns a formatted string that contains information about # the supplied module instance. # - def self.dump_module(mod) + def self.dump_module(mod, indent = " ") case mod.type when MODULE_PAYLOAD - return dump_payload_module(mod) + return dump_payload_module(mod, indent) + when MODULE_NOP + return dump_nop_module(mod, indent) when MODULE_EXPLOIT - return dump_exploit_module(mod) + return dump_exploit_module(mod, indent) else - return dump_generic_module(mod) + return dump_generic_module(mod, indent) end end - def self.dump_exploit_module(mod) + def self.dump_exploit_module(mod, indent) end # # Dumps information about a payload module. # - def self.dump_payload_module(mod) - indent = " " - + def self.dump_payload_module(mod, indent) # General output = "\n" output += " Name: #{mod.name}\n" @@ -55,15 +55,19 @@ class ReadableText output += "\n" # Options - output += "Available options:\n" - output += dump_options(mod) - output += "\n" + if (mod.options.has_options?) + output += "Available options:\n" + output += dump_options(mod) + output += "\n" + end # Advanced options - output += "Advanced options:\n" - output += dump_advanced_options(mod) - output += "\n" - + if (mod.options.has_advanced_options?) + output += "Advanced options:\n" + output += dump_advanced_options(mod) + output += "\n" + end + # Description output += "Description:\n" output += word_wrap(mod.description) @@ -72,7 +76,42 @@ class ReadableText return output end - def self.dump_generic_module(mod) + # + # Dumps information about a nop module. + # + def self.dump_nop_module(mod, indent) + # General + output = "\n" + output += " Name: #{mod.name}\n" + output += " Version: #{mod.version}\n" + #output += " Platform: #{mod.platform_to_s}\n" + output += " Arch: #{mod.arch.to_s}\n" + output += "\n" + + # Authors + output += "Provided by:\n" + mod.each_author { |author| + output += indent + author.to_s + "\n" + } + output += "\n" + + # Advanced options + if (mod.options.has_advanced_options?) + output += "Advanced options:\n" + output += dump_advanced_options(mod) + output += "\n" + end + + # Description + output += "Description:\n" + output += word_wrap(mod.description) + output += "\n\n" + + return output + + end + + def self.dump_generic_module(mod, indent) end # @@ -122,10 +161,12 @@ class ReadableText end # - # TODO: word wrapping + # Jacked from Ernest Ellingson , modified + # a bit to add indention # def self.word_wrap(str, indent = 4, col = 60) - return str + return str.gsub(/.{1,#{col - indent}}(?:\s|\Z)/){ + ( (" " * indent) + $& + 5.chr).gsub(/\n\005/,"\n").gsub(/\005/,"\n")} end end diff --git a/lib/msf/core/exploit.rb b/lib/msf/core/exploit.rb index b4ad76c5a0..dfc1e90633 100644 --- a/lib/msf/core/exploit.rb +++ b/lib/msf/core/exploit.rb @@ -212,5 +212,5 @@ end end -require 'msf/core/exploit/remote/tcp' -require 'msf/core/exploit/remote/dcerpc' +require 'msf/core/exploit/tcp' +require 'msf/core/exploit/dcerpc' diff --git a/lib/msf/core/module_manager.rb b/lib/msf/core/module_manager.rb index c945c49676..f9fea56c77 100644 --- a/lib/msf/core/module_manager.rb +++ b/lib/msf/core/module_manager.rb @@ -31,7 +31,7 @@ class ModuleSet < Hash # Enumerates each module class in the set def each_module(opts = {}, &block) - each_value { |mod| + each_pair { |name, mod| # Filter out incompatible architectures if (opts['arch']) if (!mod_arch_hash[mod]) @@ -50,7 +50,7 @@ class ModuleSet < Hash next if (mod_platform_hash[mod].include?(opts['platform']) == false) end - block.call(mod) + block.call(name, mod) } end @@ -182,13 +182,15 @@ protected # Substitute the base path path_base = file.sub(path + File::SEPARATOR, '') + # Derive the name from the path with the exclusion of the .rb + name = path_base.match(/^(.+?)#{File::SEPARATOR}(.*)(.rb?)$/)[2] + # Chop off the file name - path_base.sub!(/(.+)(#{File::SEPARATOR}.+\.rb)$/, '\1') + path_base.sub!(/(.+)(#{File::SEPARATOR}.+)(.rb?)$/, '\1') # Extract the module's namespace from its path mod = mod_from_name(path_base) type = path_base.match(/^(.+?)#{File::SEPARATOR}+?/)[1].sub(/s$/, '') - name = path_base.match(/^(.+?)#{File::SEPARATOR}(.*)$/)[2] # Let's rock the house now... dlog("Loading module from #{path_base}...", 'core', LEV_1) diff --git a/lib/msf/core/nop.rb b/lib/msf/core/nop.rb index 9ae0c71900..1bbaa250d9 100644 --- a/lib/msf/core/nop.rb +++ b/lib/msf/core/nop.rb @@ -12,6 +12,11 @@ module Msf ### class Nop < Msf::Module + # NOP module, bitch! + def type + return MODULE_NOP + end + # # Stub method for generating a sled with the provided arguments. Derived # Nop implementations must supply a length and can supply one or more of diff --git a/lib/msf/core/option_container.rb b/lib/msf/core/option_container.rb index f0354eeb50..8ce6ba2b12 100644 --- a/lib/msf/core/option_container.rb +++ b/lib/msf/core/option_container.rb @@ -158,18 +158,24 @@ end ### class OptionContainer < Hash + # # Merges in the supplied options and converts them to a OptBase # as necessary. + # def initialize(opts = {}) add_options(opts) end + # # Return the value associated with the supplied name + # def [](name) return get(name) end + # # Return the option associated with the supplied name + # def get(name) begin return fetch(name) @@ -177,6 +183,30 @@ class OptionContainer < Hash end end + # + # Returns whether or not the container has any options, + # excluding advanced. + # + def has_options? + each_option { |name, opt| + return true if (opt.advanced? == false) + } + + return false + end + + # + # Returns whether or not the container has any advanced + # options. + # + def has_advanced_options? + each_option { |name, opt| + return true if (opt.advanced? == true) + } + + return false + end + # Adds one or more options def add_options(opts, owner = nil, advanced = false) return false if (opts == nil) diff --git a/lib/msf/ui/console/command_dispatcher/core.rb b/lib/msf/ui/console/command_dispatcher/core.rb index 0c01ab6745..01b855bcc8 100644 --- a/lib/msf/ui/console/command_dispatcher/core.rb +++ b/lib/msf/ui/console/command_dispatcher/core.rb @@ -283,10 +283,10 @@ protected } }) - module_set.each_module { |mod| + module_set.each_module { |name, mod| instance = mod.new - tbl << [ instance.alias, instance.description ] + tbl << [ name, instance.description ] } print(tbl.to_s)