channel listing foo

git-svn-id: file:///home/svn/incoming/trunk@2836 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Matt Miller 2005-07-26 05:15:46 +00:00
parent 94e7e01ff9
commit 2173ba8fc8
3 changed files with 98 additions and 31 deletions

View File

@ -9,9 +9,9 @@ module Meterpreter
#
# The various types of channels
#
CHANNEL_CLASS_STREAM = 1
CHANNEL_CLASS_DATAGRAM = 2
CHANNEL_CLASS_POOL = 3
CHANNEL_CLASS_STREAM = 'stream'
CHANNEL_CLASS_DATAGRAM = 'datagram'
CHANNEL_CLASS_POOL = 'pool'
#
# The various flags that can affect how the channel operates
@ -298,7 +298,7 @@ class Channel
# Stub close handler
def dio_close_handler(packet)
client.remove_channel(self)
client.remove_channel(self.cid)
# Trap IOErrors as parts of the channel may have already been closed
begin

View File

@ -14,28 +14,39 @@ module Meterpreter
###
module ChannelContainer
#
# Initializes the channel association hash
#
def initialize_channels
self.channels = {}
end
#
# Adds a channel to the container that is indexed by its channel identifier
#
def add_channel(channel)
self.channels[channel.cid] = channel
end
#
# Looks up a channel instance based on its channel identifier
#
def find_channel(cid)
return self.channels[cid]
end
#
# Removes a channel based on its channel identifier
#
def remove_channel(cid)
return self.channels.delete(cid)
end
attr_reader :channels
protected
attr_accessor :channels
attr_writer :channels
end

View File

@ -25,7 +25,7 @@ class Console::CommandDispatcher::Core
end
@@use_opts = Rex::Parser::Arguments.new(
"-h" => [ false, "Help banner." ])
"-h" => [ false, "Help menu." ])
#
# List of supported commands
@ -33,6 +33,8 @@ class Console::CommandDispatcher::Core
def commands
{
"?" => "Help menu",
"close" => "Closes a channel",
"channel" => "Displays information about active channels",
"exit" => "Terminate the meterpreter session",
"help" => "Help menu",
"interact" => "Interacts with a channel",
@ -41,7 +43,6 @@ class Console::CommandDispatcher::Core
"quit" => "Terminate the meterpreter session",
"read" => "Reads data from a channel",
"write" => "Writes data to a channel",
"close" => "Closes a channel",
}
end
@ -52,6 +53,85 @@ class Console::CommandDispatcher::Core
"Core"
end
#
# Displays information about active channels
#
@@channel_opts = Rex::Parser::Arguments.new(
"-l" => [ false, "List active channels." ],
"-h" => [ false, "Help menu." ])
def cmd_channel(*args)
if (args.length == 0)
args.unshift("-h")
end
mode = nil
# Parse options
@@channel_opts.parse(args) { |opt, idx, val|
case opt
when "-h"
print(
"Usage: channel [options]\n\n" +
"Displays information about active channels.\n" +
@@channel_opts.usage)
return true
when "-l"
mode = 'list'
end
}
# No mode, no service.
if (mode == nil)
return true
elsif (mode == 'list')
tbl = Rex::Ui::Text::Table.new(
'Indent' => 4,
'Columns' =>
[
'Id',
'Class',
'Type'
])
items = 0
client.channels.each_pair { |cid, channel|
tbl << [ cid, channel.class.cls, channel.type ]
items += 1
}
if (items == 0)
print_line("No active channels.")
else
print("\n" + tbl.to_s + "\n")
end
end
end
#
# Closes a supplied channel.
#
def cmd_close(*args)
if (args.length == 0)
print_line(
"Usage: close channel_id\n\n" +
"Closes the supplied channel.")
return true
end
cid = args[0].to_i
channel = client.find_channel(cid)
if (!channel)
print_error("Invalid channel identifier specified.")
return true
else
channel.close
print_status("Closed channel #{cid}.")
end
end
#
# Terminates the meterpreter session.
#
@ -271,30 +351,6 @@ class Console::CommandDispatcher::Core
return true
end
#
# Closes a supplied channel.
#
def cmd_close(*args)
if (args.length == 0)
print_line(
"Usage: close channel_id\n\n" +
"Closes the supplied channel.")
return true
end
cid = args[0].to_i
channel = client.find_channel(cid)
if (!channel)
print_error("Invalid channel identifier specified.")
return true
else
channel.close
print_status("Closed channel #{cid}.")
end
end
protected
attr_accessor :extensions, :ext_hash