From c7b71a2b32d865d502f562a90d6b928b433a5a8a Mon Sep 17 00:00:00 2001 From: dmohanty-r7 Date: Mon, 5 Jun 2017 10:22:16 -0500 Subject: [PATCH] Seperate concerns of console/mic --- .../meterpreter/extensions/stdapi/mic/mic.rb | 48 ++++++++++++++++++ .../console/command_dispatcher/stdapi/mic.rb | 49 ------------------- 2 files changed, 48 insertions(+), 49 deletions(-) diff --git a/lib/rex/post/meterpreter/extensions/stdapi/mic/mic.rb b/lib/rex/post/meterpreter/extensions/stdapi/mic/mic.rb index ec51def9f8..8767a4f9a9 100644 --- a/lib/rex/post/meterpreter/extensions/stdapi/mic/mic.rb +++ b/lib/rex/post/meterpreter/extensions/stdapi/mic/mic.rb @@ -40,6 +40,54 @@ module Rex request = Packet.create_request('audio_interface_start') request.add_tlv(TLV_TYPE_AUDIO_INTERFACE_NAME, mic) client.send_request(request) + begin + client.mic.mic_start(index) + mic_started = true + ::Timeout.timeout(duration) do + ::File.open(stream_path, 'wb') do |outfd| + numchannels = 1 + sampleratehz = 11025 + bitspersample = 16 + datasize = 2000000000 + subchunk1size = 16 + chunksize = 4 + (8 + subchunk1size) + (8 + datasize) + byterate = sampleratehz * numchannels * bitspersample / 8 + blockalign = numchannels * bitspersample / 8 + + BinData::Int32be.new(0x52494646).write(outfd) # ChunkID: "RIFF" + BinData::Int32le.new(chunksize).write(outfd) # ChunkSize + BinData::Int32be.new(0x57415645).write(outfd) # Format: "WAVE" + BinData::Int32be.new(0x666d7420).write(outfd) # SubChunk1ID: "fmt " + BinData::Int32le.new(16).write(outfd) # SubChunk1Size + BinData::Int16le.new(1).write(outfd) # AudioFormat + BinData::Int16le.new(numchannels).write(outfd) # NumChannels + BinData::Int32le.new(sampleratehz).write(outfd) # SampleRate + BinData::Int32le.new(byterate).write(outfd) # ByteRate + BinData::Int16le.new(blockalign).write(outfd) # BlockAlign + BinData::Int16le.new(bitspersample).write(outfd) # BitsPerSample + BinData::Int32be.new(0x64617461).write(outfd) # SubChunk2ID: "data" + BinData::Int32le.new(datasize).write(outfd) # SubChunk2Size + end + stream_index = 0 + while client do + if play_audio && (stream_index == start_delay) + cmd_listen(stream_path) + end + data = client.mic.mic_get_frame(quality) + if data + ::File.open(stream_path, 'a') do |f| + f.write(data) + end + data = nil + end + stream_index += 1 + sleep 1 + end + end + rescue ::Timeout::Error + ensure + client.mic.mic_stop if mic_started + end true end diff --git a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/mic.rb b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/mic.rb index 8a13a418ea..88a5a3fb3b 100644 --- a/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/mic.rb +++ b/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/mic.rb @@ -64,55 +64,6 @@ module Rex print_status("Audio File: #{stream_path}") print_status("Streaming...") - - begin - client.mic.mic_start(index) - mic_started = true - ::Timeout.timeout(duration) do - ::File.open(stream_path, 'wb') do |outfd| - numchannels = 1 - sampleratehz = 11025 - bitspersample = 16 - datasize = 2000000000 - subchunk1size = 16 - chunksize = 4 + (8 + subchunk1size) + (8 + datasize) - byterate = sampleratehz * numchannels * bitspersample / 8 - blockalign = numchannels * bitspersample / 8 - - BinData::Int32be.new(0x52494646).write(outfd) # ChunkID: "RIFF" - BinData::Int32le.new(chunksize).write(outfd) # ChunkSize - BinData::Int32be.new(0x57415645).write(outfd) # Format: "WAVE" - BinData::Int32be.new(0x666d7420).write(outfd) # SubChunk1ID: "fmt " - BinData::Int32le.new(16).write(outfd) # SubChunk1Size - BinData::Int16le.new(1).write(outfd) # AudioFormat - BinData::Int16le.new(numchannels).write(outfd) # NumChannels - BinData::Int32le.new(sampleratehz).write(outfd) # SampleRate - BinData::Int32le.new(byterate).write(outfd) # ByteRate - BinData::Int16le.new(blockalign).write(outfd) # BlockAlign - BinData::Int16le.new(bitspersample).write(outfd) # BitsPerSample - BinData::Int32be.new(0x64617461).write(outfd) # SubChunk2ID: "data" - BinData::Int32le.new(datasize).write(outfd) # SubChunk2Size - end - stream_index = 0 - while client do - if play_audio && (stream_index == start_delay) - cmd_listen(stream_path) - end - data = client.mic.mic_get_frame(quality) - if data - ::File.open(stream_path, 'a') do |f| - f.write(data) - end - data = nil - end - stream_index += 1 - sleep 1 - end - end - rescue ::Timeout::Error - ensure - client.mic.mic_stop if mic_started - end end def cmd_mic_stop(index=0)