Key Logger in Python
A keylogger is a software or hardware device that records every keystroke made on a computer or mobile device. The purpose of a keylogger is to monitor and track the user’s activity and capture sensitive information, such as passwords and credit card numbers.
I’ve Created a Key Logger in python here’s its working and technical functionalities. You can check it out on github.
The first part of the code uses the pynput library to record every keystroke made on the computer and store them in a list. The press function is called every time a key is pressed, and the release function is called every time a key is released. The press function appends the pressed key to the list of keys, and if the number of keys in the list reaches 10, the write function is called to write the list of keys to a file. The write function opens a file, loggedkeys.txt, in append mode and writes each key in the list to the file.
The sysinformation function uses the socket and platform libraries to retrieve information about the system, including the hostname, IP address, processor, system type, machine type, and private IP address. This information is written to a file, sysinfo.txt.
The clipboard_info function uses the win32clipboard library to retrieve the contents of the clipboard and write them to a file, clipboard.txt.
The screenshot function uses the PIL library to take a screenshot of the computer and save it to a file, screenshot.png.
Get M Tabarik Asif’s stories in your inbox
Join Medium for free to get updates from this writer.
The upload_files function uses the requests library to upload the files created by the keylogger to a server. The files are uploaded to a specified URL using a POST request, and the response status code is checked to determine if the upload was successful.
The delete_files function deletes the files created by the keylogger to erase any evidence of the keylogger's activity.
I’ve used the the
requeststo send a HTTP request to a server which will uplaod the files to the destination. Here’s the implementation of PHP code for server side. I’ve used XAMPP for this implementation. You can either choose to save files with the same name everytime but it’ll be a problem as the files gets overwritten. The funciton to give unique names for the files uploaded is also present in index.php file, just uncomment that it’ll be ready to go.
We first check if a file has been submitted by checking the $_FILES array. If a file has been submitted, we retrieve its properties such as the file name, temporary location, size, and error status.
Next, we determine the file extension by exploding the file name and retrieving the last element of the resulting array. This gives us the file extension in lowercase which is important for security reasons.
We then check if the file extension is in the list of allowed file types. If it is, we proceed to check if there were any errors during the upload process. If there were no errors, we then check if the file size is within our specified limit of 2 MB (2097152 bytes). If the file size is within the limit, we then specify the destination folder for the file to be uploaded to by concatenating the string upload/with the original file name.
Finally, we use the move_uploaded_file() function to move the uploaded file from its temporary location to the destination folder. If any of the previous checks failed, we display a corresponding error message such as “File size too big” or “File type not allowed”. Printing can be skipped because there will be no response for the python handler
The code provides a basic demonstration of the keylogger is implemented, but it is important to note that creating and using a keylogger without the consent of the user is illegal and unethical. Additionally, this code is meant for educational purposes only and should not be used for malicious purposes.
If you have any questions or suggestions, please don’t hesitate to leave a comment or check out the code on GitHub. Additionally, if you find the code to be helpful, I would greatly appreciate it if you could leave a star on the repository. Finally, you can also connect with me on LinkedIn. Thank you for your support!






