Giter Site home page Giter Site logo

chenjj / espoofer Goto Github PK

View Code? Open in Web Editor NEW
1.3K 25.0 235.0 3.98 MB

An email spoofing testing tool that aims to bypass SPF/DKIM/DMARC and forge DKIM signatures.🍻

Home Page: https://www.jianjunchen.com/p/composition-kills.USESEC20.pdf

License: MIT License

Python 100.00%
spoofing-emails spf dkim dmarc smtp phishing-attacks email-spoof phishing spoofing dmarc-bypass

espoofer's Introduction

espoofer

espoofer is an open-source testing tool to bypass SPF, DKIM, and DMARC authentication in email systems. It helps mail server administrators and penetration testers to check whether the target email server and client are vulnerable to email spoofing attacks or can be abused to send spoofing emails.


Figure 1. A case of our spoofing attacks on Gmail (Fixed, Demo video)

Why build this tool?

Email spoofing is a big threat to both individuals and organizations (Yahoo breach, John podesta). To address this problem, modern email services and websites employ authentication protocols -- SPF, DKIM, and DMARC -- to prevent email forgery.

Our latest research shows that the implementation of those protocols suffers a number of security issues, which can be exploited to bypass SPF/DKIM/DMARC protections. Figure 1 demonstrates one of our spoofing attacks to bypass DKIM and DMARC in Gmail. For more technical details, please see our Black Hat USA 2020 talk (with presentation video) or USENIX security 2020 paper.

In this repo, we summarize all test cases we found and integrate them into this tool to help administrators and security-practitioners quickly identify and locate such security issues.

Please use the following citation if you do scentific research (Click me).

Latex version:

@inproceedings{chen-email,
author = {Jianjun Chen and Vern Paxson and Jian Jiang},
title = {Composition Kills: A Case Study of Email Sender Authentication},
booktitle = {29th {USENIX} Security Symposium ({USENIX} Security 20)},
year = {2020},
isbn = {978-1-939133-17-5},
pages = {2183--2199},
url = {https://www.usenix.org/conference/usenixsecurity20/presentation/chen-jianjun},
publisher = {{USENIX} Association},
month = aug,
}

Word version:

Jianjun Chen, Vern Paxson, and Jian Jiang. "Composition kills: A case study of email sender authentication." In 29th USENIX Security Symposium (USENIX Security 20), pp. 2183-2199. 2020.

Installation

  • Download this tool
git clone https://github.com/chenjj/espoofer
  • Install dependencies
sudo pip3 install -r requirements.txt

Python version: Python 3 (>=3.7).

Usage

espoofer has three work modes: server ('s', default mode), client ('c') and manual ('m'). In server mode, espoofer works like a mail server to test validation in receiving services. In client mode, espoofer works as an email client to test validation in sending services. Manual mode is used for debug purposes.


Figure 2. Three types of attackers and their work modes

Server mode

To run espoofer in server mode, you need to have: 1) an IP address (1.2.3.4), which outgoing port 25 is not blocked by the ISP, and 2) a domain (attack.com).

  1. Domain configuration
  • Set DKIM public key for attack.com
selector._domainkey.attacker.com TXT  "v=DKIM1; k=rsa; t=y; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDNjwdrmp/gcbKLaGQfRZk+LJ6XOWuQXkAOa/lI1En4t4sLuWiKiL6hACqMrsKQ8XfgqN76mmx4CHWn2VqVewFh7QTvshGLywWwrAJZdQ4KTlfR/2EwAlrItndijOfr2tpZRgP0nTY6saktkhQdwrk3U0SZmG7U8L9IPj7ZwPKGvQIDAQAB"
  • Set SPF record for attack.com
attack.com TXT "v=spf1 ip4:1.2.3.4 +all"
  1. Configure the tool in config.py
config ={
	"attacker_site": b"attack.com", # attack.com
	"legitimate_site_address": b"[email protected]", # legitimate.com
	"victim_address": b"[email protected]", # [email protected]
	"case_id": b"server_a1", # server_a1
}

