more channel foo

git-svn-id: file:///home/svn/incoming/trunk@2376 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Matt Miller 2005-04-13 08:19:22 +00:00
parent ca42291606
commit 3338ebb82c
7 changed files with 193 additions and 30 deletions

View File

@ -233,7 +233,36 @@ class Channel
# Handles dispatching I/O requests based on the request packet.
# The default implementation does nothing with direct I/O requests.
def dio_handler(dio, packet)
return nil
if (dio == CHANNEL_DIO_READ)
length = packet.get_tlv_value(TLV_TYPE_LENGTH)
return dio_read_handler(packet, length)
elsif (dio == CHANNEL_DIO_WRITE)
data = packet.get_tlv_value(TLV_TYPE_CHANNEL_DATA)
return dio_write_handler(packet, data)
elsif (dio == CHANNEL_DIO_CLOSE)
return dio_close_handler(packet)
end
return false;
end
# Stub read handler
def dio_read_handler(packet, length)
return false
end
# Stub write handler
def dio_write_handler(packet, data)
return false
end
# Stub close handler
def dio_close_handler(packet)
client.remove_channel(self)
return false
end
##

View File

@ -1,6 +1,7 @@
#!/usr/bin/ruby
require 'Rex/Post/Meterpreter/Channels/Pool'
require 'Rex/Post/Meterpreter/Extensions/Stdapi/Tlv'
module Rex
module Post
@ -19,6 +20,27 @@ module Pools
###
class File < Rex::Post::Meterpreter::Channels::Pool
##
#
# Factory
#
##
def File.open(client, name, mode = "r", perm = 0)
return Channel.create(client, 'stdapi_fs_file',
self, CHANNEL_FLAG_SYNCHRONOUS,
[
{
'type' => Rex::Post::Meterpreter::Extensions::Stdapi::TLV_TYPE_FILE_PATH,
'value' => name
},
{
'type' => Rex::Post::Meterpreter::Extensions::Stdapi::TLV_TYPE_FILE_MODE,
'value' => mode + "b"
},
])
end
##
#
# Constructor

View File

@ -0,0 +1,59 @@
#!/usr/bin/ruby
require 'Rex/Socket/StreamAbstraction'
module Rex
module Post
module Meterpreter
###
#
# Stream
# ------
#
# This class represents a channel that is streaming. This means
# that sequential data is flowing in either one or both directions.
#
###
class Stream
include Rex::Socket::StreamAbstraction
class <<self
def cls
return CHANNEL_CLASS_STREAM
end
end
##
#
# Constructor
#
##
# Passes the initialization information up to the base class
def initialize(client, cid, type, flags)
super(client, cid, type, flags)
end
##
#
# I/O handlers
#
##
def dio_write_handler(packet, data)
rsock.write(data)
return true;
end
def dio_close_handler(packet)
rsock.close
return super(packet)
end
end
end; end; end

View File

