2005-12-17 06:46:23 +00:00
|
|
|
#!/usr/bin/env ruby
|
2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2005-04-13 08:19:22 +00:00
|
|
|
|
2005-07-09 21:18:49 +00:00
|
|
|
require 'rex/io/stream_abstraction'
|
|
|
|
require 'rex/post/meterpreter/channel'
|
2005-04-13 08:19:22 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
#
|
|
|
|
###
|
2005-04-21 06:32:01 +00:00
|
|
|
class Stream < Rex::Post::Meterpreter::Channel
|
2005-04-13 08:19:22 +00:00
|
|
|
|
2005-07-08 00:30:10 +00:00
|
|
|
include Rex::IO::StreamAbstraction
|
2005-04-13 08:19:22 +00:00
|
|
|
|
2009-12-08 18:32:26 +00:00
|
|
|
class << self
|
2005-04-13 08:19:22 +00:00
|
|
|
def cls
|
|
|
|
return CHANNEL_CLASS_STREAM
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
|
|
|
# Constructor
|
|
|
|
#
|
|
|
|
##
|
2005-11-15 05:22:13 +00:00
|
|
|
|
|
|
|
#
|
2005-04-13 08:19:22 +00:00
|
|
|
# Passes the initialization information up to the base class
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
2005-04-13 08:19:22 +00:00
|
|
|
def initialize(client, cid, type, flags)
|
2010-02-06 20:12:52 +00:00
|
|
|
# sf: initialize_abstraction() before super() as we can get a scenario where dio_write_handler() is called
|
|
|
|
# with data to write to the rsock but rsock has not yet been initialized. This happens if the channel
|
|
|
|
# is registered (client.add_channel(self) in Channel.initialize) to a session and a 'core_channel_write'
|
|
|
|
# request comes in before we have called self.initialize_abstraction()
|
2005-04-15 06:23:59 +00:00
|
|
|
initialize_abstraction
|
2010-02-06 20:12:52 +00:00
|
|
|
super(client, cid, type, flags)
|
2005-04-13 08:19:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
#
|
2005-04-21 06:32:01 +00:00
|
|
|
# Remote I/O handlers
|
2005-04-13 08:19:22 +00:00
|
|
|
#
|
|
|
|
##
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# Performs a write operation on the right side of the local stream.
|
|
|
|
#
|
2005-04-13 08:19:22 +00:00
|
|
|
def dio_write_handler(packet, data)
|
2009-12-10 05:40:26 +00:00
|
|
|
rv = Rex::ThreadSafe.select(nil, [rsock], nil, 0.01)
|
|
|
|
if(rv)
|
|
|
|
rsock.write(data)
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
2005-04-13 08:19:22 +00:00
|
|
|
end
|
|
|
|
|
2005-11-15 05:22:13 +00:00
|
|
|
#
|
|
|
|
# Performs a close operation on the right side of the local stream.
|
|
|
|
#
|
2005-04-13 08:19:22 +00:00
|
|
|
def dio_close_handler(packet)
|
|
|
|
rsock.close
|
2009-12-08 18:32:26 +00:00
|
|
|
|
2005-04-13 08:19:22 +00:00
|
|
|
return super(packet)
|
|
|
|
end
|
|
|
|
|
2005-07-26 04:08:01 +00:00
|
|
|
#
|
2005-11-15 05:22:13 +00:00
|
|
|
# Cleans up the stream abstraction.
|
2005-07-26 04:08:01 +00:00
|
|
|
#
|
|
|
|
def cleanup
|
|
|
|
super
|
|
|
|
|
|
|
|
cleanup_abstraction
|
|
|
|
end
|
|
|
|
|
2005-04-13 08:19:22 +00:00
|
|
|
end
|
|
|
|
|
2009-12-08 18:32:26 +00:00
|
|
|
end; end; end
|
|
|
|
|