Email Security
Email Security
Welcome to the Email & Email Security module of your Ethical Hacking class! In this session, we'll
delve deep into the intricacies of email communication, understand its components, explore the
protocols that govern it, and examine the security measures that protect it. Through detailed
explanations and live examples, you'll gain a robust understanding of how emails function and how to
secure them against various threats.
Table of Contents
1. Email Basics
o Email Header
o Email Body
o SPAM
2. Email Components
o SMTP
o POP3
o IMAP
o MIME
o SPF
o DKIM
o DMARC
5. Advanced Topics
o Email Encryption
6. Practical Exercises
7. Live Demonstrations
Email Header
Definition: The email header contains metadata about the email, providing essential information about the
sender, recipient, and the path the email has taken.
• BCC (Blind Carbon Copy): Recipients who receive the email without their addresses being visible to
others.
Live Example:
Let's examine a sample email header:
Explanation:
• Return-Path: Indicates the sender's address for bounce messages.
• Received: Shows that the email was sent from mail.example.com to smtp.receiver.com.
• From, To, CC, BCC: Lists the sender and all recipients.
• HTML Content: Richly formatted text with images, links, and styles.
• Attachments: Files like documents, images, or videos sent alongside the email.
Live Example:
Plain Text Email Body:
Hi Bob,
I wanted to update you on the project's progress. We've completed the initial phase and are moving into testing.
Best,
Alice
<html>
<body>
<p>Hi Bob,</p>
<p>I wanted to update you on the <strong>project's progress</strong>. We've completed the initial phase and are moving into
<em>testing</em>.</p>
<p>Best,<br>Alice</p>
</body>
</html>
• Subject: Acts as the email's title, helping recipients understand the purpose at a glance. It should be
concise and relevant.
• CC (Carbon Copy): Used to send copies to secondary recipients who should be informed but are not
directly involved.
Example: Sending an update to your manager (To) and copying your team members (CC).
• BCC (Blind Carbon Copy): Sends copies to recipients without revealing their addresses to others,
maintaining privacy.
Example: Sending a newsletter to multiple subscribers without exposing their email addresses to each other.
SPAM
Definition: Unsolicited and often irrelevant or malicious emails sent in bulk. SPAM can clutter inboxes and pose
security risks through phishing links or malware attachments.
Characteristics of SPAM:
• Generic greetings (e.g., "Dear User")
Live Example:
A SPAM email might look like this:
To: <[email protected]>
Dear User,
We are excited to inform you that you have won $10,000 in our annual lottery. To claim your prize, please click the link below and
provide your banking details.
Best regards,
Lottery Team
Examples:
Live Example:
2. Send the Email: After writing, click "Send" to dispatch the email through Gmail's servers.
Examples:
• Sendmail
• Postfix
• Exim
• Microsoft Exchange
Live Example:
1. MUA Action: You compose and send the email via Gmail's interface.
2. MTA Role: Gmail's MTA (e.g., Google SMTP servers) processes the email and determines the recipient's
mail server.
3. Email Transfer: The email is sent over the internet to the recipient's MTA using SMTP.
Examples:
• Dovecot
• Procmail
• Courier
2. MDA Role: The MDA on the recipient's server (e.g., Dovecot) delivers the email to the recipient's
mailbox.
3. MUA Access: The recipient accesses the email via their MUA (e.g., Outlook).
3. Email Protocols & Their Ports
Email communication relies on specific protocols that define how data is transmitted between servers and clients.
Each protocol has standard ports, with secure (encrypted) and insecure (unencrypted) variants.
Ports:
• Insecure: 25
• Secure:
o 465: SMTPS (SMTP Secure) - Deprecated but still used by some servers.
o 587: Submission port with STARTTLS - Recommended for secure email submission.
Live Example:
Sending an Email via SMTP:
1. Client Action: Your email client (e.g., Thunderbird) connects to the SMTP server (smtp.example.com)
on port 587.
3. Email Transfer: The email is sent securely using STARTTLS to encrypt the connection.
Ports:
• Insecure: 110
• Secure:
Live Example:
Retrieving Emails via POP3:
3. Email Retrieval: Emails are downloaded to your device and removed from the server.
Ports:
• Insecure: 143
• Secure:
3. Email Management: Emails remain on the server, accessible from multiple devices, with actions like
read/unread status synchronized.
Key Features:
• Multipart Messages: Allows emails to contain multiple parts (e.g., text and attachments).
Live Example:
Sending an Email with an Attachment:
2. MIME Encoding: The email client encodes the PDF using Base64 and includes it as a separate MIME
part.
3. Transmission: The email is sent with a multipart/mixed content type, allowing the attachment to be
included alongside the text.
Ports:
• HTTP: 80 (Insecure)
• HTTPS: 443 (Secure) - Encrypts data between the browser and server.
Live Example:
Accessing Gmail via HTTPS:
2. Secure Connection: The browser establishes an encrypted connection over port 443.
3. Email Access: You log in securely and access your emails through the web interface.
4. Email Security & Assurance
With the prevalence of email-based attacks like phishing and spoofing, securing email communication is
paramount. Various protocols and standards help verify the authenticity and integrity of emails.
How It Works:
1. DNS Record: Domain owners publish SPF records in DNS, listing authorized sending IP addresses.
2. Email Sending: When an email is sent, the recipient's server checks the SPF record to verify if the
sender's IP is authorized.
3. Verification: If the IP matches, the email passes SPF; otherwise, it may be marked as suspicious or
rejected.
Live Example:
Setting Up an SPF Record:
1. DNS Entry: Add the following TXT record to your domain's DNS settings:
1. Email Signing: Configure your MTA to sign outgoing emails with the private key.
2. Verification: When a recipient's server receives the email, it uses the public key to verify the signature.
How It Works:
1. DNS Record: Domain owners publish a DMARC policy in DNS specifying actions (none, quarantine,
reject) for emails failing SPF/DKIM checks.
2. Alignment: Ensures that the domain in the "From" header aligns with SPF and DKIM authenticated
domains.
3. Reporting: Receivers send aggregate and forensic reports back to the domain owner.
Live Example:
Setting Up a DMARC Policy:
2. Policy Enforcement: If an email from [email protected] fails SPF and DKIM checks, recipient servers
will reject it based on the DMARC policy.
5. Advanced Topics
Phishing & Spoofing
Phishing:
• Techniques:
Spoofing:
• Definition: Forging email headers to make an email appear as if it originated from a different source.
• Techniques:
o Display Name Spoofing: Altering the display name to appear as a known contact.
Live Example:
Phishing Email Example:
To: <[email protected]>
Dear User,
Our records indicate unusual activity in your account. Please reset your password immediately by clicking the link below:
[Reset Password](http://malicious-link.com/reset)
Thank you,
IT Support Team
Spoofing Detection:
3. Analyze DMARC Policy: See if the email aligns with DMARC requirements.
Email Encryption
Purpose: Protects the content of emails from being read by unauthorized parties during transit.
Types:
• Transport Layer Security (TLS): Encrypts the connection between email servers.
• End-to-End Encryption: Ensures only the sender and recipient can read the email content.
Technologies:
• S/MIME (Secure/Multipurpose Internet Mail Extensions): Uses certificates to encrypt and sign
emails.
• PGP (Pretty Good Privacy): Uses a web of trust and key pairs for encryption and signing.
Live Example:
1. Key Generation: Both sender and recipient generate PGP key pairs.
3. Encrypt Email: Sender encrypts the email content using the recipient's public key.
4. Send Email: The encrypted email is sent and can only be decrypted by the recipient's private key.
6. Practical Exercises
Hands-on exercises reinforce theoretical knowledge. Below are practical tasks to apply what you've learned.
Steps:
2. View Source:
o Gmail: Open the email, click on the three dots (⋮) next to the reply button, and select "Show
original."
o Outlook: Open the email, go to "File" > "Properties," and view the "Internet headers."
4. Determine Authenticity:
Example Analysis:
Interpretation:
Important: Do not perform actual phishing attacks. This exercise is purely for educational purposes in a
controlled environment.
Steps:
o Craft a message that prompts urgent action (e.g., "Update your password immediately").
Objective: Implement email authentication protocols to secure your domain's email communication.
Steps:
2. Set Up SPF:
3. Set Up DKIM:
• Generate a DKIM key pair (public and private keys).
• Configure your MTA to sign outgoing emails with the private key.
4. Set Up DMARC:
• Add a TXT record defining DMARC policies.
5. Verify Configuration:
• Use online tools like MXToolbox or DMARC Analyzer to check DNS records.
Outcome: By completing this exercise, you ensure that your domain's emails are authenticated, reducing the risk
of spoofing and phishing attacks using your domain.
7. Live Demonstrations
Demo 1: Viewing and Interpreting Email Headers
Objective: Learn how to view email headers and interpret authentication results.
Steps:
2. View Headers:
o Outlook: Open the email, go to "File" > "Properties" > "Internet headers."
4. Interpret Results:
Live Analysis:
Suppose you receive an email with the following Authentication-Results:
Interpretation:
• SPF: Passed – the sending IP is authorized.
Objective: Understand how DKIM signatures are generated and added to emails.
Prerequisites:
Steps:
1. Generate DKIM Keys:
o Use a tool like opendkim-genkey.
4. Restart Services:
• Restart OpenDKIM and Postfix to apply changes.
Outcome: The sent email should include a DKIM-Signature header that recipients can verify using your published
public key, ensuring email integrity and authenticity.
8. Conclusion & Assignment
Conclusion
Emails are a fundamental mode of communication but also a significant vector for cyberattacks. Understanding
the components and protocols governing emails is essential for both effective communication and robust security.
By implementing and verifying SPF, DKIM, and DMARC, you can significantly enhance your domain's email
security, protecting both your organization and its users from phishing, spoofing, and other malicious activities.
Assignment
1. Analyze an Email Header:
o Task: Select an email from your inbox and perform a detailed analysis of its header.
o Objectives:
o Task: In a controlled environment, create a mock phishing email targeting a specific scenario
(e.g., password reset).
o Objectives:
o Task: Using a test domain, configure SPF, DKIM, and DMARC records.
o Objectives:
o Objectives:
Note: Ensure that all practical exercises, especially those involving security configurations and simulated attacks,
are performed in a safe and ethical manner, respecting all relevant policies and guidelines.
Feel free to reach out with any questions or clarifications as you work through this module.
Understanding email security is a critical skill in ethical hacking, and your proactive engagement will
contribute significantly to your expertise in the field.
Happy Learning!
Best Regards
Jafar Hasan
Appin Technology Lab, Indore