Skip to content

Commit e21ae88

Browse files
committed
Update wave file header with actual length.
Fixes MS-2759.
1 parent be56d37 commit e21ae88

File tree

1 file changed

+13
-6
lines changed
  • lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi

1 file changed

+13
-6
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ def cmd_mic_start(*args)
9797
::File.open(file, 'a') do |f|
9898
f.write(data)
9999
end
100-
data = nil
100+
return data.length
101101
end
102+
return 0
102103
end
103104
device_id = 1
104105
duration = 1800
@@ -138,25 +139,31 @@ def cmd_mic_start(*args)
138139
end
139140

140141
print_status("Saving to audio file: #{saved_audio_path}")
142+
total_data_len = 0
141143
begin
142144
channel = client.mic.mic_start(device_id)
143145
mic_started = true
144146
print_status("Streaming started...")
147+
::File.open(saved_audio_path, 'wb') do |outfile|
148+
audio_file_wave_header(11025, 1, 16, 2000000000).each { |e| e.write(outfile) }
149+
end
145150
::Timeout.timeout(duration) do
146-
::File.open(saved_audio_path, 'wb') do |outfd|
147-
audio_file_wave_header(11025, 1, 16, 2000000000).each { |e| e.write(outfd) }
148-
end
149151
while client do
150-
get_data.call(channel, saved_audio_path)
151152
Rex::sleep(0.5)
153+
total_data_len += get_data.call(channel, saved_audio_path)
152154
end
153155
end
154156
rescue ::Timeout::Error
155157
ensure
156158
if mic_started
157-
get_data.call(channel, saved_audio_path)
159+
total_data_len += get_data.call(channel, saved_audio_path)
158160
client.mic.mic_stop
159161
print_status("Streaming stopped.")
162+
# Now that we know the actual length of data, update the file header.
163+
::File.open(saved_audio_path, 'rb+') do |outfile|
164+
outfile.seek(0, ::IO::SEEK_SET)
165+
audio_file_wave_header(11025, 1, 16, total_data_len).each { |e| e.write(outfile) }
166+
end
160167
end
161168
end
162169
end

0 commit comments

Comments
 (0)