Class: Rex::Proto::Http::WebSocket::AmazonSsm::Interface::SsmChannel
- Inherits:
-
Interface::Channel
- Object
- Interface::Channel
- Rex::Proto::Http::WebSocket::AmazonSsm::Interface::SsmChannel
- Includes:
- SsmChannelMethods
- Defined in:
- lib/rex/proto/http/web_socket/amazon_ssm.rb
Instance Attribute Summary collapse
-
#ack_message ⇒ Object
readonly
Returns the value of attribute ack_message.
-
#ack_seq_num ⇒ Object
readonly
Returns the value of attribute ack_seq_num.
-
#out_seq_num ⇒ Object
readonly
Returns the value of attribute out_seq_num.
-
#run_ssm_pub ⇒ Object
readonly
Returns the value of attribute run_ssm_pub.
Attributes included from SsmChannelMethods
Attributes inherited from Interface::Channel
Instance Method Summary collapse
-
#initialize(websocket) ⇒ SsmChannel
constructor
A new instance of SsmChannel.
- #on_data_read(data, _data_type) ⇒ Object
- #on_data_write(data) ⇒ Object
- #publishing? ⇒ Boolean
Methods included from SsmChannelMethods
#_start_ssm_keepalive, #acknowledge_output, #close, #handle_acknowledge, #handle_output_data, #pause_publication, #set_term_size, #start_publication, #update_term_size
Methods inherited from Interface::Channel
#close, #close_write, #closed?, #write
Methods included from Rex::Post::Channel::StreamAbstraction
Constructor Details
#initialize(websocket) ⇒ SsmChannel
Returns a new instance of SsmChannel.
150 151 152 153 154 155 156 157 158 |
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 150 def initialize(websocket) @ack_seq_num = 0 @out_seq_num = 0 @run_ssm_pub = true @ack_message = nil @publication = false super(websocket, write_type: :binary) end |
Instance Attribute Details
#ack_message ⇒ Object (readonly)
Returns the value of attribute ack_message.
148 149 150 |
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 148 def @ack_message end |
#ack_seq_num ⇒ Object (readonly)
Returns the value of attribute ack_seq_num.
148 149 150 |
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 148 def ack_seq_num @ack_seq_num end |
#out_seq_num ⇒ Object (readonly)
Returns the value of attribute out_seq_num.
148 149 150 |
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 148 def out_seq_num @out_seq_num end |
#run_ssm_pub ⇒ Object (readonly)
Returns the value of attribute run_ssm_pub.
148 149 150 |
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 148 def run_ssm_pub @run_ssm_pub end |
Instance Method Details
#on_data_read(data, _data_type) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 160 def on_data_read(data, _data_type) return data if data.blank? ssm_frame = SsmFrame.read(data) case ssm_frame.header..strip when 'output_stream_data' @publication = true # Linux sends stream data before sending start_publication message return handle_output_data(ssm_frame) when 'acknowledge' # update ACK seqno handle_acknowledge(ssm_frame) when 'start_publication' @out_seq_num = @ack_seq_num if @out_seq_num > 0 @publication = true # handle session resumption - foregrounding or resumption of input when 'pause_publication' # @websocket.put_wsbinary(ssm_frame.to_ack.to_binary_s) @publication = false # handle session suspension - backgrounding or general idle when 'input_stream_data' # this is supposed to be a one way street emsg = "SsmChannel received input_stream_data from SSM (!!)" elog(emsg) raise emsg when 'channel_closed' elog("SsmChannel got closed message #{ssm_frame.uuid}") close else raise Rex::Proto::Http::WebSocket::ConnectionError.new( msg: "Unknown AWS SSM message type: #{ssm_frame.header.}" ) end nil end |
#on_data_write(data) ⇒ Object
196 197 198 199 200 201 202 |
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 196 def on_data_write(data) start_publication if not @publication frame = SsmFrame.create(data) frame.header.sequence_number = @out_seq_num @out_seq_num += 1 frame.to_binary_s end |
#publishing? ⇒ Boolean
204 205 206 |
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 204 def publishing? @publication end |