diff --git a/lib/rex/post/meterpreter/extensions/stdapi/audio_output/audio_output.rb b/lib/rex/post/meterpreter/extensions/stdapi/audio_output/audio_output.rb index 9312bbbf7f..81f54a150f 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/audio_output/audio_output.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/audio_output/audio_output.rb @@ -4,52 +4,53 @@ require 'rex/post/meterpreter/channel' require 'rex/post/meterpreter/channels/pools/stream_pool' module Rex - module Post - module Meterpreter - module Extensions - module Stdapi - module AudioOutput +module Post +module Meterpreter +module Extensions +module Stdapi +module AudioOutput - ### - # - # Play an audio file - # - ### - class AudioOutput - def initialize(client) - @client = client - end - - def session - @client - end - - # Upload file and play it - def play_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 - - channel.close() - end - - attr_accessor :client - end - end - end - end - end +### +# +# Play an audio file +# +### +class AudioOutput + def initialize(client) + @client = client end + + def session + @client + end + + # Upload file and play it + def play_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 + + channel.close() + end + + attr_accessor :client +end + +end +end +end +end +end end diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/audio_output.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/audio_output.rb index 41e00d1a22..dcf4991b10 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/audio_output.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/audio_output.rb @@ -3,72 +3,73 @@ require 'rex/post/meterpreter' require 'bindata' module Rex - module Post - module Meterpreter - module Ui +module Post +module Meterpreter +module Ui - ### - # - # Play audio on remote system - # - ### - class Console::CommandDispatcher::Stdapi::AudioOutput - Klass = Console::CommandDispatcher::Stdapi::AudioOutput +### +# +# Play audio on remote system +# +### +class Console::CommandDispatcher::Stdapi::AudioOutput + Klass = Console::CommandDispatcher::Stdapi::AudioOutput - include Console::CommandDispatcher + include Console::CommandDispatcher - # - # List of supported commands. - # - def commands - all = { - 'play' => 'play an audio file on target system, nothing written on disk' - } - reqs = { - 'play' => [] - } + # + # List of supported commands. + # + def commands + all = { + 'play' => 'play an audio file on target system, nothing written on disk' + } + reqs = { + 'play' => [] + } - filter_commands(all, reqs) - end + filter_commands(all, reqs) + end - # - # Name for this dispatcher - # - def name - "Stdapi: Audio Output" - end + # + # Name for this dispatcher + # + def name + 'Stdapi: Audio Output' + end - def cmd_play(*args) - audio_path = nil + def cmd_play(*args) + audio_path = nil - play_start_opts = Rex::Parser::Arguments.new( - "-h" => [ false, "Help Banner" ], - "-f" => [ true, "The audio file path (warning: will be copied to memory)" ] - ) + play_start_opts = Rex::Parser::Arguments.new( + '-h' => [ false, "Help Banner" ], + '-f' => [ true, "The audio file path (warning: will be copied to memory)" ] + ) - play_start_opts.parse(args) do |opt, _idx, val| - case opt - when "-h" - print_line("Usage: audio_play [options]\n") - print_line("Upload file to targets memory and play it from memory") - print_line(play_start_opts.usage) - return - when "-f" - audio_path = val - end - end - - if audio_path == nil - print_line("Please specify a path to an audio file via the '-f' option or use '-h'") - return - end - - print_status("Playing #{audio_path}...") - client.audio_output.play_file(audio_path) - print_status("Done") - end - end + play_start_opts.parse(args) do |opt, _idx, val| + case opt + when '-h' + print_line('Usage: audio_play [options]\n') + print_line('Upload file to targets memory and play it from memory') + print_line(play_start_opts.usage) + return + when '-f' + audio_path = val end end + + if audio_path == nil + print_line('Please specify a path to an audio file via the '-f' option or use '-h'') + return + end + + print_status('Playing #{audio_path}...') + client.audio_output.play_file(audio_path) + print_status('Done') end end + +end +end +end +end