CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/post/meterpreter/channels/pools/stream_pool.rb
Views: 1904
1
# -*- coding: binary -*-
2
3
require 'rex/io/stream_abstraction'
4
require 'rex/post/meterpreter/channels/pool'
5
require 'rex/post/meterpreter/extensions/stdapi/tlv'
6
7
module Rex
8
module Post
9
module Meterpreter
10
module Channels
11
module Pools
12
13
###
14
#
15
# StreamPool
16
# ----------
17
#
18
# This class represents a channel that is associated with a
19
# streaming pool that has no definite end-point. While this
20
# may seem a paradox given the stream class of channels, it's
21
# in fact dinstinct because streams automatically forward
22
# traffic between the two ends of the channel whereas
23
# stream pools are always requested data in a single direction.
24
#
25
###
26
class StreamPool < Rex::Post::Meterpreter::Channels::Pool
27
28
include Rex::IO::StreamAbstraction
29
30
##
31
#
32
# Constructor
33
#
34
##
35
36
# Initializes the file channel instance
37
def initialize(client, cid, type, flags, packet, **_)
38
super(client, cid, type, flags, packet)
39
40
initialize_abstraction
41
end
42
43
##
44
#
45
# Streaming pools don't support tell, seek, or eof.
46
#
47
##
48
49
#
50
# This method returns the current offset into the pool.
51
#
52
def tell
53
raise NotImplementedError
54
end
55
56
#
57
# This method seeks to an offset in the pool.
58
#
59
def seek
60
raise NotImplementedError
61
end
62
63
#
64
# This method returns whether or not eof has been returned.
65
#
66
def eof
67
return false
68
end
69
70
#
71
# Transfers data to the local half of the pool for reading.
72
#
73
def dio_write_handler(packet, data)
74
rv = Rex::ThreadSafe.select(nil, [rsock], nil, 0.01)
75
if(rv)
76
rsock.write(data)
77
return true
78
else
79
return false
80
end
81
end
82
83
#
84
# Closes the local half of the pool stream.
85
#
86
def dio_close_handler(packet)
87
rsock.close
88
89
return super(packet)
90
end
91
92
#
93
# Cleans up resources used by the channel.
94
#
95
def cleanup
96
super
97
98
cleanup_abstraction
99
end
100
101
end
102
103
end; end; end; end; end
104
105
106