From 6f6924e001c1a295a0f1d390dc310ef34fb555cf Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Fri, 30 Sep 2005 05:59:44 +0000 Subject: [PATCH] meterpreter comm session implemented, untested git-svn-id: file:///home/svn/incoming/trunk@2920 4d416f70-5f16-0410-b530-b9f4589650da --- documentation/plan.txt | 2 +- lib/msf/base/sessions/meterpreter.rb | 22 ++++++++++++++++++++ lib/msf/core/session.rb | 1 + lib/msf/core/session/comm.rb | 30 ++++++++++++++++++++++++++++ lib/rex/socket.rb | 4 ++++ lib/rex/socket/comm.rb | 28 ++++++++++++++++++++++++++ lib/rex/socket/comm/local.rb | 3 ++- 7 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 lib/msf/core/session/comm.rb create mode 100644 lib/rex/socket/comm.rb diff --git a/documentation/plan.txt b/documentation/plan.txt index c03c108910..d53751bd04 100644 --- a/documentation/plan.txt +++ b/documentation/plan.txt @@ -6,7 +6,7 @@ X - meterpreter X - pivoting X - portfwd command - networking - - switch board routing table for pivoting +X - switch board routing table for pivoting - meterpreter 'comm' support - proxy 'comm' support - asm diff --git a/lib/msf/base/sessions/meterpreter.rb b/lib/msf/base/sessions/meterpreter.rb index ca5db474ab..c24f851501 100644 --- a/lib/msf/base/sessions/meterpreter.rb +++ b/lib/msf/base/sessions/meterpreter.rb @@ -21,6 +21,7 @@ class Meterpreter < Rex::Post::Meterpreter::Client # include Msf::Session include Msf::Session::Interactive + include Msf::Session::Comm def initialize(rstream) super @@ -89,6 +90,27 @@ class Meterpreter < Rex::Post::Meterpreter::Client raise EOFError if (console.stopped? == true) end + + ## + # + # Msf::Session::Comm implementors + # + ## + + # + # Creates a connection based on the supplied parameters and returns it to + # the caller. The connection is created relative to the remote machine on + # which the meterpreter server instance is running. + # + def create(param) + case param.proto + when 'tcp' + return net.socket.create(param) + else + raise Rex::UnsupportedProtocol.new(param.proto), caller + end + end + protected attr_accessor :rstream, :console diff --git a/lib/msf/core/session.rb b/lib/msf/core/session.rb index 70fbadbafa..f08b9cce18 100644 --- a/lib/msf/core/session.rb +++ b/lib/msf/core/session.rb @@ -46,6 +46,7 @@ module Session # Direct descendents require 'msf/core/session/interactive' require 'msf/core/session/basic' + require 'msf/core/session/comm' # Provider interfaces require 'msf/core/session/provider/single_command_execution' diff --git a/lib/msf/core/session/comm.rb b/lib/msf/core/session/comm.rb new file mode 100644 index 0000000000..a5bd3f8053 --- /dev/null +++ b/lib/msf/core/session/comm.rb @@ -0,0 +1,30 @@ +require 'rex/socket' + +module Msf +module Session + +### +# +# Comm +# ---- +# +# This class implements the Rex::Socket::Comm module interface and is capable +# of creating network-based connections that are pivoted from the session in +# question. +# +### +module Comm + include Rex::Socket::Comm + + # + # Session-based comm classes implement an instance specific method for + # creating network-based connections rather than the typicall class + # specific methods. + # + def create(param) + raise NotImplementedError + end +end + +end +end diff --git a/lib/rex/socket.rb b/lib/rex/socket.rb index 1d0a6ab566..732fcd6ca7 100644 --- a/lib/rex/socket.rb +++ b/lib/rex/socket.rb @@ -1,5 +1,6 @@ require 'socket' require 'resolv' +require 'rex/exceptions' module Rex @@ -19,7 +20,10 @@ module Socket require 'rex/socket/parameters' require 'rex/socket/tcp' require 'rex/socket/tcp_server' + + require 'rex/socket/comm' require 'rex/socket/comm/local' + require 'rex/socket/switch_board' ## diff --git a/lib/rex/socket/comm.rb b/lib/rex/socket/comm.rb new file mode 100644 index 0000000000..3a21f94043 --- /dev/null +++ b/lib/rex/socket/comm.rb @@ -0,0 +1,28 @@ +require 'rex/socket' + +module Rex +module Socket + +### +# +# Comm +# ---- +# +# This mixin provides the basic interface that a derived class must implement +# in order to be a compatible comm class. +# +### +module Comm + + # + # Creates a compatible socket based on the supplied uniform parameters. + # + def self.create(param) + raise NotImplementedError + end + +end + +end +end + diff --git a/lib/rex/socket/comm/local.rb b/lib/rex/socket/comm/local.rb index bc29949d61..6f919a1b0c 100644 --- a/lib/rex/socket/comm/local.rb +++ b/lib/rex/socket/comm/local.rb @@ -1,4 +1,3 @@ -require 'rex/exceptions' require 'rex/socket' require 'rex/socket/tcp' require 'rex/socket/ssl_tcp' @@ -14,6 +13,8 @@ require 'rex/socket/udp' ### class Rex::Socket::Comm::Local + include Rex::Socket::Comm + # # Creates an instance of a socket using the supplied parameters. #