You can list find the case_id of all test cases using -l option:

python3 espoofer.py -l
  1. Run the tool to send a spoofing email
python3 espoofer.py

You can change case_id in the config.py or use -id option in the command line to test different cases:

python3 espoofer.py -id server_a1

Client mode

To run epsoofer in client mode, you need to have an account on the target email services. This attack exploits the failure of some email services to perform sufficient validation of emails received from local MUAs. For example, [email protected] tries to impersonate [email protected]

  1. Configure the tool in config.py
config ={
	"legitimate_site_address": b"[email protected]",  
	"victim_address": b"[email protected]", 
	"case_id": b"client_a1",

	"client_mode": {
		"sending_server": ("smtp.gmail.com", 587),  # SMTP sending serve ip and port
		"username": b"[email protected]", # Your account username and password
		"password": b"your_passward_here",
	},
}

You can list find the case_id of all test cases using -l option:

python3 espoofer.py -l

Note: sending_server should be the SMTP sending server address, not the receiving server address.

  1. Run the tool to send a spoofing email
python3 espoofer.py -m c

You can change case_id in the config.py and run it again, or you can use -id option in the command line:

python3 espoofer.py -m c -id client_a1

Manual mode

Here is an example of manual mode:

python3 espoofer.py -m m -helo attack.com -mfrom <[email protected]> -rcptto <[email protected]> -data raw_msg_here -ip 127.0.0.1 -port 25

Screenshots

  1. A brief overview of test cases.

Bugs found with this tool

Welcome to send a pull request to file your bug report here.

Q&A

  1. How do I know if the email has bypassed DMARC authentication successfully?

You can check it in the Authentication-results header in the raw message headers. If the header shows dmarc=pass, it means the email has passed the DMARC authentication.  You can check some demos video here.

  1. Why do emails fail to send?

There are several possible reasons if you fail to send an email: 1) your ISP blocks outgoing emails to port 25 to prevent spam. In this case, you need to ask for permission from the ISP; 2) the IP address is in the spam list of the target email services. In many cases, you resolve the problem here, https://www.spamhaus.org/lookup/ ;  3) some email services check if there is a PTR record for the sending IP, you may also need to set the PTR record to bypass this check; 4) the email cannot pass the format validation of the target email service, you may want to try a different test case.

  1. Why the email goes to the spam folder? Any way to avoid this?

Currently, espoofer focuses on bypassing SPF/DKIM/DMARC authentication and doesn't aim for spam filter bypass. But you could try to use a reputable sending IP address, domain, and benign message content to bypass the spam filter.

  1. Why I send an email successfully but the email didn't show up in either inbox or spam folder?

In our prior experiences, some email services filter suspicious emails silently.

  1. When testing server_a5/a6, why I cannot set specical characters like "(" in the domain?

You will need to set up your own authority DNS server, rather than use third-party DNS hosting services, as some DNS hosting services have restrictions on setting specical characters. See issue.

Credits

Welcome to add more test cases.

espoofer's People

Contributors

chenjj avatar hieronymusma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

espoofer's Issues

No longer working in Gmail

Hi,

Thanks for this tool, however, no longer seems to work with Gmail. It shows that the email is coming from my test Gmail account as opposed to the legitimate_site_address.

Perhaps, I am doing something wrong - can you kindly share a working example script?

I do see this in raw mail: X-Google-Original-From which is the display address I want, but that's not how it was displayed in Gmail. Gmail is actually using the username as the From address in the client_mode config.

Presumably Google fixed the bug?

problem with smtp gmail

After several tests, I find the following error:

530-5.7.0 Authentication Required. Learn more at
530 5.7.0 https://support.google.com/mail/?p=WantAuthError y18-20020a92d0d2000000b002f685e47b47sm428291ila.54 - gsmtp

