Class: Rex::Post::Meterpreter::Stream

Inherits:
Channel
  • Object
show all
Includes:
IO::StreamAbstraction
Defined in:
lib/rex/post/meterpreter/channels/stream.rb

Overview

Stream


This class represents a channel that is streaming. This means that sequential data is flowing in either one or both directions.

Instance Attribute Summary

Attributes included from IO::StreamAbstraction

#lsock, #rsock

Attributes inherited from Channel

#cid, #client, #cls, #flags, #params, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IO::StreamAbstraction

#cleanup_abstraction, #close, #initialize_abstraction, #localinfo, #peerinfo, #shutdown, #sysread, #syswrite

Methods inherited from Channel

_close, #_close, #_read, #_write, #close, #close_read, #close_write, create, #dio_handler, #dio_map, #dio_read_handler, finalize, #flag?, #interactive, #read, request_handler, #synchronous?, #write

Methods included from InboundPacketHandler

#request_handler, #response_handler

Constructor Details

#initialize(client, cid, type, flags) ⇒ Stream

Passes the initialization information up to the base class



39
40
41
42
43
44
45
46
# File 'lib/rex/post/meterpreter/channels/stream.rb', line 39

def initialize(client, cid, type, flags)
	# 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()
	initialize_abstraction
	super(client, cid, type, flags)
end

Class Method Details

.clsObject



25
26
27
# File 'lib/rex/post/meterpreter/channels/stream.rb', line 25

def cls
	return CHANNEL_CLASS_STREAM
end

Instance Method Details

#cleanupObject

Cleans up the stream abstraction.



79
80
81
82
83
# File 'lib/rex/post/meterpreter/channels/stream.rb', line 79

def cleanup
	super

	cleanup_abstraction
end

#dio_close_handler(packet) ⇒ Object

Performs a close operation on the right side of the local stream.



70
71
72
73
74
# File 'lib/rex/post/meterpreter/channels/stream.rb', line 70

def dio_close_handler(packet)
	rsock.close

	return super(packet)
end

#dio_write_handler(packet, data) ⇒ Object

Performs a write operation on the right side of the local stream.



57
58
59
60
61
62
63
64
65
# File 'lib/rex/post/meterpreter/channels/stream.rb', line 57

def dio_write_handler(packet, data)
	rv = Rex::ThreadSafe.select(nil, [rsock], nil, 0.01)
	if(rv)
		rsock.write(data)
		return true
	else
		return false
	end
end