1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-05 14:57:30 +01:00

more stuff, ui isn't pretty, but just wanting to test shit

git-svn-id: file:///home/svn/incoming/trunk@2509 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
Matt Miller 2005-05-22 20:28:21 +00:00
parent 9ba20c7b34
commit 5521a1254d
4 changed files with 166 additions and 56 deletions

View File

@ -136,7 +136,7 @@ class ModuleManager < ModuleSet
# Returns the set of loaded nop module classes
def nops
return module_sets[MODULE_NOPS]
return module_sets[MODULE_NOP]
end
# Returns the set of loaded payload module classes

View File

@ -8,19 +8,19 @@ module CommandDispatcher
self.driver = in_driver
end
def print_error(msg)
def print_error(msg = '')
driver.print_error(msg)
end
def print_status(msg)
def print_status(msg = '')
driver.print_status(msg)
end
def print_line(msg)
def print_line(msg = '')
driver.print_line(msg)
end
def print(msg)
def print(msg = '')
driver.print(msg)
end

View File

@ -9,6 +9,129 @@ class Core
include Msf::Ui::Console::CommandDispatcher
# Returns the list of commands supported by this command dispatcher
def commands
return {
"?" => "Help menu",
"exit" => "Exit the console",
"help" => "Help menu",
"search" => "Adds one or more module search paths",
"set" => "Sets a variable to a value",
"show" => "Displays modules of a given type, or all modules",
"use" => "Selects a module by name",
"quit" => "Exit the console",
}
end
# Instructs the driver to stop executing
def cmd_exit(args)
print_line("Exiting...")
driver.stop
end
alias cmd_quit cmd_exit
def cmd_help(args)
all_commands = {}
driver.dispatcher_stack.reverse.each { |dispatcher|
begin
commands = dispatcher.commands
rescue
commands = nil
next
end
all_commands.update(commands)
}
# Display the commands
#
# TODO: change to column printing
all_commands.sort.each { |c|
cmd, desc = c
print_line(" #{cmd} #{desc}")
}
end
alias cmd_? cmd_help
# Adds one or more search paths
def cmd_search(args)
if (args.length == 0)
print_error("No search paths were provided.")
return false
end
args.each { |path|
framework.modules.add_module_path(path)
}
print_line("Added #{args.length} search paths.")
end
# Sets a name to a value in a context aware environment
def cmd_set(args)
# Determine which data store we're operating on
if (mod = get_active_module())
datastore = mod.datastore
else
datastore = driver.datastore
end
# Dump the contents of the active datastore if no args were supplied
if (args.length == 0)
datastore.each_pair { |name, value|
print_line("#{name}: #{value}")
}
return true
elsif (args.length < 2)
print(
"Usage: set name value\n\n" +
"Sets an arbitrary name to an arbitrary value.\n")
return false
end
# Set the supplied name to the supplied value
name = args[0]
value = args[1]
datastore[name] = value
print_line("#{name} => #{value}")
end
# Displays the list of modules based on their type, or all modules if
# no type is provided
def cmd_show(args)
args << "all" if (args.length == 0)
args.each { |type|
case type
when 'all'
show_encoders
show_nops
show_exploits
show_payloads
show_recon
when 'encoders'
show_encoders
when 'nops'
show_nops
when 'exploits'
show_exploits
when 'payloads'
show_payloads
when 'recon'
show_recon
end
}
end
# Uses a module
def cmd_use(args)
if (args.length == 0)
@ -50,57 +173,44 @@ class Core
driver.update_prompt("#{mod.type}(#{mod_name}) ")
end
# Adds one or more search paths
def cmd_search(args)
args.each { |path|
framework.modules.add_module_path(path)
protected
#
# Module list enumeration
#
def show_encoders
show_module_set("Encoders", framework.encoders)
end
def show_nops
show_module_set("NOP Generators", framework.nops)
end
def show_exploits
show_module_set("Exploits", framework.exploits)
end
def show_payloads
show_module_set("Payloads", framework.payloads)
end
def show_recon
show_module_set("Recon", framework.recon)
end
def show_module_set(type, module_set)
print_line("#{type}:")
module_set.each_module { |mod|
instance = mod.new
print_line("#{instance.class} #{instance.name}")
}
print_line("Added #{args.length} search paths.")
print_line
end
# Sets a name to a value in a context aware environment
def cmd_set(args)
# Determine which data store we're operating on
if (mod = get_active_module())
datastore = mod.datastore
else
datastore = driver.datastore
end
# Dump the contents of the active datastore if no args were supplied
if (args.length == 0)
datastore.each_pair { |name, value|
print_line("#{name}: #{value}")
}
return true
elsif (args.length < 2)
print(
"Usage: set name value\n\n" +
"Sets an arbitrary name to an arbitrary value.\n")
return false
end
# Set the supplied name to the supplied value
name = args[0]
value = args[1]
datastore[name] = value
print_line("#{name} => #{value}")
end
# Instructs the driver to stop executing
def cmd_exit(args)
print_line("Exiting...")
driver.stop
end
alias cmd_quit cmd_exit
end
end end end end

View File

@ -6,19 +6,19 @@ class OutputMethod
end
class StdioOutputMethod < OutputMethod
def print_error(msg)
def print_error(msg = '')
print_line("[*] #{msg}")
end
def print_status(msg)
def print_status(msg = '')
print_line("[-] #{msg}")
end
def print_line(msg)
def print_line(msg = '')
print(msg + "\n")
end
def print(msg)
def print(msg = '')
$stdout.print(msg)
end
end