forked from rapid7/metasploit-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
git-svn-id: file:///home/svn/incoming/trunk@2508 4d416f70-5f16-0410-b530-b9f4589650da
- Loading branch information
Matt Miller
committed
May 22, 2005
1 parent
e69dece
commit 9ba20c7
Showing
15 changed files
with
552 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Msf | ||
module Ui | ||
end | ||
end | ||
|
||
require 'Msf/Ui/Driver' | ||
require 'Msf/Ui/Console' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Msf | ||
module Ui | ||
module Console | ||
|
||
|
||
end | ||
end | ||
end | ||
|
||
require 'Msf/Ui/Console/Driver' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module Msf | ||
module Ui | ||
module Console | ||
|
||
module CommandDispatcher | ||
|
||
def initialize(in_driver) | ||
self.driver = in_driver | ||
end | ||
|
||
def print_error(msg) | ||
driver.print_error(msg) | ||
end | ||
|
||
def print_status(msg) | ||
driver.print_status(msg) | ||
end | ||
|
||
def print_line(msg) | ||
driver.print_line(msg) | ||
end | ||
|
||
def print(msg) | ||
driver.print(msg) | ||
end | ||
|
||
def update_prompt(prompt) | ||
driver.update_prompt(prompt) | ||
end | ||
|
||
def framework | ||
return driver.framework | ||
end | ||
|
||
def set_active_module(mod) | ||
driver.datastore['_ActiveModule'] = mod | ||
end | ||
|
||
def get_active_module | ||
return driver.datastore['_ActiveModule'] | ||
end | ||
|
||
protected | ||
|
||
attr_accessor :driver | ||
|
||
end | ||
|
||
end end end | ||
|
||
require 'Msf/Ui/Console/ModuleCommandDispatcher' | ||
require 'Msf/Ui/Console/CommandDispatcher/Core' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
require 'Msf/Ui/Console/CommandDispatcher/Encoder' | ||
|
||
module Msf | ||
module Ui | ||
module Console | ||
module CommandDispatcher | ||
|
||
class Core | ||
|
||
include Msf::Ui::Console::CommandDispatcher | ||
|
||
# Uses a module | ||
def cmd_use(args) | ||
if (args.length == 0) | ||
print( | ||
"Usage: use module_name\n\n" + | ||
"The use command is used to interact with a module of a given name.\n") | ||
return false | ||
end | ||
|
||
# Try to create an instance of the supplied module name | ||
mod_name = args[0] | ||
|
||
begin | ||
if ((mod = framework.modules.create(mod_name)) == nil) | ||
print_error("Failed to load module: #{mod_name}") | ||
return false | ||
end | ||
rescue NameError => info | ||
print_error("The supplied module name is ambiguous.") | ||
return false | ||
end | ||
|
||
# Enstack the command dispatcher for this module type | ||
dispatcher = nil | ||
|
||
case mod.type | ||
when MODULE_ENCODER | ||
dispatcher = Encoder | ||
end | ||
|
||
if (dispatcher != nil) | ||
driver.enstack_dispatcher(dispatcher) | ||
end | ||
|
||
# Update the active module | ||
set_active_module(mod) | ||
|
||
# Update the command prompt | ||
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) | ||
} | ||
|
||
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 | ||
|
||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Msf | ||
module Ui | ||
module Console | ||
module CommandDispatcher | ||
|
||
class Encoder | ||
|
||
include Msf::Ui::Console::ModuleCommandDispatcher | ||
|
||
def cmd_encode(args) | ||
end | ||
|
||
end | ||
|
||
end end end end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
require 'Msf/Core' | ||
require 'Msf/Ui' | ||
require 'Msf/Ui/Console/Shell' | ||
require 'Msf/Ui/Console/CommandDispatcher' | ||
|
||
module Msf | ||
module Ui | ||
module Console | ||
|
||
|
||
### | ||
# | ||
# Driver | ||
# ------ | ||
# | ||
# This class implements a user interface driver on a console interface. | ||
# | ||
### | ||
class Driver < Msf::Ui::Driver | ||
|
||
include Msf::Ui::Console::Shell | ||
|
||
def initialize(prompt = "msf") | ||
# Initialize attributes | ||
self.framework = Msf::Framework.new | ||
self.dispatcher_stack = [] | ||
|
||
# Add the core command dispatcher as the root of the dispatcher | ||
# stack | ||
enstack_dispatcher(CommandDispatcher::Core) | ||
|
||
# Initialize the super | ||
super(prompt) | ||
end | ||
|
||
# Run a single command line | ||
def run_single(line) | ||
arguments = parse_line(line) | ||
method = arguments.shift | ||
found = false | ||
|
||
if (method) | ||
entries = dispatcher_stack.length | ||
|
||
dispatcher_stack.each { |dispatcher| | ||
begin | ||
eval(" | ||
if (dispatcher.respond_to?('cmd_' + method)) | ||
dispatcher.#{'cmd_' + method}(arguments) | ||
found = true | ||
end") | ||
rescue | ||
output.print_error("Error while running command #{method}: #{$!}.") | ||
end | ||
|
||
# If the dispatcher stack changed as a result of this command, | ||
# break out | ||
break if (dispatcher_stack.length != entries) | ||
} | ||
|
||
if (!found) | ||
output.print_error("Unknown command: #{method}.") | ||
end | ||
end | ||
|
||
return found | ||
end | ||
|
||
# Push a dispatcher to the front of the stack | ||
def enstack_dispatcher(dispatcher) | ||
self.dispatcher_stack.unshift(dispatcher.new(self)) | ||
end | ||
|
||
# Pop a dispatcher from the front of the stacker | ||
def destack_dispatcher | ||
self.dispatcher_stack.shift | ||
end | ||
|
||
attr_reader :dispatcher_stack, :framework | ||
|
||
protected | ||
|
||
attr_writer :dispatcher_stack, :framework | ||
|
||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require 'Msf/Ui' | ||
|
||
module Msf | ||
module Ui | ||
module Console | ||
|
||
### | ||
# | ||
# InputMethod | ||
# ----------- | ||
# | ||
# This class is the base class for the three kinds of console input methods: | ||
# Stdio, File, and Readline. These classes are nearly idential to the classes | ||
# found in irb. | ||
# | ||
### | ||
class InputMethod | ||
def initialize | ||
self.eof = false | ||
end | ||
|
||
def gets | ||
raise NotImplementedError | ||
end | ||
|
||
def eof? | ||
return eof | ||
end | ||
|
||
attr_accessor :prompt, :eof | ||
end | ||
|
||
class StdioInputMethod < InputMethod | ||
def gets | ||
print prompt | ||
return $stdin.gets | ||
end | ||
|
||
def eof? | ||
return $stdin.eof? | ||
end | ||
end | ||
|
||
begin | ||
require 'readline' | ||
|
||
class ReadlineInputMethod < InputMethod | ||
include Readline | ||
|
||
def gets | ||
if ((line = readline(prompt, true))) | ||
HISTORY.pop if (line.empty?) | ||
return line + "\n" | ||
else | ||
eof = true | ||
return line | ||
end | ||
end | ||
end | ||
rescue LoadError | ||
end | ||
|
||
class FileInputMethod < InputMethod | ||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.