SMTP
Pentesting SMTP - TCP Ports 25,465,587
Theory
SMTP (Simple Mail Transfer Protocol) is a TCP/IP protocol used for sending e-mail. Default ports are 25 (SMTP), 465 (SMTPS), 587 (SMTPS)
Practice
Enumerate
Commands
We may attempts to use EHLO and HELP commands to gather the Extended commands supported by an SMTP server.
We may list all supported enhanced functions of a SMTP server as follow
root@kali$ telnet example.com 587
220 example.com SMTP Server Banner
>> HELO
250 example.com Hello [x.x.x.x]
>> EHLO all #or EHLO domain.comWe may use the smtp-commands.nse nmap's script
nmap --script smtp-commands -p 25,465,587 <target-ip>Usernames
SMTP supports several interesting commands, such as VRFY, EXPN and RCPT TO.
VRFYrequests asks the server to verify an email address.EXPNasks the server for the membership of a mailing list.RCPT TOis used to specify an email recipient but may trigger an "Unknown user" error if the specified user does not exist.
These can often be abused to verify existing users on a mail server, which is useful information during a penetration test.
smtp-user-enum is a python script for user enumeration via VRFY, EXPN and RCPT
We may use the smtp-enum-users.nse nmap's script
We can use the VRFY command to enumerate users as follow
We can use the EXPN command to enumerate users as follow
We can use the RCPT TO command to enumerate users as follow
NTLM Auth - Information disclosure
If the server supports NTLM auth (Windows) you can obtain sensitive info (versions). More information here.
We may leak sensitive information as follow
We may use the smtp-ntlm-info.nse nmap's script
Connect
We may use following command to connect to a SMTP
We may use following command to connect to a SMTP server using TLS
Authentication Bruteforce
We may use hydra to bruteforce SMTP accounts on the server
We may use the smtp-brute.nse nmap's script
Send E-mail
swaks is a swiss army knife for SMTP and can be used to send emails from external domain
sendEmail is a lightweight, completely command line based, SMTP email agent.
We may use following python script to send emails
Mail Spoofing
Open Relay
To prevent the sent emails from being filtered by spam filters and not reaching the recipient, the sender can use a relay server that the recipient trusts. Often, administrators haven't overviewed of which IP ranges they have to allow. This results in a misconfiguration of the SMTP server that we will still often find in external and internal penetration tests. Therefore, they allow all IP addresses not to cause errors in the email traffic and thus not to disturb or unintentionally interrupt the communication with potential and current customers:
We may use the smtp-open-relay script to enumerate if a SMTP server is vulnerable to mail relaying.
Tools
MagicSpoofing is a python script that checks & test SPF/DMARC DNS records an tries to spoof a domain with a open relay mail system.
Resources
Last updated
Was this helpful?