name: email-security
description: >-
Email security engineering covering authentication protocols (SPF, DKIM, DMARC, ARC),
secure email gateway configuration, spoofing detection, email encryption (S/MIME, PGP,
TLS enforcement), header forensics, malware detection, DLP policies, compliance auditing,
account compromise detection, archival security, email threat hunting, and security
awareness training. Spans offensive testing, defensive hardening, and incident response
for enterprise email infrastructure.
domain: cybersecurity
subdomain: email-security
tags:
- email-security
- spf
- dkim
- dmarc
- phishing
- email-gateway
- email-encryption
- email-forensics
- dlp
- bec
- email-compliance
- threat-hunting
version: "1.0"
author: defconxt
license: AGPL-3.0
compatibility: Designed for Claude Code, GitHub Copilot, OpenAI Codex, Cursor, Gemini CLI, and any agentskills.io-compatible agent.
metadata:
mitre-attack: ["T1566", "T1566.001", "T1566.002", "T1534", "T1114", "T1048.003"]
frameworks: ["NIST 800-177", "DMARC RFC 7489", "CIS Controls v8"]
Email Security
When to Use
Activate when the operator asks about email authentication (SPF/DKIM/DMARC),
email gateway hardening, phishing detection, email encryption, header analysis,
email-borne malware, DLP for email, compliance auditing, BEC detection, email
archival, email threat hunting, or security awareness programs.
Mode: [MODE: RED] for phishing simulation and email spoofing; [MODE: BLUE] for gateway hardening and detection; [MODE: INCIDENT] for BEC triage and header forensics; [MODE: ARCHITECT] for email infrastructure design.
Prerequisites
- DNS query tools (
dig, nslookup, host) for SPF/DKIM/DMARC validation
- Email header access (raw message source) for forensic analysis
- Administrative access to email gateway (Exchange, M365, Google Workspace)
- SMTP testing tools (
swaks, openssl s_client) for protocol testing
Quick Reference
| Control |
Command / Technique |
Framework |
| SPF check |
dig TXT domain.com | grep spf |
NIST 800-177 |
| DKIM verify |
opendkim-testkey -d domain.com -s selector -vvv |
RFC 6376 |
| DMARC lookup |
dig TXT _dmarc.domain.com |
RFC 7489 |
| SMTP TLS test |
openssl s_client -starttls smtp -connect mx.domain.com:25 |
RFC 3207 |
| Header trace |
swaks --to test@domain.com --from test@spoof.com |
— |
| Phishing test |
gophish campaign deployment |
NIST 800-50 |
| BEC detection |
Authentication-Results header analysis |
CIS 9.2 |
| Email DLP |
Transport rule with sensitive info types |
CIS 13.4 |
Workflow
1. Email Authentication Assessment
# SPF record validation
dig TXT example.com | grep "v=spf1"
# DKIM selector discovery and validation
dig TXT selector1._domainkey.example.com
dig TXT selector2._domainkey.example.com
# DMARC policy check
dig TXT _dmarc.example.com
# MTA-STS policy verification
curl -s https://mta-sts.example.com/.well-known/mta-sts.txt
# DANE/TLSA record check
dig TLSA _25._tcp.mx.example.com
# ARC chain validation (for forwarding scenarios)
# Check ARC-Seal, ARC-Message-Signature, ARC-Authentication-Results headers
2. Email Gateway Security Audit
# Test SMTP STARTTLS support
openssl s_client -starttls smtp -connect mx.example.com:25 -brief
# Check for open relay
swaks --to external@test.com --from fake@example.com \
--server mx.example.com --quit-after RCPT
# Test SPF enforcement
swaks --to target@example.com --from spoofed@fakedomain.com \
--server mx.example.com
# Verify TLS certificate
openssl s_client -starttls smtp -connect mx.example.com:25 \
| openssl x509 -noout -subject -dates -issuer
3. Phishing & Spoofing Detection
# Extract Authentication-Results from email headers
grep -E "^(Authentication-Results|Received-SPF|DKIM-Signature|ARC-)" headers.txt
# Check return-path vs from alignment
grep -E "^(From|Return-Path|Reply-To|Envelope-From):" headers.txt
# Analyze received chain for suspicious hops
grep "^Received:" headers.txt | tac
# URL extraction and analysis from email body
grep -oE 'https?://[^"'"'"'> ]+' email_body.txt | sort -u
4. Email-Based Threat Hunting
# Hunt for BEC patterns — sender display name spoofing
# Search for emails where From display name matches executive but address differs
# Hunt for credential harvesting
# Search for emails with links to login pages on non-corporate domains
# Hunt for attachment-based threats
# Search for emails with macro-enabled attachments (.docm, .xlsm, .pptm)
# Hunt for email forwarding rules (persistence)
# M365: Search-UnifiedAuditLog -Operations "New-InboxRule","Set-InboxRule"
5. Email Encryption Verification
# Test S/MIME certificate
openssl x509 -in cert.pem -noout -text | grep -A2 "Key Usage"
# Verify PGP key
gpg --import public.asc
gpg --verify signed_message.asc
# Test mandatory TLS enforcement
swaks --to secure@partner.com --tls-verify --server mx.partner.com
# Check MTA-STS enforcement mode
curl -s https://mta-sts.example.com/.well-known/mta-sts.txt | grep mode
Verification
References
1---2name: email-security3description: <!-- Copyright (c) 2026 defconxt. All rights reserved. -->4---5
6<!-- Copyright (c) 2026 defconxt. All rights reserved. -->
7<!-- Licensed under AGPL-3.0 — see LICENSE file for details. -->
8---
9name: email-security
10description: >-
11 Email security engineering covering authentication protocols (SPF, DKIM, DMARC, ARC),
12 secure email gateway configuration, spoofing detection, email encryption (S/MIME, PGP,
13 TLS enforcement), header forensics, malware detection, DLP policies, compliance auditing,
14 account compromise detection, archival security, email threat hunting, and security
15 awareness training. Spans offensive testing, defensive hardening, and incident response
16 for enterprise email infrastructure.
17domain: cybersecurity
18subdomain: email-security
19tags:
20 - email-security
21 - spf
22 - dkim
23 - dmarc
24 - phishing
25 - email-gateway
26 - email-encryption
27 - email-forensics
28 - dlp
29 - bec
30 - email-compliance
31 - threat-hunting
32version: "1.0"
33author: defconxt
34license: AGPL-3.0
35compatibility: Designed for Claude Code, GitHub Copilot, OpenAI Codex, Cursor, Gemini CLI, and any agentskills.io-compatible agent.
36metadata:
37 mitre-attack: ["T1566", "T1566.001", "T1566.002", "T1534", "T1114", "T1048.003"]
38 frameworks: ["NIST 800-177", "DMARC RFC 7489", "CIS Controls v8"]
39---
40
41# Email Security
42
43## When to Use
44
45Activate when the operator asks about email authentication (SPF/DKIM/DMARC),
46email gateway hardening, phishing detection, email encryption, header analysis,
47email-borne malware, DLP for email, compliance auditing, BEC detection, email
48archival, email threat hunting, or security awareness programs.
49
50Mode: `[MODE: RED]` for phishing simulation and email spoofing; `[MODE: BLUE]` for gateway hardening and detection; `[MODE: INCIDENT]` for BEC triage and header forensics; `[MODE: ARCHITECT]` for email infrastructure design.
51
52## Prerequisites
53
54- DNS query tools (`dig`, `nslookup`, `host`) for SPF/DKIM/DMARC validation
55- Email header access (raw message source) for forensic analysis
56- Administrative access to email gateway (Exchange, M365, Google Workspace)
57- SMTP testing tools (`swaks`, `openssl s_client`) for protocol testing
58
59## Quick Reference
60
61| Control | Command / Technique | Framework |
62|---------|---------------------|-----------|
63| SPF check | `dig TXT domain.com \| grep spf` | NIST 800-177 |
64| DKIM verify | `opendkim-testkey -d domain.com -s selector -vvv` | RFC 6376 |
65| DMARC lookup | `dig TXT _dmarc.domain.com` | RFC 7489 |
66| SMTP TLS test | `openssl s_client -starttls smtp -connect mx.domain.com:25` | RFC 3207 |
67| Header trace | `swaks --to test@domain.com --from test@spoof.com` | — |
68| Phishing test | `gophish` campaign deployment | NIST 800-50 |
69| BEC detection | Authentication-Results header analysis | CIS 9.2 |
70| Email DLP | Transport rule with sensitive info types | CIS 13.4 |
71
72## Workflow
73
74### 1. Email Authentication Assessment
75
76```bash
77# SPF record validation
78dig TXT example.com | grep "v=spf1"
79
80# DKIM selector discovery and validation
81dig TXT selector1._domainkey.example.com
82dig TXT selector2._domainkey.example.com
83
84# DMARC policy check
85dig TXT _dmarc.example.com
86
87# MTA-STS policy verification
88curl -s https://mta-sts.example.com/.well-known/mta-sts.txt
89
90# DANE/TLSA record check
91dig TLSA _25._tcp.mx.example.com
92
93# ARC chain validation (for forwarding scenarios)
94# Check ARC-Seal, ARC-Message-Signature, ARC-Authentication-Results headers
95```
96
97### 2. Email Gateway Security Audit
98
99```bash
100# Test SMTP STARTTLS support
101openssl s_client -starttls smtp -connect mx.example.com:25 -brief
102
103# Check for open relay
104swaks --to external@test.com --from fake@example.com \
105 --server mx.example.com --quit-after RCPT
106
107# Test SPF enforcement
108swaks --to target@example.com --from spoofed@fakedomain.com \
109 --server mx.example.com
110
111# Verify TLS certificate
112openssl s_client -starttls smtp -connect mx.example.com:25 \
113 | openssl x509 -noout -subject -dates -issuer
114```
115
116### 3. Phishing & Spoofing Detection
117
118```bash
119# Extract Authentication-Results from email headers
120grep -E "^(Authentication-Results|Received-SPF|DKIM-Signature|ARC-)" headers.txt
121
122# Check return-path vs from alignment
123grep -E "^(From|Return-Path|Reply-To|Envelope-From):" headers.txt
124
125# Analyze received chain for suspicious hops
126grep "^Received:" headers.txt | tac
127
128# URL extraction and analysis from email body
129grep -oE 'https?://[^"'"'"'> ]+' email_body.txt | sort -u
130```
131
132### 4. Email-Based Threat Hunting
133
134```bash
135# Hunt for BEC patterns — sender display name spoofing
136# Search for emails where From display name matches executive but address differs
137
138# Hunt for credential harvesting
139# Search for emails with links to login pages on non-corporate domains
140
141# Hunt for attachment-based threats
142# Search for emails with macro-enabled attachments (.docm, .xlsm, .pptm)
143
144# Hunt for email forwarding rules (persistence)
145# M365: Search-UnifiedAuditLog -Operations "New-InboxRule","Set-InboxRule"
146```
147
148### 5. Email Encryption Verification
149
150```bash
151# Test S/MIME certificate
152openssl x509 -in cert.pem -noout -text | grep -A2 "Key Usage"
153
154# Verify PGP key
155gpg --import public.asc
156gpg --verify signed_message.asc
157
158# Test mandatory TLS enforcement
159swaks --to secure@partner.com --tls-verify --server mx.partner.com
160
161# Check MTA-STS enforcement mode
162curl -s https://mta-sts.example.com/.well-known/mta-sts.txt | grep mode
163```
164
165## Verification
166
167- [ ] SPF, DKIM, DMARC records validated and aligned
168- [ ] Email gateway enforces TLS and rejects spoofed messages
169- [ ] Phishing simulation campaign executed and metrics collected
170- [ ] Email encryption (TLS/S/MIME/PGP) verified end-to-end
171- [ ] Header forensics workflow tested with sample phishing emails
172- [ ] DLP policies cover sensitive data patterns in email
173- [ ] Compliance audit covers retention, encryption, and access control
174- [ ] BEC detection rules deployed and tested
175- [ ] Email archival integrity and access controls verified
176- [ ] Threat hunting queries deployed for email-based IOCs
177- [ ] Security awareness program metrics tracked
178
179## References
180
181- [NIST SP 800-177 — Trustworthy Email](https://csrc.nist.gov/publications/detail/sp/800-177/rev-1/final)
182- [DMARC RFC 7489](https://datatracker.ietf.org/doc/html/rfc7489)
183- [SPF RFC 7208](https://datatracker.ietf.org/doc/html/rfc7208)
184- [DKIM RFC 6376](https://datatracker.ietf.org/doc/html/rfc6376)
185- [MITRE ATT&CK T1566 — Phishing](https://attack.mitre.org/techniques/T1566/)
186- [CIS Controls v8 — Section 9](https://www.cisecurity.org/controls)