MCADDF

[COLLECT-EMAIL-003]: Mail Search via PowerShell

Metadata

| Attribute | Details | |—|—| | Technique ID | COLLECT-EMAIL-003 | | MITRE ATT&CK v18.1 | Email Collection (T1114) – Remote Email Collection (T1114.002) via Exchange PowerShell / Compliance Search | | Tactic | Collection | | Platforms | M365 (Exchange Online), Exchange 2013–2019 | | Severity | High | | Technique Status | ACTIVE (Search-Mailbox retired in EXO; Compliance Search / Graph API now primary) | | Last Verified | 2024-09-30 | | Affected Versions | Exchange Online; Exchange 2013–2019 (on‑prem Search-Mailbox still supported) | | Patched In | N/A – functionality replaced/redirected in Exchange Online; risk mitigated via RBAC and audit logging | | Environment | M365 | | Author | SERVTEPArtur Pchelnikau |


2. EXECUTIVE SUMMARY

Operational Risk

Compliance Mappings

| Framework | Control / ID | Description | |—|—|—| | CIS Benchmark | M365 / Exchange Online – eDiscovery role minimization | Over‑privileged discovery roles allow bulk search and export of regulated communications. | | DISA STIG | O365 STIG – privileged role management | Inadequate separation of duties around compliance/eDiscovery roles. | | CISA SCuBA | Admin and eDiscovery controls | Weak guardrails around content search and export functions. | | NIST 800-53 | AC-5, AC-6, AU-2, AU-12 | Excessive admin privileges and missing audit/alerting for mass search/export. | | GDPR | Art. 32, Art. 25 | Failure to enforce least privilege and logging when processing personal data via search/export. | | DORA | Art. 9 | Non‑monitored access to historical communications breaches ICT logging and monitoring duties. | | NIS2 | Art. 21 | Insufficient risk‑management around powerful search/export operations on critical communications. | | ISO 27001 | A.5, A.8.12, A.8.16 | Missing controls and monitoring on use of admin/eDiscovery tooling. | | ISO 27005 | Abuse of admin/eDiscovery channels | High‑impact risk scenario where trusted tooling is turned into an exfiltration vector.

3. TECHNICAL PREREQUISITES

Supported Versions:

4. ENVIRONMENTAL RECONNAISSANCE

PowerShell Reconnaissance – Role and Search Discovery

# Connect to Exchange Online
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline

# List high-privilege discovery roles
Get-RoleGroup | Where-Object { $_.Name -like '*Discovery*' -or $_.Name -like '*Compliance*' } |
  Select-Object Name, ManagedBy

# List existing compliance searches
Get-ComplianceSearch | Select-Object Name, Status, ExchangeLocation, ContentMatchQuery

# List recent compliance search actions (including exports)
Get-ComplianceSearchAction | Select-Object Name, Action, Status, Workload

What to Look For:

5. DETAILED EXECUTION METHODS AND THEIRS STEPS

METHOD 1 – Exchange Online Compliance Search and Export

Supported Versions: Exchange Online.

Objective: Define a KQL query and target mailboxes for collection.

Command:

Connect-IPPSSession  # Purview / Compliance PowerShell

New-ComplianceSearch -Name 'HR-Keyword-Scan' `
  -ExchangeLocation 'All' `
  -ContentMatchQuery '"confidential" OR "wire transfer" OR "password"'

Start-ComplianceSearch -Identity 'HR-Keyword-Scan'

Expected Output:

Step 2: Export Search Results

Objective: Stage results for PST export.

Command:

New-ComplianceSearchAction -SearchName 'HR-Keyword-Scan' -Export -ExchangeArchiveFormat PerUserPST

Get-ComplianceSearchAction -SearchName 'HR-Keyword-Scan' -Action Export | fl Name,Status,Results

Expected Output:

OpSec & Evasion:

References & Proofs:

METHOD 2 – On‑Prem Search-Mailbox (Copy to Target Mailbox)

Supported Versions: Exchange 2013–2019 (on‑prem, not Exchange Online).

Step 1: Search and Copy

Objective: Search a source mailbox and copy results to a target mailbox/folder for later export.

Command:

# Example – copy all mail from a user into a discovery mailbox
Search-Mailbox -Identity 'user@corp.local' `
  -TargetMailbox 'DiscoveryMailbox{GUID}' `
  -TargetFolder 'User-Collection' `
  -LogLevel Full

Expected Output:

OpSec & Evasion:

References & Proofs:

6. ATTACK SIMULATION & VERIFICATION

Atomic Red Team

7. TOOLS & COMMANDS REFERENCE

Exchange Online Management

Installation:

Install-Module ExchangeOnlineManagement -Scope CurrentUser
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline

Usage:

Script (One-Liner) – Quick Unified Audit Search for Compliance Actions

Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-7) -EndDate (Get-Date) `
  -Operations New-ComplianceSearch, New-ComplianceSearchAction `
  -ResultSize 5000

8. SPLUNK DETECTION RULES

Rule 1: Suspicious ComplianceSearch and Export Activity

Rule Configuration:

SPL Query:

index=o365 Workload="SecurityComplianceCenter"
| eval op=coalesce(Operation, operation)
| where op IN ("New-ComplianceSearch","New-ComplianceSearchAction")
| stats count AS op_count,
        values(op) AS operations,
        values(UserId) AS users
  by UserId, SearchName
| where op_count >= 2

9. MICROSOFT SENTINEL DETECTION

Query 1: New Compliance Search + Export

KQL Query:

OfficeActivity
| where OfficeWorkload =~ "SecurityComplianceCenter"
| where Operation in ("New-ComplianceSearch","New-ComplianceSearchAction")
| summarize Count = count(), Ops = make_set(Operation) by UserId, SearchName, bin(TimeGenerated, 1h)
| where Count >= 2 and array_length(Ops) == 2

10. WINDOWS EVENT LOG MONITORING

11. SYSMON DETECTION PATTERNS

12. MICROSOFT DEFENDER FOR CLOUD / M365 DEFENDER

13. MICROSOFT PURVIEW (UNIFIED AUDIT LOG)

14. DEFENSIVE MITIGATIONS

15. DETECTION & INCIDENT RESPONSE

Step Phase Technique Description
1 Initial Access Compromised admin or compliance account Entry point.
2 Collection COLLECT-EMAIL-003 – Mail Search via PowerShell Targeted search across many mailboxes.
3 Exfiltration Export PST + download Final data theft.

17. REAL-WORLD EXAMPLES