After doing some research, I realized that Google has disabled the user and password authentication function for less secure applications, according to the following document: https://support.google.com/accounts/answer/6010255?authuser=7&hl=en&authuser=7&visit_id=637998656290115666-696177386&p=less-secure-apps&rd=1

in this regard, I'm not sure if it's possible to achieve this with password alone. You would have to modify the code to convert your application according to Google standards so that it can be authenticated.

in this sense, I don't think it's possible to continue using Gmail's SMTP for testing. I'm going to test SMTP from my own domain to test and see if I can manage to continue using your tool.

One more thing please help.

In last message you told no need to use smtp server if you are in client mode the what should I do exactly.
1st step - clone your tool in termux
2step - change victim address and sender address only.
3rd step - run the tool in client mode. Using cmd - python3 espoofer.py -m c -id client_a1

Are the above steps perfects which I should follow exactly Sam only or I have to edit something more in the tool.
Please help and also once again sorry for irritating by asking questions.

authentication required

I'm getting an error saying authentication required, username and password not accepted for the gmail address, even though the username and password are absolutely correct. Why is this happening?

Server IP blocked via SpamHaus

Hello,

i have a server ip but regardless its blocked by spamhaus by default. Unable to send emails to yahoo.com. Using the server mode. Can you please add a SMTP relay option for the server mode?

python3 espoofer.py -id server_a3
                               ____         
  ___  _________  ____  ____  / __/__  _____
 / _ \/ ___/ __ \/ __ \/ __ \/ /_/ _ \/ ___/
/  __(__  ) /_/ / /_/ / /_/ / __/  __/ /    
\___/____/ .___/\____/\____/_/  \___/_/     
        /_/                                 
    
Start sending emails...
Connecting ('98.136.96.76', 25)
>>> 220 mtaproxy401.free.mail.ne1.yahoo.com ESMTP ready

<<< ehlo 33.gooqle.net

>>> 250-mtaproxy401.free.mail.ne1.yahoo.com
250-PIPELINING
250-SIZE 41943040
250-8BITMIME
250 STARTTLS

<<< mail from: <[email protected]>

>>> 553 5.7.1 [TSS07] Connections will not be accepted from 206.189.235.121, because the ip is in Spamhaus's list; see https://postmaster.verizonmedia.com/error-codes

Spray and pray mode

Hi,

Is it possible to use all of the server or client cases at once ?
I mean its risky, but in some situations it could be handy to test the target server for multiple problems at once.
The problem is that you will have hard time figuring out which mail corresponds to which attack method (case), so maybe automatic tagging in the headers / body could be applied.

Sadly i'm not having the skills to do a PR, so its just an idea.

Thanks for your awesome work and sharing your tool / research with the community.

Kind Regards,
PY

Emails getting bounced.

I have been using this tool and I have a problem I am using smtp2go relay server and whenever I send forged mails through your tool it gets bounced and the victim doesn't recives the forged mail. Please help this problem only occurs only when I enter victim email address of gmail domain for all domain it works only for gmail it don't works please help. It's very important for me.

Running on port 25

Please help me configure port 25 for sending email and setting up an attack server. Thanks!

Email address encoding (A10) to bypass DMARC on Outlook Web

Hi Jianjun :-)
I have tested encoding an extra From address in base64 as shown in Fig 8b of your paper. I have sent the mail to an address whose MX are on M365. Outlook Web always displays the base64 encoded version,
g1
g2

Otherly said, it doesn't decode the extra From address before displaying it.

Here is the syntax I used : bs64([email protected]), [email protected]

I tried both base64 and MIME/base64 encoding, none was displayed as decoded.

Does it still work for you or has it been fixed by Microsoft?

Congrats again for your work and the quality of your paper.
Christophe DARY

Some problems with client_mode and server_mode

Hi bro! I need help a bit.
I tried to run espoofer in client mode, but it didn't work. A screenshot of the error from the terminal is attached.

help___github_____________________--
nastroiki_config

