Skip to content

Commit baead02

Browse files
committed
Addressing PR feedback.
Removing the audio_stream_pool.rb class file for now, we can recreate for MS-2749 if we really need one.
1 parent ef1145c commit baead02

File tree

3 files changed

+44
-141
lines changed

3 files changed

+44
-141
lines changed

lib/rex/post/meterpreter/channels/pools/audio_stream_pool.rb

Lines changed: 0 additions & 103 deletions
This file was deleted.

lib/rex/post/meterpreter/extensions/stdapi/mic/mic.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: binary -*-
22

33
require 'rex/post/meterpreter/channel'
4-
require 'rex/post/meterpreter/channels/pools/audio_stream_pool'
4+
require 'rex/post/meterpreter/channels/pools/stream_pool'
55

66
module Rex
77
module Post
@@ -16,8 +16,6 @@ module Mic
1616
#
1717
###
1818
class Mic
19-
include Msf::Post::Common
20-
2119
def initialize(client)
2220
@client = client
2321
end
@@ -30,8 +28,10 @@ def session
3028
def mic_list
3129
response = client.send_request(Packet.create_request('audio_mic_list'))
3230
names = []
33-
response.get_tlvs(TLV_TYPE_AUDIO_INTERFACE_NAME).each do |tlv|
34-
names << tlv.value
31+
if response.result == 0
32+
response.get_tlvs(TLV_TYPE_AUDIO_INTERFACE_NAME).each do |tlv|
33+
names << tlv.value
34+
end
3535
end
3636
names
3737
end
@@ -41,8 +41,9 @@ def mic_start(device_id)
4141
request = Packet.create_request('audio_mic_start')
4242
request.add_tlv(TLV_TYPE_AUDIO_INTERFACE_ID, device_id)
4343
response = client.send_request(request)
44+
return nil unless response.result == 0
4445

45-
channel = Channel.create(client, 'audio_mic', Rex::Post::Meterpreter::Channels::Pools::AudioStreamPool, CHANNEL_FLAG_SYNCHRONOUS)
46+
channel = Channel.create(client, 'audio_mic', Rex::Post::Meterpreter::Channels::Pools::StreamPool, CHANNEL_FLAG_SYNCHRONOUS)
4647
end
4748

4849
# Stop recording from microphone

lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/mic.rb

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def cmd_mic_list
5757
end
5858
end
5959

60-
def audio_file_wave_header(sample_rate_hz, num_channels, bits_per_sample, data_size)
60+
def audio_file_wave_header(sample_rate_hz:, num_channels:, bits_per_sample:, data_size:)
6161
subchunk1_size = 16
6262
chunk_size = 4 + (8 + subchunk1_size) + (8 + data_size)
6363
byte_rate = sample_rate_hz * num_channels * bits_per_sample / 8
@@ -104,17 +104,17 @@ def cmd_mic_start(*args)
104104

105105
mic_start_opts.parse(args) do |opt, _idx, val|
106106
case opt
107-
when "-h"
108-
print_line("Usage: mic_start [options]\n")
109-
print_line("Streams and records audio from the target microphone.")
110-
print_line(mic_start_opts.usage)
111-
return
112-
when "-d"
113-
duration = val.to_i
114-
when "-m"
115-
device_id = val.to_i
116-
when "-s"
117-
saved_audio_path = val
107+
when "-h"
108+
print_line("Usage: mic_start [options]\n")
109+
print_line("Streams and records audio from the target microphone.")
110+
print_line(mic_start_opts.usage)
111+
return
112+
when "-d"
113+
duration = val.to_i
114+
when "-m"
115+
device_id = val.to_i
116+
when "-s"
117+
saved_audio_path = val
118118
end
119119
end
120120

@@ -128,14 +128,19 @@ def cmd_mic_start(*args)
128128
return
129129
end
130130

131+
channel = client.mic.mic_start(device_id)
132+
if channel.nil?
133+
print_error("Mic failed to start streaming.")
134+
return
135+
end
131136
print_status("Saving to audio file: #{saved_audio_path}")
137+
print_status("Streaming started...")
132138
total_data_len = 0
133139
begin
134-
channel = client.mic.mic_start(device_id)
135-
mic_started = true
136-
print_status("Streaming started...")
137140
::File.open(saved_audio_path, 'wb') do |outfile|
138-
audio_file_wave_header(11025, 1, 16, 2000000000).each { |e| e.write(outfile) }
141+
audio_file_wave_header(sample_rate_hz: 11025, num_channels: 1, bits_per_sample: 16, data_size: 2_000_000_000).each {
142+
|e| e.write(outfile)
143+
}
139144
end
140145
::Timeout.timeout(duration) do
141146
while client do
@@ -145,15 +150,15 @@ def cmd_mic_start(*args)
145150
end
146151
rescue ::Timeout::Error
147152
ensure
148-
if mic_started
149-
total_data_len += get_data.call(channel, saved_audio_path)
150-
client.mic.mic_stop
151-
print_status("Streaming stopped.")
152-
# Now that we know the actual length of data, update the file header.
153-
::File.open(saved_audio_path, 'rb+') do |outfile|
154-
outfile.seek(0, ::IO::SEEK_SET)
155-
audio_file_wave_header(11025, 1, 16, total_data_len).each { |e| e.write(outfile) }
156-
end
153+
total_data_len += get_data.call(channel, saved_audio_path)
154+
client.mic.mic_stop
155+
print_status("Streaming stopped.")
156+
# Now that we know the actual length of data, update the file header.
157+
::File.open(saved_audio_path, 'rb+') do |outfile|
158+
outfile.seek(0, ::IO::SEEK_SET)
159+
audio_file_wave_header(sample_rate_hz: 11025, num_channels: 1, bits_per_sample: 16, data_size: total_data_len).each {
160+
|e| e.write(outfile)
161+
}
157162
end
158163
end
159164
end
@@ -168,13 +173,13 @@ def cmd_listen(*args)
168173

169174
listen_opts.parse(args) do |opt, _idx, val|
170175
case opt
171-
when "-h"
172-
print_line("Usage: listen -f <filename>\n")
173-
print_line("Plays saved audio from a file.")
174-
print_line(listen_opts.usage)
175-
return
176-
when "-f"
177-
filename = val
176+
when "-h"
177+
print_line("Usage: listen -f <filename>\n")
178+
print_line("Plays saved audio from a file.")
179+
print_line(listen_opts.usage)
180+
return
181+
when "-f"
182+
filename = val
178183
end
179184
end
180185

0 commit comments

Comments
 (0)