diff options
author | Matt Graeber <mattifestation@users.noreply.github.com> | 2016-01-14 12:37:52 -0800 |
---|---|---|
committer | Matt Graeber <mattifestation@users.noreply.github.com> | 2016-01-14 12:37:52 -0800 |
commit | cde9447c5fc0ecd89e80b13ed065c46d1b4dbbb7 (patch) | |
tree | 732abdc56feb27c4531ee76e70fc94168ca490e8 /Tests | |
parent | e83e97d672632ca2253e06c9e00ef427c6f8353c (diff) | |
parent | 9cc65e4a856a062d1f6d63d5412d7f0cd801877d (diff) | |
download | PowerSploit-cde9447c5fc0ecd89e80b13ed065c46d1b4dbbb7.tar.gz PowerSploit-cde9447c5fc0ecd89e80b13ed065c46d1b4dbbb7.zip |
Merge pull request #107 from secabstraction/dev
new Get-Keystrokes
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/Exfiltration.tests.ps1 | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Tests/Exfiltration.tests.ps1 b/Tests/Exfiltration.tests.ps1 new file mode 100644 index 0000000..e4f60d5 --- /dev/null +++ b/Tests/Exfiltration.tests.ps1 @@ -0,0 +1,54 @@ +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" +} |