Skip to content

Commit 48e7e83

Browse files
pbarry-r7dmohanty-r7
authored andcommitted
Make listen focus on prerecorded items.
1 parent e8468a5 commit 48e7e83

File tree

1 file changed

+27
-14
lines changed
  • lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi

1 file changed

+27
-14
lines changed

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

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def commands
2626
'mic_start' => 'start capturing an audio stream from the target mic',
2727
'mic_stop' => 'stop capturing audio',
2828
'mic_list' => 'list all microphone interfaces',
29-
'listen' => 'listen to streaming audio via audio player'
29+
'listen' => 'listen to a saved audio recording via audio player'
3030
}
3131
reqs = {
3232
'mic_start' => [ 'audio_mic_start' ],
@@ -91,17 +91,14 @@ def audio_file_wave_header(sample_rate_hz, num_channels, bits_per_sample, data_s
9191
end
9292

9393
def cmd_mic_start(*args)
94-
start_delay = 8
9594
device_id = 1
9695
duration = 1800
97-
play_stream = true
9896
saved_audio_path = Rex::Text.rand_text_alpha(8) + ".wav"
9997

10098
mic_start_opts = Rex::Parser::Arguments.new(
10199
"-h" => [ false, "Help Banner" ],
102100
"-d" => [ true, "The stream duration in seconds (Default: 1800)" ], # 30 min
103101
"-m" => [ true, "Microphone device index to record from (1: system default)" ],
104-
"-p" => [ true, "Automatically start a player for the stream (Default: '#{play_stream}')" ],
105102
"-s" => [ true, "The saved audio file path (Default: '#{saved_audio_path}')" ]
106103
)
107104

@@ -116,8 +113,6 @@ def cmd_mic_start(*args)
116113
duration = val.to_i
117114
when "-m"
118115
device_id = val.to_i
119-
when "-p"
120-
play = false if val =~ /^(f|n|0)/i
121116
when "-s"
122117
saved_audio_path = val
123118
end
@@ -142,7 +137,6 @@ def cmd_mic_start(*args)
142137
::File.open(saved_audio_path, 'wb') do |outfd|
143138
audio_file_wave_header(11025, 1, 16, 2000000000).each { |e| e.write(outfd) }
144139
end
145-
stream_index = 0
146140
while client do
147141
Rex::sleep(0.5)
148142
data = channel.read(65536)
@@ -151,10 +145,6 @@ def cmd_mic_start(*args)
151145
f.write(data)
152146
end
153147
data = nil
154-
stream_index += 1
155-
if stream_index == start_delay
156-
cmd_listen(saved_audio_path)
157-
end
158148
end
159149
end
160150
end
@@ -167,9 +157,32 @@ def cmd_mic_start(*args)
167157
end
168158
end
169159

170-
def cmd_listen(saved_audio_path)
171-
#Rex::Compat.open_webrtc_browser("file://#{::File.absolute_path(saved_audio_path)}")
172-
Rex::Compat.play_sound(::File.expand_path(saved_audio_path))
160+
def cmd_listen(*args)
161+
filename = nil
162+
163+
listen_opts = Rex::Parser::Arguments.new(
164+
"-h" => [ false, "Help Banner" ],
165+
"-f" => [ true, "audio filename" ]
166+
)
167+
168+
listen_opts.parse(args) do |opt, _idx, val|
169+
case opt
170+
when "-h"
171+
print_line("Usage: listen -f <filename>\n")
172+
print_line("Plays saved audio from a file.")
173+
print_line(listen_opts.usage)
174+
return
175+
when "-f"
176+
filename = val
177+
end
178+
end
179+
180+
if filename.nil?
181+
print_error("use '-f' option to provide a filename for playback")
182+
return
183+
end
184+
185+
Rex::Compat.play_sound(::File.expand_path(filename))
173186
end
174187

175188
def cmd_mic_stop

0 commit comments

Comments
 (0)