Also I tried to run in server mode but I failed. I don't know where to enter the following commands:

  1. Domain configuration

Set DKIM public key for attack.com

selector._domainkey.attacker.com TXT "v=DKIM1; k=rsa; t=y; p=MIGfMA0GCSqG...
2) Set SPF record for attack.com

attack.com TXT "v=spf1 ip4:1.2.3.4 +all"

cant do

Start sending emails...
Connecting ('209.85.233.27', 25)

220 mx.google.com ESMTP 64si4174903ljf.377 - gsmtp

<<< ehlo 0x01.pw

250-mx.google.com at your service, [62.171.141.54]
250-SIZE 157286400
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8

<<< mail from: <([email protected]>

553-5.1.7 The sender address <([email protected]> is not a valid RFC-5321
553 5.1.7 address. 64si4174903ljf.377 - gsmtp

<<< rcpt to: [email protected]

503 5.5.1 MAIL first. 64si4174903ljf.377 - gsmtp

<<< data

503 5.5.1 MAIL first. 64si4174903ljf.377 - gsmtp

<<< From: [email protected]
To: [email protected]
Subject: A2: empty MAIL FROM address
Date: Sat, 05 Sep 2020 15:01:53 +0000
Content-Type: text/plain; charset="UTF-8"
MIME-Version: 1.0
Message-ID: [email protected]
X-Email-Client: https://github.com/chenjj/espoofer

Hi, this is a test message! Best wishes.

.

502 5.5.1 Unrecognized command. 64si4174903ljf.377 - gsmtp

<<< quit

502 5.5.1 Unrecognized command. 64si4174903ljf.377 - gsmtp

Finished.

it seems that i use wrong encoding... but other apps works great.. can u help me?)

eMail body configuration

First of all thanks to share this for us. I just wonder how can I configure the email message as html. In the "testcases" file I want to add html format mail body. Is it possible to create a mail body path?

Issue with Client mode

I have this issue when i try to set it as a client_a1
client_a1

It connects to the server, but then i got that error.

Recipient email address not printed in mail client

Hi,
In server mode, with all test cases, when email is received by the recipient his email address is not printed (see picture below).
Tested on Gmail, Protonmail, Outlook and the behavior is still the same.
The config.py file is configured as described in the wiki.

image

Error i couldnt solve

Hi, When i run the code on py 3.7 & 3.9 i got this error. I tried to understand and attempt to fix it, but still the same. Do you have any idea, im not good at phyton. I can see you just define that, but seems the import is not working. Can help?

Start sending emails...
Traceback (most recent call last):
File ".\test\espoofer.py", line 160, in
main()
File ".\test\espoofer.py", line 148, in main
exploits_builder = ExploitsBuilder(testcases.test_cases, config)
File "C:\Users\User\AppData\Local\Programs\Python\Python37\test\exploits_builder.py", line 11, in init
self.test_cases = self.fixup_test_case_data(test_cases)
File "C:\Users\User\AppData\Local\Programs\Python\Python37\test\exploits_builder.py", line 27, in fixup_test_case_data
t['data']['subject_header'] = self.config['subject_header']
KeyError: 'data'

detail steps to use tool

can you make any video or pdf including screenshots to install and use this tool.
including all steps need to install this

Wrong SSL version with Orange

Hello,

I am using the espoofer in client mode, by using an Orange account. The SMTP servers details are the following:

"sending_server": ("smtp.orange.fr", 465) #btw 465 is not working so I am using the 587

However, while trying to send an email, I am getting the following error:

Traceback (most recent call last):
  File "espoofer.py", line 161, in <module>
    main()
  File "espoofer.py", line 156, in main
    mail_sender.send_email()
  File "/home/devnet/Projects/spoofing/espoofer/common/mail_sender.py", line 145, in send_email
    self.establish_socket()
  File "/home/devnet/Projects/spoofing/espoofer/common/mail_sender.py", line 54, in establish_socket
    tls_socket = ssl.wrap_socket(client_socket, ssl_version=ssl.PROTOCOL_TLS)
  File "/usr/lib/python3.8/ssl.py", line 1405, in wrap_socket
    return context.wrap_socket(
  File "/usr/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/usr/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1131)

I can't find what SSL/TLS version smtp.orange.fr is using,

Do you have any idea on how to solve this issue?

Bad sequence of commands

Trying the client mode with a local SMTP server, running on port 587 with STARTTLS as optional and I am getting the following error. Any ideas?

Thank you for this project btw!

image

SPF record location

Hi,

shouldn't the SPF be located directly on the domain and not under _spf subdomain?
attack.com TXT "v=spf1 ip4:1.2.3.4 ?all"
instead of
_spf.attack.com TXT "v=spf1 ip4:1.2.3.4 ?all"
??

A6 subject in server_a7 test

Hello,

I noticed that two tests have the A6 subject: the server_a6 and server_a7 tests:

A6: SPF authentication results injection 2
A6: routing address in mailfrom

Is this intended?

How to change postmaster in the spoofed email address in client_a12

Hello last request I am able to spoof emails I am using smtp-relay.gmail.com and when I use the tool in client mode a12 the email is received by victim but the victim receives the email from [email protected] but it should be [email protected] in above address I want to change postmaster. The above domain prajwalextensionsoftware.42web.io is mine but I want to send the spoofed email from [email protected] to the victim [email protected]. please help I don't think anybody can help please I have asked all to help but no one is helping please help me to change the postmaster word.
One more important note you may think how it is client_a12 so I have changed the word server to client in the testcases.py

Is it still working?

Could you confirm if this still works, why it is not working correctly and if it is possible to send the initial configuration.
Thx.

error

Traceback (most recent call last):
  File "C:\Users\Ultimate\Documents\stuff\espoofer\espoofer.py", line 161, in <module>
    main()
  File "C:\Users\Ultimate\Documents\stuff\espoofer\espoofer.py", line 139, in main
    mail_sender.send_email()
  File "C:\Users\Ultimate\Documents\stuff\espoofer\common\mail_sender.py", line 145, in send_email
    self.establish_socket()
  File "C:\Users\Ultimate\Documents\stuff\espoofer\common\mail_sender.py", line 42, in establish_socket
    client_socket.connect(self.mail_server)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

Email is not spoofed.

Please help me victim is receiving the email but it is not spoofed. I have read a issue in which you told not all testcases can bypass and told to try creating your own testcases but i dont know how to create it please can you guide me i have read the slides provided by you but i didn't understood please help me it is most important for me. I hope you will help.

Encryption issue

Why the encryption is not working in server mode?
Very thanks guys, this tool is awesome!
encryption

Problem for by pass gmail in server mode

I bypass few service with your script, but it s not work on gmail. i have this error:

[6.20.7.244] The IP address sending this message does not have a
550-5.7.25 PTR record setup, or the corresponding forward DNS entry does not
550-5.7.25 point to the sending IP. As a policy, Gmail does not accept messages
550-5.7.25 from IPs with missing PTR records. Please visit
550-5.7.25 https://support.google.com/mail/answer/81126#ip-practices for more
550 5.7.25 information. uo38-20020a170907cc2600b0087bda90a805si8503852ejc.488 - gsmtp

HTML in email body

Hey! I'm trying to send HTML in the email body for the last 2 days, but unsuccessfully. I tried it in three many different email clients (like protonmail and tutanota) and the HTML code is not being rendered.

I tried to put the code in the "body" field in the config.py like this: "body": b"<h1>example</h1>"
The mail was sent, but the HTML is not being rendered.

Can someone give me more details on how to do this? I appreciate a lot!
Tks!

Issue, Client mode

Hello,
I have been trying to use the Client mode
for Case 1, I get the email but it is not spoofed. I tried using case 2 and 3, but I keep getting this error:

Client does not have permissions to send as this sender

Do you have any idea how to fix it? Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.