aboutsummaryrefslogtreecommitdiff
path: root/Tests/Exfiltration.tests.ps1
blob: ed98f45c524a48d4a3e2650e0f0a262c8b142fd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
Set-StrictMode -Version Latest

$TestScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
$ModuleRoot = Resolve-Path "$TestScriptRoot\.."
$ModuleManifest = "$ModuleRoot\Exfiltration\Exfiltration.psd1"

Remove-Module [E]xfiltration
Import-Module $ModuleManifest -Force -ErrorAction Stop

Describe 'Get-Keystrokes' {
    
    if (Test-Path "$($env:TEMP)\key.log") { Remove-Item -Force "$($env:TEMP)\key.log" }
    $WindowTitle = (Get-Process -Id $PID).MainWindowTitle
    
    $Shell = New-Object -ComObject wscript.shell
    $Shell.AppActivate($WindowTitle)
    
    $KeyLogger = Get-Keystrokes -PassThru
    Start-Sleep -Seconds 1

    $Shell.SendKeys("Pester`b`b`b`b`b`b")
    $KeyLogger.Dispose()

    It 'Should output to file' { Test-Path "$($env:TEMP)\key.log" | Should Be $true }
    
    $KeyObjects = Get-Content -Path "$($env:TEMP)\key.log" | ConvertFrom-Csv

    It 'Should log keystrokes' {
        $FileLength = (Get-Item "$($env:TEMP)\key.log").Length
        $FileLength | Should BeGreaterThan 14
    }

    It 'Should get foreground window title' {
        $KeyObjects[0].WindowTitle | Should Be $WindowTitle
    }

    It 'Should log time of key press' {
        $KeyTime = [DateTime]::Parse($KeyObjects[0].Time)
        $KeyTime.GetType().Name | Should Be 'DateTime'
    }

    It 'Should stop logging after timeout' {
        
        $Timeout = 0.05
        $KeyLogger = Get-Keystrokes -Timeout $Timeout -PassThru
        
        Start-Sleep -Seconds 4

        $KeyLogger.Runspace.RunspaceAvailability | Should Be 'Available'
        $KeyLogger.Dispose()
    }

    Remove-Item -Force "$($env:TEMP)\key.log"
}

Describe "Get-MicrophoneAudio" {

	$RecordPath = "$env:TEMP\test_record.wav"
	$RecordLen = 2
	Context 'Successful Recording' {
		BeforeEach { 
			#Ensure the recording as been removed prior to testing
			Remove-Item -Path $RecordPath -ErrorAction SilentlyContinue
		}

		AfterEach {
			#Remove the recording after testing
			Remove-Item -Path $RecordPath -ErrorAction SilentlyContinue
		}

		It 'should record audio from the microphone and save it to a specified path' {
			$result = Get-MicrophoneAudio -Path $RecordPath -Length $RecordLen
			$result | Should Not BeNullOrEmpty
			$result.Length | Should BeGreaterThan 0
		}

	}

	Context 'Invalid Arguments' {
		It 'should not allow invalid paths to be used' {
			{ Get-MicrophoneAudio -Path "c:\FAKEPATH\yay.wav" -Length RecordLen} | Should Throw
		}
	}

}