Class: Rex::Proto::Http::WebSocket::AmazonSsm::Interface::SsmChannel

Inherits:
Interface::Channel show all
Includes:
SsmChannelMethods
Defined in:
lib/rex/proto/http/web_socket/amazon_ssm.rb

Instance Attribute Summary collapse

Attributes included from SsmChannelMethods

#cols, #rows

Attributes inherited from Interface::Channel

#params

Instance Method Summary collapse

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

#read

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_messageObject (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
  @ack_message
end

#ack_seq_numObject (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_numObject (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_pubObject (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.message_type.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.message_type}"
    )
  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

Returns:

  • (Boolean)


204
205
206
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 204

def publishing?
  @publication
end