M365 Business Email Compromise
What Is BEC (Business Email Compromise)?
Attack
Once an attacker gains access to a compromised mailbox, they may further perform actions on objectives like:
Grant permissions to mailboxes
Malicious forwarding rules
Creating new users
OAuth abuse
Disabling audit logging
Abuse of eDiscovery (search for emails and exfiltrate them)
Credential pilfering
Recon on security incident
Example attack flow
Ability to perform these actions depends on the amount of permissions an account has:
Read emails on account
Run eDiscovery search for keywords "salary" or "bonus" in the title.
Create forwarding rule to send emails with "invoice" or "finance keywords to third-party mailbox and mark them as read.
Add "sendas" permission to users (requires admin privs)
Add member to a role i.e. Exchange Administrator (requires admin privs)
Leveraging Graph API for BEC
Some actions require administrative consent:
Adding members to groups
Creating Malicious Inbox Rule
The following rule will forward any email containing finance keywords to be forwarded to a malicious gmail account.
Send post request to:
Body of POST request:
Send an email as another user
Must be an administrative user and assign the "Send on behalf of permission" to the compromised user account. In the below screenshots, Bob Jones will be able to send emails on behalf of Alex Wilber.
Impersonate users with SendAs function.
POST Request: https://graph.microsoft.com/v1.0/me/sendMail
Request body:
Leverage eDiscovery to Search
Navigate to the Purview Compliance portal: https://compliance.microsoft.com/homepage
This will allow you to create a case and search with coniditions through Exchange, Yammer, Teams, SharePoint, OneDrive, etc. Useful for pilfering for credentials or reading contents of emails.
Create a search in eDiscovery and export results.
Detect
What logs are available?
Primary:
UAL
Azure Audit Logs
Sign-Ins
Azure Activity Logs
Message Tracing Logs
Secondary:
Azure AD Provisioning Logs
Azure Resource Logs (needs to be enabled).
Diagnostic Logs
Security Reports
Log Retention:
Audit Logs
7 Days
30 Days
30 Days
Sign In Logs
7 Days
30 Days
30 Days
Unified Audit Logs
30 Days
Up to 1 year depending on retention policy
Up to 1 year depending on retention policy
Best to push these logs into SIEM, Sentinel, or external account to keep evidence.
Emails Accessed
UAL Operations:
MailItemsAccessed: Messages read or accessed (only logged for e5 licenses).
FileAccessed: User accesses file on sharepoint or onedrive.
Find MailItemsAccessed log and input it in explorer or message trace to find specific email.
Ediscovery
UAL Operations:
SearchStarted/SearchCreated: Content search was started
SearchExported: Results were exported
SearchExportDownloaded: Export was downloaded
SearchPreviewed/PreviewItemListed: Previewed search results
SeachRemoved: Search was deleted
CaseAdded/Removed: Case management in eDiscovery.
Admin must give permission to user for them to use eDiscovery.
Microsoft alerts on this activity.
Email Forwarding Rules
UAL Operations:
New-InboxRule - Inbox Rule Created
Set-InboxRule - User modified inbox rule using OWA
UpdateInboxRule - Inbox rule was modified, deleted, created by mailbox owner
Move - Message was moved to another folder
By default, forwarding rules are disabled by Microsoft's "scure by default" principles. Most companies have reenabled this.
Exchange Permission Abuse:
SendOnBehalf and accessing mailboxes require Admin privs.
UAL Operations:
Add-MailboxPermission - Admin assigned FullAccess mailbox permission to user allowing them to read/manage another inbox.
AddFolderPermission/UpdateFolderPermission - Allows user to access a folder and the message/mail within it.
SendAs - Message was sent using SendAs permission
SendOnBehalf - Message sent with SendOnBehalf permission
Message sent to nebula from AlexW (on behlaf of AlexW).
IDs at the end are object IDs for users. Malicious user was granted permissions to SendOnBehalf of another user. Trustee is able to send on behalf of Identity.
BEC Persistence:
Azure Audit Logs Operations:
Requires admin privs to all:
Add member to role - Added a user to an admin role in m365
Add member to group - Added a user to a group in Azure AD
Updated group - Updating property on a group
Add service principal credentials - Adding a secret to a service principal in Azure AD
Mitigate
Proactive Steps
Ensure MFA is enabled on all accounts, if an account is compromised reset the password and token.
Enforce strong password policy.
Forward all M365/Azure logs to a SIEM.
Block any mail forwarding to an external domain
Create alerting rules for permissions being granted to users/forwarding rules being created/new users being created.
Disable Forwarding Rules to Outbound
This is turned off by default.
Last updated