Code your own keylogger
Keylogger in python for all your malicious intent
If you are a Phisher then you will know the need of a keylogger, and not only for malicious intent but also to monitor people in an organisation and kids it can be of great use. but finding a free version of any software and requirement and all other of this stuff sometimes sucks.
so why not code your own keylogger, it will not be with all those fancy functionalities but will get the job done.
What Is a Keylogger?
Keystroke logging, often referred to as keylogging or keyboard capturing, is the action of recording (logging) the keys struck on a keyboard, typically covertly, so that the person using the keyboard is unaware that their actions are being monitored.
we will code our keylogger in python as python being a versatile and powerful language it is also quite easy and with help of various packages, we don't have to build things from scratch.
If you are new or don't know how to install python on your/ host machine guide below will help you.
So after installing python we need to install a few extra packages which will help in easing out our task.
for that simply open your command prompt and install using pip package manager
pip install logging
This will install the logging package which is intended to provide a standard error logging mechanism in python
pip install pynput
This library allows you to control and monitor input devices.
Now the game begins, fire up your favourite code editor and start typing
That's it the whole keylogger in just 11 lines of code (technically 8) which is also not hard to understand even if you are a noob.
so let's understand it line by line
First we started with import packages which will help us to give a head start as the main purpose of packages is to reuse someone else's code.
we imported logging for log messages and keyboard from pynput which help in storing the key when pressed.
After that, we specified the log directory which helps in determining the location where you want to save the log file. this field is empty now which means the file will be saved in the same location where the code file is.
Next is the basic configuration where we configure the key logger, the basicConfig() method takes three arguments i.e. filename, level and format. respectively for the name of the file, level and date-time format for the logged keys. After this, we have a listener method with keypress function which logs all the keys pressed.
This file should be saved with .pyw extension rather than usual .py
The reason for saving this file with .pyw extension is that it will prevent unnecessary prompt to pop up and the script will keep running in the background logging all the keystrokes pressed.
hence the user is not able to see any running application in the foreground but it is running and can be exposed with task manager.
Note: if any antivirus or windows security is activated on the host machine that it will detect the keylogger and quarantine it.
Well done, you have created a keylogger with just 11 lines of code.
to start the script just double click the .pyw file and the script will start running.
and to stop the script just open up your task manager and stop the process.
Thank you for bearing me till the end, do clap and follow us if you like it.