Hi everyone,
Welcome back to another blog post. I completed another cybersecurity project: How to create a simple keylogger. Shout out to my partners Guerline and Simon, who worked with me on this project. Please follow and connect with them on LinkedIn.
Before I begin talking about a project, let's discuss what a keylogger is. A keylogger can be special hardware or software that can record keystrokes as you type on a keyboard. You will be able to see passwords and usernames to various accounts (i.e bank accounts, email, etc), google searches, conversations that can be used to extort money or more information from a target, etc. Cybercriminals create fake websites or send an email embedding the keylogger in a malicious link or in a downloadable attachment known as a phishing attack. Everyone should be aware of what a keylogger is and how to protect yourself or your business against one.
In this project, I will create a python script to create a Keylogger and keylogger.txt to record keystrokes on a text file. I used this script in this video by Josh Madakor and made a video that goes over each line of the keylogger script. Please follow Josh Madakor’s youtube channel because he provides easy cybersecurity projects for aspiring cybersecurity professionals to do to showcase cyber skills on a resume.
I watched the video and got excited to create and run a keylogger. Unfortunately, this script didn’t work for me. I kept getting an error when I ran the script. However, my partner, Guerline, was able to make it work. If you understand the programming language: C# and want to see this keylogger in action. You can see how she did it here. Hopefully, you have better luck than me with this script.
Instead of scratching the project, I decided to look for a python script that was a bit easier to understand. I have taken a couple of python classes, so I was more comfortable with that programming language. I watched this video by Cyberfault. If you need an in-depth video on understanding the python script when creating a keylogger, you can watch this video by Codecademy.
Here are the steps to create a Keylogger for educational purposes only:
- Make sure you have python or IDE installed on your computer.
What is an IDE? An integrated development environment (IDE) is software that programmers used to write code. Examples of IDE are Visual Studio, NetBeans, Eclipse, IntelliJ, etc. You can use any IDE you are comfortable with. In this project, I used atom.io. You can download it here. Because atom.io doesn't have python installed within the application, I installed python on my computer. You can download python here.
2. Install pynput by using the command pip install pynput. You know that pynput is installed seen in the picture below. If pip doesn’t work, then try the command: pip3 install pynput.
We need pynput because it records user input aka keystrokes. Also, pynput contains packages that monitor the keyboard. This is an important feature for the keylogger.
3. Optional: If you are working on a Windows computer, then go to settings. In the search bar, type virus & threat protection. Under Virus & Threat protection, click on manage settings and scroll down until you see exclusions. Under exclusions, click on add or remove exclusions and add. Next, click add exclusions. It will provide a drop-down menu and select folder. Add the folder that contains your folder. This prevents your computer from thinking that the keylogger you created is a threat. Also, it prevents the computer from deleting the file after the keylogger has been executed.
4. After python, atom.io, and pynput were installed on my computer, I copied the python script and created a Keylogger.py file on atom.io. You can find the python script here.
5. I used the command prompt and type the command: python3 keylogger.py. Make sure you are in the folder where your keylogger script is before running this script.
When you run this script, no new window will open indicating that the script is running. Instead, you will see a Keylogger.txt file appear in the directory of your Keylogger python script. This script uses pynput to record the keystrokes on your target’s computer and logs the keystrokes into a text file. You can open the log text file and see every keystroke made on the target computer.
Here are pictures of when I ran the Keylogger script:
The picture below shows the python script that was used to create the keylogger. Basically, this python script is using pynput to record the keystrokes and logging it into text file.
In the picture below, I ran the python script in my command prompt using the command: python3 Keylogger.py. The python script is a file I made using the IDE, atom.io. When you run the command, a keylog.txt file appears logging the keystrokes.
This picture below shows the logs of keystrokes when the keylogger script was active.
Now, you ran the keylogger script and see how dangerous this can be. Hopefully, you are thinking about how to defend yourself against it. Remember, cyberattacks are inevitable. The goal of blue team (defensive cybersecurity) is to prevent cyberattacks to occur in the first place. Blue team does this by system hardening, patch management, IPS/IDS, SIEM alerts,etc to detect and monitor malicious activity.
Here are some ways to prevent keylogger attacks:
- Don’t download any unknown files
- Install antivirus software
- Enable two-factor authentication
- Consider a virtual keyboard
- Use password manager
- Consider voice-to-text conversion software
Resources: https://us.norton.com/internetsecurity-malware-what-is-a-keylogger.html
That is the end of my cybersecurity project. You have learned how to create a keylogger and log the keystrokes into the text file. Thank you for reading my blog post. Don’t forget to follow my page to keep up with my projects and journey into breaking into cybersecurity.