Skip to content

Commit c7b71a2

Browse files
committed
Seperate concerns of console/mic
1 parent 9ca74d6 commit c7b71a2

File tree

2 files changed

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

2 files changed

+48
-49
lines changed

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,54 @@ def mic_start(mic)
4040
request = Packet.create_request('audio_interface_start')
4141
request.add_tlv(TLV_TYPE_AUDIO_INTERFACE_NAME, mic)
4242
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
4391
true
4492
end
4593

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

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -64,55 +64,6 @@ def cmd_mic_start(index=0, start_delay=4096, play_audio=true)
6464

6565
print_status("Audio File: #{stream_path}")
6666
print_status("Streaming...")
67-
68-
begin
69-
client.mic.mic_start(index)
70-
mic_started = true
71-
::Timeout.timeout(duration) do
72-
::File.open(stream_path, 'wb') do |outfd|
73-
numchannels = 1
74-
sampleratehz = 11025
75-
bitspersample = 16
76-
datasize = 2000000000
77-
subchunk1size = 16
78-
chunksize = 4 + (8 + subchunk1size) + (8 + datasize)
79-
byterate = sampleratehz * numchannels * bitspersample / 8
80-
blockalign = numchannels * bitspersample / 8
81-
82-
BinData::Int32be.new(0x52494646).write(outfd) # ChunkID: "RIFF"
83-
BinData::Int32le.new(chunksize).write(outfd) # ChunkSize
84-
BinData::Int32be.new(0x57415645).write(outfd) # Format: "WAVE"
85-
BinData::Int32be.new(0x666d7420).write(outfd) # SubChunk1ID: "fmt "
86-
BinData::Int32le.new(16).write(outfd) # SubChunk1Size
87-
BinData::Int16le.new(1).write(outfd) # AudioFormat
88-
BinData::Int16le.new(numchannels).write(outfd) # NumChannels
89-
BinData::Int32le.new(sampleratehz).write(outfd) # SampleRate
90-
BinData::Int32le.new(byterate).write(outfd) # ByteRate
91-
BinData::Int16le.new(blockalign).write(outfd) # BlockAlign
92-
BinData::Int16le.new(bitspersample).write(outfd) # BitsPerSample
93-
BinData::Int32be.new(0x64617461).write(outfd) # SubChunk2ID: "data"
94-
BinData::Int32le.new(datasize).write(outfd) # SubChunk2Size
95-
end
96-
stream_index = 0
97-
while client do
98-
if play_audio && (stream_index == start_delay)
99-
cmd_listen(stream_path)
100-
end
101-
data = client.mic.mic_get_frame(quality)
102-
if data
103-
::File.open(stream_path, 'a') do |f|
104-
f.write(data)
105-
end
106-
data = nil
107-
end
108-
stream_index += 1
109-
sleep 1
110-
end
111-
end
112-
rescue ::Timeout::Error
113-
ensure
114-
client.mic.mic_stop if mic_started
115-
end
11667
end
11768

11869
def cmd_mic_stop(index=0)

0 commit comments

Comments
 (0)