Skip to content

Commit bd9c157

Browse files
committed
Bring polling back in
1 parent 3d51301 commit bd9c157

File tree

2 files changed

+55
-63
lines changed
  • lib/rex/post/meterpreter
    • extensions/stdapi/mic
    • ui/console/command_dispatcher/stdapi

2 files changed

+55
-63
lines changed

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

Lines changed: 51 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -36,59 +36,58 @@ def mic_list
3636
end
3737

3838
# Starts recording video from video source of index +cam+
39-
def mic_start(mic)
39+
def mic_start(mic_index=0, start_delay)
4040
request = Packet.create_request('audio_interface_start')
41-
request.add_tlv(TLV_TYPE_AUDIO_INTERFACE_NAME, mic)
42-
channel_id = client.send_request(request)
43-
# begin
44-
# client.mic.mic_start(index)
45-
# mic_started = true
46-
# ::Timeout.timeout(duration) do
47-
# ::File.open(stream_path, 'wb') do |outfd|
48-
# numchannels = 1
49-
# sampleratehz = 11025
50-
# bitspersample = 16
51-
# datasize = 2000000000
52-
# subchunk1size = 16
53-
# chunksize = 4 + (8 + subchunk1size) + (8 + datasize)
54-
# byterate = sampleratehz * numchannels * bitspersample / 8
55-
# blockalign = numchannels * bitspersample / 8
56-
#
57-
# BinData::Int32be.new(0x52494646).write(outfd) # ChunkID: "RIFF"
58-
# BinData::Int32le.new(chunksize).write(outfd) # ChunkSize
59-
# BinData::Int32be.new(0x57415645).write(outfd) # Format: "WAVE"
60-
# BinData::Int32be.new(0x666d7420).write(outfd) # SubChunk1ID: "fmt "
61-
# BinData::Int32le.new(16).write(outfd) # SubChunk1Size
62-
# BinData::Int16le.new(1).write(outfd) # AudioFormat
63-
# BinData::Int16le.new(numchannels).write(outfd) # NumChannels
64-
# BinData::Int32le.new(sampleratehz).write(outfd) # SampleRate
65-
# BinData::Int32le.new(byterate).write(outfd) # ByteRate
66-
# BinData::Int16le.new(blockalign).write(outfd) # BlockAlign
67-
# BinData::Int16le.new(bitspersample).write(outfd) # BitsPerSample
68-
# BinData::Int32be.new(0x64617461).write(outfd) # SubChunk2ID: "data"
69-
# BinData::Int32le.new(datasize).write(outfd) # SubChunk2Size
70-
# end
71-
# stream_index = 0
72-
# while client do
73-
# if play_audio && (stream_index == start_delay)
74-
# cmd_listen(stream_path)
75-
# end
76-
# data = client.mic.mic_get_frame(quality)
77-
# if data
78-
# ::File.open(stream_path, 'a') do |f|
79-
# f.write(data)
80-
# end
81-
# data = nil
82-
# end
83-
# stream_index += 1
84-
# sleep 1
85-
# end
86-
# end
87-
# rescue ::Timeout::Error
88-
# ensure
89-
# client.mic.mic_stop if mic_started
90-
# end
91-
mic_stream(channel_id)
41+
request.add_tlv(TLV_TYPE_AUDIO_INTERFACE_NAME, mic_index)
42+
response = client.send_request(request)
43+
begin
44+
client.mic.mic_start(index)
45+
mic_started = true
46+
::Timeout.timeout(duration) do
47+
::File.open(stream_path, 'wb') do |outfd|
48+
numchannels = 1
49+
sampleratehz = 11025
50+
bitspersample = 16
51+
datasize = 2000000000
52+
subchunk1size = 16
53+
chunksize = 4 + (8 + subchunk1size) + (8 + datasize)
54+
byterate = sampleratehz * numchannels * bitspersample / 8
55+
blockalign = numchannels * bitspersample / 8
56+
57+
BinData::Int32be.new(0x52494646).write(outfd) # ChunkID: "RIFF"
58+
BinData::Int32le.new(chunksize).write(outfd) # ChunkSize
59+
BinData::Int32be.new(0x57415645).write(outfd) # Format: "WAVE"
60+
BinData::Int32be.new(0x666d7420).write(outfd) # SubChunk1ID: "fmt "
61+
BinData::Int32le.new(16).write(outfd) # SubChunk1Size
62+
BinData::Int16le.new(1).write(outfd) # AudioFormat
63+
BinData::Int16le.new(numchannels).write(outfd) # NumChannels
64+
BinData::Int32le.new(sampleratehz).write(outfd) # SampleRate
65+
BinData::Int32le.new(byterate).write(outfd) # ByteRate
66+
BinData::Int16le.new(blockalign).write(outfd) # BlockAlign
67+
BinData::Int16le.new(bitspersample).write(outfd) # BitsPerSample
68+
BinData::Int32be.new(0x64617461).write(outfd) # SubChunk2ID: "data"
69+
BinData::Int32le.new(datasize).write(outfd) # SubChunk2Size
70+
end
71+
stream_index = 0
72+
while client do
73+
if stream_index == start_delay
74+
cmd_listen(stream_path)
75+
end
76+
data = client.mic.mic_get_frame(quality)
77+
if data
78+
::File.open(stream_path, 'a') do |f|
79+
f.write(data)
80+
end
81+
data = nil
82+
end
83+
stream_index += 1
84+
sleep 1
85+
end
86+
end
87+
rescue ::Timeout::Error
88+
ensure
89+
client.mic.mic_stop if mic_started
90+
end
9291
end
9392

9493
def mic_get_frame(quality)
@@ -103,13 +102,6 @@ def mic_stop
103102
true
104103
end
105104

106-
def mic_stream(channel_id)
107-
## Read from channel
108-
@channel = Channel.create(client, 'audio_interface_stream', Rex::Post::Meterpreter::Channel::Stream,
109-
CHANNEL_FLAG_SYNCHRONOUS)
110-
111-
end
112-
113105
attr_accessor :client
114106
end
115107
end

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def cmd_list_audio_interfaces
4949
end
5050
end
5151

52-
def cmd_mic_start(index=0, start_delay=4096, play_audio=true)
52+
def cmd_mic_start(mic_index=0, start_delay=4096)
5353
print_status("Streaming mic audio channel...")
5454

5555
if client.mic.mic_list.length == 0
@@ -65,11 +65,11 @@ def cmd_mic_start(index=0, start_delay=4096, play_audio=true)
6565
print_status("Audio File: #{stream_path}")
6666
print_status("Streaming...")
6767

68-
client.mic.stream
68+
client.mic_start(mic_index, start_delay)
6969
end
7070

71-
def cmd_mic_stop(index=0)
72-
client.mic.mic_stop(index)
71+
def cmd_mic_stop
72+
client.mic.mic_stop
7373
end
7474

7575
def cmd_listen(stream_path)

0 commit comments

Comments
 (0)