Class: Rex::Post::Meterpreter::Extensions::Stdapi::AudioOutput::AudioOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/post/meterpreter/extensions/stdapi/audio_output/audio_output.rb

Overview

Play an audio file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ AudioOutput

Returns a new instance of AudioOutput.



19
20
21
# File 'lib/rex/post/meterpreter/extensions/stdapi/audio_output/audio_output.rb', line 19

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



50
51
52
# File 'lib/rex/post/meterpreter/extensions/stdapi/audio_output/audio_output.rb', line 50

def client
  @client
end

Instance Method Details

#play_file(path) ⇒ Object

Upload file and play it



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rex/post/meterpreter/extensions/stdapi/audio_output/audio_output.rb', line 28

def play_file(path)
  raise "Could not read file: #{path}" unless ::File.readable?(path) && ::File.file?(path)

  channel = Channel.create(client, 'audio_output', Rex::Post::Meterpreter::Channels::Pools::StreamPool, CHANNEL_FLAG_SYNCHRONOUS)

  # Read file buffers after buffers and upload
  buf_size = 8 * 1024 * 1024
  src_fd = nil

  begin
    src_fd = ::File.open(path, 'rb')
    src_size = src_fd.stat.size
    while (buf = src_fd.read(buf_size))
      channel.write(buf)
      percent = src_size / src_fd.pos.to_f * 100.0
    end
  ensure src_fd.close unless src_fd.nil?
  end
ensure
  channel.close unless channel.nil?
end

#sessionObject



23
24
25
# File 'lib/rex/post/meterpreter/extensions/stdapi/audio_output/audio_output.rb', line 23

def session
  @client
end