Update record-mic.ps1

This commit is contained in:
Markus Fleschutz 2021-08-23 15:20:22 +02:00
parent 53d6c54402
commit 13d4bc48e3

View File

@ -6,10 +6,6 @@ Author: Justin Warner (@sixdub)
License: BSD 3-Clause License: BSD 3-Clause
Required Dependencies: None Required Dependencies: None
Optional Dependencies: None Optional Dependencies: None
All credit for PowerSploit functions belongs to the original author and project contributors. Thanks for the awesomeness! See here for more info:
http://www.exploit-monday.com/2012/05/accessing-native-windows-api-in.html
https://github.com/PowerShellMafia/PowerSploit
Thanks to Ed Wilson (Scripting Guy) for the one liner to generate random chars. https://blogs.technet.microsoft.com/heyscriptingguy/2015/11/05/generate-random-letters-with-powershell/
.DESCRIPTION .DESCRIPTION
Get-MicrophoneAudio utilizes the Windows API from winmm.dll to record audio from the microphone and saves the wave file to disk. Get-MicrophoneAudio utilizes the Windows API from winmm.dll to record audio from the microphone and saves the wave file to disk.
.OUTPUTS .OUTPUTS
@ -39,7 +35,6 @@ Records 10 seconds of audio to the path C:\windows\temp\secret.wav using WinMM a
) )
#Get-DelegateType from PowerSploit
function Local:Get-DelegateType function Local:Get-DelegateType
{ {
Param Param
@ -68,7 +63,6 @@ Records 10 seconds of audio to the path C:\windows\temp\secret.wav using WinMM a
Write-Output $TypeBuilder.CreateType() Write-Output $TypeBuilder.CreateType()
} }
#Get-ProcAddress from PowerSploit
function local:Get-ProcAddress function local:Get-ProcAddress
{ {
Param Param
@ -108,7 +102,7 @@ Records 10 seconds of audio to the path C:\windows\temp\secret.wav using WinMM a
$HND = $LoadLibrary.Invoke('winmm.dll') $HND = $LoadLibrary.Invoke('winmm.dll')
if ($HND -eq $null) if ($HND -eq $null)
{ {
Throw 'Failed to aquire handle to winmm.dll' throw 'Failed to aquire handle to winmm.dll'
} }
#Initialize the function call to count devices #Initialize the function call to count devices
@ -117,7 +111,7 @@ Records 10 seconds of audio to the path C:\windows\temp\secret.wav using WinMM a
$waveInGetNumDevsDelegate = Get-DelegateType @() ([Uint32]) $waveInGetNumDevsDelegate = Get-DelegateType @() ([Uint32])
if ($waveInGetNumDevsAddr -eq $null) if ($waveInGetNumDevsAddr -eq $null)
{ {
Throw 'Failed to aquire address to WaveInGetNumDevs' throw 'Failed to aquire address to WaveInGetNumDevs'
} }
$waveInGetNumDevs = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer($waveInGetNumDevsAddr, $waveInGetNumDevsDelegate) $waveInGetNumDevs = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer($waveInGetNumDevsAddr, $waveInGetNumDevsDelegate)
@ -137,11 +131,10 @@ Records 10 seconds of audio to the path C:\windows\temp\secret.wav using WinMM a
$mciGetErrorStringDelegate = Get-DelegateType @([UInt32],[Text.StringBuilder],[UInt32]) ([bool]) $mciGetErrorStringDelegate = Get-DelegateType @([UInt32],[Text.StringBuilder],[UInt32]) ([bool])
if ($mciGetErrorStringAddr -eq $null) if ($mciGetErrorStringAddr -eq $null)
{ {
Throw 'Failed to aquire address to mciGetErrorString' throw 'Failed to aquire address to mciGetErrorString'
} }
$mciGetErrorString = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer($mciGetErrorStringAddr,$mciGetErrorStringDelegate) $mciGetErrorString = [System.Runtime.InteropServices.Marshal]::GetDelegateForFunctionPointer($mciGetErrorStringAddr,$mciGetErrorStringDelegate)
#Get device count
$DeviceCount = $waveInGetNumDevs.Invoke() $DeviceCount = $waveInGetNumDevs.Invoke()
if ($DeviceCount -gt 0) if ($DeviceCount -gt 0)
@ -170,10 +163,9 @@ Records 10 seconds of audio to the path C:\windows\temp\secret.wav using WinMM a
$OutFile = Get-ChildItem -path $path $OutFile = Get-ChildItem -path $path
Write-Output $OutFile Write-Output $OutFile
} }
else else
{ {
Throw 'Failed to enumerate any recording devices' throw 'Failed to enumerate any recording devices'
} }
} }