fixed up meterp, use is working

git-svn-id: file:///home/svn/incoming/trunk@2792 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Matt Miller 2005-07-18 05:59:27 +00:00
parent 4679586c49
commit 45b1e69210
11 changed files with 90 additions and 9 deletions

View File

@ -25,6 +25,11 @@ class Meterpreter < Rex::Post::Meterpreter::Client
def initialize(rstream) def initialize(rstream)
super super
#
# Initialize the meterpreter client
#
self.init_meterpreter(rstream)
# #
# Create the console instance # Create the console instance
# #

View File

@ -31,6 +31,13 @@ class Client
# Initializes the client context with the supplied socket through # Initializes the client context with the supplied socket through
# which communication with the server will be performed # which communication with the server will be performed
def initialize(sock, to = self.class.default_timeout) def initialize(sock, to = self.class.default_timeout)
init_meterpreter(sock, to)
end
#
# Initializes the meterpreter client instance
#
def init_meterpreter(sock, to = self.class.default_timeout)
self.sock = sock self.sock = sock
self.parser = PacketParser.new self.parser = PacketParser.new
self.ext = ObjectAliases.new self.ext = ObjectAliases.new
@ -82,7 +89,7 @@ class Client
# Loads the client half of the supplied extension and initializes it as a # Loads the client half of the supplied extension and initializes it as a
# registered extension that can be reached through client.ext.[extension]. # registered extension that can be reached through client.ext.[extension].
def add_extension(name) def add_extension(name)
require("Rex/Post/Meterpreter/Extensions/#{name}/#{name}") require("rex/post/meterpreter/extensions/#{name.downcase}/#{name.downcase}")
# XXX might want to be safer and catch the exception here? # XXX might want to be safer and catch the exception here?
# maybe not since we are just going to reraise right away... # maybe not since we are just going to reraise right away...

View File

@ -126,9 +126,6 @@ class ClientCore < Extension
Module Module
The module that should be loaded The module that should be loaded
Modules
The modules that should be loaded
LoadFromDisk LoadFromDisk
Indicates that the library should be loaded from disk, not from Indicates that the library should be loaded from disk, not from
memory on the remote machine memory on the remote machine
@ -137,9 +134,19 @@ class ClientCore < Extension
if (mod == nil) if (mod == nil)
raise RuntimeError, "No modules were specified", caller raise RuntimeError, "No modules were specified", caller
end end
# Get us to the installation root and then into data/meterpreter, where
# the file is expected to be
path = File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'data/meterpreter/ext_server_' + mod.downcase + '.dll')
if (opts['ExtensionPath'])
path = opts['ExtensionPath']
end
path = File.expand_path(path)
# Load the extension DLL
if (load_library( if (load_library(
'LibraryFilePath' => 'Data/meterpreter/ext_server_' + mod.downcase + '.dll', 'LibraryFilePath' => path,
'UploadLibrary' => true, 'UploadLibrary' => true,
'Extension' => true, 'Extension' => true,
'SaveToDisk' => opts['LoadFromDisk'])) 'SaveToDisk' => opts['LoadFromDisk']))
@ -315,7 +322,7 @@ class ClientCore < Extension
wrote = client.sock.write(inject_lib) wrote = client.sock.write(inject_lib)
# Transmit the size of the server # Transmit the size of the server
metsrv = "Data/meterpreter/metsrv.dll" metsrv = "data/meterpreter/metsrv.dll"
buf = "metsrv.dll\x00" + ::IO.readlines(metsrv).join buf = "metsrv.dll\x00" + ::IO.readlines(metsrv).join
size = buf.length size = buf.length

View File

@ -87,7 +87,11 @@ module PacketDispatcher
# Spawn a new thread that monitors the socket # Spawn a new thread that monitors the socket
thr = ::Thread.new { thr = ::Thread.new {
while (true) while (true)
rv = select([ self.sock ], nil, nil, 2) begin
rv = Rex::ThreadSafe.select([ self.sock.fd ], nil, nil, 2)
rescue
dlog("Exception caught in monitor_socket: #{$!}", 'meterpreter', LEV_1)
end
begin begin
packet = receive_packet packet = receive_packet

View File

@ -19,6 +19,7 @@ class Console
include Rex::Ui::Text::DispatcherShell include Rex::Ui::Text::DispatcherShell
# Dispatchers # Dispatchers
require 'rex/post/meterpreter/ui/console/command_dispatcher'
require 'rex/post/meterpreter/ui/console/core' require 'rex/post/meterpreter/ui/console/core'
# #

View File

@ -0,0 +1,38 @@
module Rex
module Post
module Meterpreter
module Ui
###
#
# CommandDispatcher
# -----------------
#
# Base class for all command dispatchers within the meterpreter console user
# interface.
#
###
module Console::CommandDispatcher
include Rex::Ui::Text::DispatcherShell::CommandDispatcher
#
# Returns the meterpreter client context
#
def client
shell.client
end
#
# Log that an error occurred
#
def log_error(msg)
print_error(msg)
end
end
end
end
end
end

View File

@ -15,7 +15,7 @@ module Ui
### ###
class Console::Core class Console::Core
include Rex::Ui::Text::DispatcherShell::CommandDispatcher include Console::CommandDispatcher
@@use_opts = Rex::Parser::Arguments.new( @@use_opts = Rex::Parser::Arguments.new(
"-m" => [ true, "The name of the module or modules to load (Ex: stdapi)." ], "-m" => [ true, "The name of the module or modules to load (Ex: stdapi)." ],
@ -49,17 +49,36 @@ class Console::Core
args.unshift("-h") args.unshift("-h")
end end
modules = nil
@@use_opts.parse(args) { |opt, idx, val| @@use_opts.parse(args) { |opt, idx, val|
case opt case opt
when "-m" when "-m"
mod = val modules = val.split(/,\s?/)
when "-h" when "-h"
print( print(
"Usage: use [options]\n\n" + "Usage: use [options]\n\n" +
"Loads a meterpreter extension module or modules.\n" + "Loads a meterpreter extension module or modules.\n" +
@use_opts.usage) @use_opts.usage)
return true
end end
} }
# Load each of the modules
modules.each { |m|
print("Loading extension #{m}...")
begin
client.core.use(m)
rescue
log_error("failure: #{$!}")
next
end
print_line("success.")
}
return true
end end
end end