@ -0,0 +1,48 @@
#!/usr/bin/ruby
require 'Rex/Post/Meterpreter/Channels/Stream'
module Rex
module Post
module Meterpreter
module Channels
###
#
# Tcp
# ---
#
# The TCP class wrappers a stream-based meterpreter channel.
#
###
class Tcp < Rex::Post::Meterpreter::Channels::Stream
##
#
# Factory
#
##
def Tcp.open(client, host, port)
return Channel.create(client, 'net_stream_tcp',
self, CHANNEL_FLAG_SYNCHRONOUS,
[
{ 'type' =>
]
end
##
#
# Constructor
#
##
# Passes the initialization information up to the base class
def initialize(client, cid, type, flags)
super(client, cid, type, flags)
end
end
end; end; end; end

View File

@ -73,13 +73,8 @@ protected
# Creates a File channel using the supplied information
def _open(name, mode = "r", perms = 0)
return Channel.create(self.client, 'stdapi_fs_file',
Rex::Post::Meterpreter::Channels::Pools::File,
CHANNEL_FLAG_SYNCHRONOUS,
[
{ 'type' => TLV_TYPE_FILE_PATH, 'value' => name },
{ 'type' => TLV_TYPE_FILE_MODE, 'value' => mode + "b" },
])
return Rex::Post::Meterpreter::Channels::Pools::File.open(
self.client, name, mode, perms)
end
attr_accessor :client

View File

@ -1,6 +1,7 @@
#!/usr/bin/ruby
require 'Rex/Post/Meterpreter/Extension'
require 'Rex/Post/Meterpreter/Extensions/Stdapi/Tlv'
require 'Rex/Post/Meterpreter/Extensions/Stdapi/Dir'
require 'Rex/Post/Meterpreter/Extensions/Stdapi/File'
require 'Rex/Post/Meterpreter/Extensions/Stdapi/FileStat'
@ -13,28 +14,6 @@ module Meterpreter
module Extensions
module Stdapi
# Process
TLV_TYPE_PID = TLV_META_TYPE_UINT | 0
# Registry
TLV_TYPE_HKEY = TLV_META_TYPE_UINT | 1000
TLV_TYPE_ROOT_KEY = TLV_TYPE_HKEY
TLV_TYPE_BASE_KEY = TLV_META_TYPE_STRING | 1001
TLV_TYPE_PERMISSION = TLV_META_TYPE_UINT | 1002
TLV_TYPE_KEY_NAME = TLV_META_TYPE_STRING | 1003
TLV_TYPE_VALUE_NAME = TLV_META_TYPE_STRING | 1010
TLV_TYPE_VALUE_TYPE = TLV_META_TYPE_UINT | 1011
TLV_TYPE_VALUE_DATA = TLV_META_TYPE_RAW | 1012
# Fs
TLV_TYPE_DIRECTORY_PATH = TLV_META_TYPE_STRING | 1200
TLV_TYPE_FILE_NAME = TLV_META_TYPE_STRING | 1201
TLV_TYPE_FILE_PATH = TLV_META_TYPE_STRING | 1202
TLV_TYPE_FILE_MODE = TLV_META_TYPE_STRING | 1203
TLV_TYPE_STAT_BUF = TLV_META_TYPE_COMPLEX | 1220
DELETE_KEY_FLAG_RECURSIVE = (1 << 0)
###
#
# Stdapi

View File

@ -0,0 +1,31 @@
#!/usr/bin/ruby
module Rex
module Post
module Meterpreter
module Extensions
module Stdapi
# Process
TLV_TYPE_PID = TLV_META_TYPE_UINT | 0
# Registry
TLV_TYPE_HKEY = TLV_META_TYPE_UINT | 1000
TLV_TYPE_ROOT_KEY = TLV_TYPE_HKEY
TLV_TYPE_BASE_KEY = TLV_META_TYPE_STRING | 1001
TLV_TYPE_PERMISSION = TLV_META_TYPE_UINT | 1002
TLV_TYPE_KEY_NAME = TLV_META_TYPE_STRING | 1003
TLV_TYPE_VALUE_NAME = TLV_META_TYPE_STRING | 1010
TLV_TYPE_VALUE_TYPE = TLV_META_TYPE_UINT | 1011
TLV_TYPE_VALUE_DATA = TLV_META_TYPE_RAW | 1012
# Fs
TLV_TYPE_DIRECTORY_PATH = TLV_META_TYPE_STRING | 1200
TLV_TYPE_FILE_NAME = TLV_META_TYPE_STRING | 1201
TLV_TYPE_FILE_PATH = TLV_META_TYPE_STRING | 1202
TLV_TYPE_FILE_MODE = TLV_META_TYPE_STRING | 1203
TLV_TYPE_STAT_BUF = TLV_META_TYPE_COMPLEX | 1220
DELETE_KEY_FLAG_RECURSIVE = (1 << 0)
end; end; end; end; end