Skip to main content

Python Keylogger

Creating a Keylogger in Python
Introduction :
Keylogging is one of the old school ways but still most affective way to capture the sensitive information from the victim's like credentials ,sensative conversation ,sensive emails etc.
Lets walkthrough from the code and try to build our own keylogger from scratch
You can also checkout some other hacking scripts in python : scripts
Required Libraries
##
ctypes : This library will provide the C compatible data types as well as will allows us calling functions in DDL / shared libraries
pythoncom : This library provide support for the microsoft component object model(COM)
pyHook : This provides the callbacks for global mouse and keyboard events in windows.
win32clipboard : This will help to access the windows clipboard api.

##
We will first call 'GetforegroundWindow()' method which will return the handle to the active window on the desktop .Then we will pass this handle as an arg to the 'GetWindowThreadProcessId()' function to retrieve the windows's process ID.After we will open that process using PID and it will return the process handle and using this handle ,we will find the executable name .Then as a final step we will grab the full text of the window's title bar using 'GetWindowTextA()' function. and then we will print output (like PID ,TITLE etc.) all the value we recieved while calling methods .
##
firstly we will check if the target has changed the window or not and if so ,we will get the new windows name and process information .We will then look at the keystroke which were issued and in case it falls within ASCII range we simply print it out in the 'keystroke' file but if it's a modifier (like CTRL ,SHIFT ,ALT ) we will grab the keyname from event object.Even if the user us performing the copy paste operation we will copy the content from the clipboard and then log it in the file.

##
Let's first create the 'pyHookManager' object and then bind the 'KeyDown' to our user-defined callback function keystroke .Then we will register the PyHook to to hook all the keypresses and continue the execution.
Whenever target user will hit a key on keyboard ,our 'KeyStroke' function is called and with an event object as its arg.

Clone the code from Git Repository : python_keylogger



Checkout some more hacking scripts


SECURING SYSTEM BLUETOOTH ATTACKS STEALING AND SNIFFING ATTACKS KALI LINUX HACKING COMMANDS CHEATSHEET TROJAN AND BACKDOORS DICTIONARY AND BURTEFORCING ATTACKS MAN IN THE MIDDLE ATTACKS
1. Sign & Verify message 1. Bluetooth discovery 1. Stealing saved wifi password from windows 1. Pentesting commands with Kali Linux 1. Command and Control Trojan 1. Dictionary Attack 1. Man in Browser Attack
2. SandBox Detection 2. Bluetooth SDP browsing 2. Sniffing packets 2. Reverse shell in python
3. TCP Proxy 3. Bluetooth OBEX 3. Email Credential sniffers 3. Keylogger
4. Bluetooth RCOMM channel scanner 4. Screenshot with Python
5. Blue Bug Exploit 5. Backdoor with Python
6. Blue Snarf Exploit
7. Bluetooth spoofing
8. Bluetooth sniffing