Create keylogger with Python

Tram Ho

In the content of this article, I will introduce step by step to create a keylogger in Python language. But wait to mention that, have you ever heard of keylogger, or what is keylogger? Keylogger is a program that helps us track the keystrokes pressed on the keyboard. It seems a bit confused, to make it easier to understand, for example, if you type anything on the keyboard, Keylogger will track what keys you have typed, then save them to a file, often called logfile, especially dangerous if some sensitive personal information such as your username, password, online payment card information, … have been tracked and saved and then transferred to bad guy’s hand.

Oops! If you have never heard of keylogger, will you feel scared when you know it?

Install the support library

Okay, let’s start on the main part. To create the keylogger, we will use the pinput module, a little introduction to pinput: this is a library that allows users to control and control input devices, in this case we need to control the keyboard to Data control is entered from the keyboard. For a more in-depth look at pinput, you can read more at the homepage . Because it’s not a standard python library, we have to install it

Results received:

Start creating Keylogger

After completing the installation of the required library, we will import the packages and methods in it. To be able to monitor the keyboard, we will use the pynput key and listener method. We will also use the logging module to record keystrokes typed into the file.

Next, set the path where we will save the logfile.

We then call the on_press() function to create a definition for typing and use the key we just typed as a param.

The last thing we need to do is install an instance of Listener and define the on_press () method in it, then connect the instance to the main thread.

OK, got it DONE. Now let’s combine all the steps above, we get the complete code file.

Running the program and trying the keystroke, I received a log file that recorded exactly what I typed

OK, just a few simple steps we can see if this code is run on the machine plus the log file is programmed to send to an address we don’t want, you could be exposed a lot. sensitive information. Good luck

Share the news now

Source : Viblo