Class: Rex::Proto::Http::WebSocket::AmazonSsm::SsmFrame

Inherits:
BinData::Record
  • Object
show all
Defined in:
lib/rex/proto/http/web_socket/amazon_ssm.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(data = nil, mtype = 'input_stream_data') ⇒ Object



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 248

def create(data = nil, mtype = 'input_stream_data')
  return data if data.is_a?(SsmFrame)

  frame = SsmFrame.new(header: {
    message_type: mtype,
    created_date: (Time.now.to_f * 1000).to_i,
    message_id: UUID.pack(UUID.rand)
  })
  if !data.nil?
    frame.payload_data   = data
    frame.payload_digest = Digest::SHA256.digest(data)
    frame.payload_length = data.length
    frame.payload_type   = PayloadType::Output
  end
  frame
end

.create_pause_pubObject



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 265

def create_pause_pub
  uuid = UUID.rand
  time = Time.now
  data = JSON.generate({
    MessageType: 'pause_publication',
    SchemaVersion: 1,
    MessageId: uuid,
    CreateData: time.strftime("%Y-%m-%dT%T.%LZ")
  })
  frame = SsmFrame.new( header: {
    message_type: 'pause_publication',
    created_date: (time.to_f * 1000).to_i,
    message_id: UUID.pack(uuid)
  })
  frame.payload_data   = data
  frame.payload_digest = Digest::SHA256.digest(data)
  frame.payload_length = data.length
  frame.payload_type   = 0
  frame
end

.create_start_pubObject



286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 286

def create_start_pub
  data = 'start_publication'
  frame = SsmFrame.new( header: {
    message_type: data,
    created_date: (Time.now.to_f * 1000).to_i,
    message_id: UUID.pack(UUID.rand)
  })
  frame.payload_data   = data
  frame.payload_digest = Digest::SHA256.digest(data)
  frame.payload_length = data.length
  frame.payload_type   = 0
  frame
end

.from_ws_frame(wsframe) ⇒ Object



300
301
302
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 300

def from_ws_frame(wsframe)
  SsmFrame.read(wsframe.payload_data)
end

Instance Method Details

#lengthObject



322
323
324
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 322

def length
  to_binary_s.length
end

#to_ackObject



309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 309

def to_ack
  data = JSON.generate({
    AcknowledgedMessageType: header.message_type.strip,
    AcknowledgedMessageId: uuid,
    AcknowledgedMessageSequenceNumber: header.sequence_number.to_i,
    IsSequentialMessage: true
  })
  ack = SsmFrame.create(data, 'acknowledge')
  ack.header.sequence_number = header.sequence_number
  ack.header.flags = header.flags
  ack
end

#uuidObject



305
306
307
# File 'lib/rex/proto/http/web_socket/amazon_ssm.rb', line 305

def uuid
  UUID.unpack(header.message_id)
end