如何获取 Microsoft 365 中的邮箱转发规则
攻击者获得邮箱帐户访问权限后要做的第一件事就是设置邮箱转发规则,允许他们将敏感数据泄露到外部电子邮件地址并将其用于恶意目的。因此,扫描您的环境并查看是否有任何规则处于活动状态并且不是为此类意图而设置的规则非常重要。在本文中,您将了解如何使用 PowerShell 在 Microsoft 365 – Exchange Online 中获取邮箱转发规则。
外部转发是默认禁用在 Microsoft 365 中,您应该保持这种状态。但是,如果由于某些原因需要启用外部转发,您应该创建出站策略并选择被授予转发外部邮件的用户和组。
重要的:创建只有选定的用户和组才能转发外部邮件的出站策略。
Microsoft 365 中提供以下类型的自动转发:
- 用户可以配置收件箱规则,将邮件自动转发给外部发件人
- 管理员可以配置邮箱转发(也称为 SMTP 转发)以自动将邮件转发给外部收件人。管理员可以选择是简单转发邮件,还是在邮箱中保留转发邮件的副本。
连接到 Exchange Online PowerShell
在开始之前,您必须连接到 Exchange Online PowerShell。否则,命令将不起作用。
获取单个用户的邮箱转发规则
获取单个用户的邮箱转发规则。
Get-Mailbox "[email protected]" | Where-Object { ($_.ForwardingAddress -ne $null) -or ($_.ForwardingsmtpAddress -ne $null) } | ft DisplayName, UserPrincipalName, ForwardingAddress, ForwardingSmtpAddress, DeliverToMailboxAndForward
输出将如下所示。
有关的:在 Exchange Server/Microsoft 365 上配置邮箱的电子邮件转发
DisplayName UserPrincipalName ForwardingAddress ForwardingSmtpAddress DeliverToMailboxAndForward
----------- ----------------- ----------------- --------------------- --------------------------
Amanda Morgan [email protected] smtp:[email protected] True
获取所有用户的邮箱转发规则
获取所有用户的邮箱转发规则
Get-Mailbox -ResultSize Unlimited | Where-Object { ($_.ForwardingAddress -ne $null) -or ($_.ForwardingsmtpAddress -ne $null) } | ft DisplayName, UserPrincipalName, ForwardingAddress, ForwardingSmtpAddress, DeliverToMailboxAndForward
输出将显示如下。
DisplayName UserPrincipalName ForwardingAddress ForwardingSmtpAddress DeliverToMailboxAndForward
----------- ----------------- ----------------- --------------------- --------------------------
Amanda Morgan [email protected] smtp:[email protected] True
Phil Peters [email protected] smtp:[email protected] True
SharedMailbox1 [email protected] smtp:[email protected] True
SharedMailbox2 [email protected] smtp:[email protected] False
邮箱转发 PowerShell 报告脚本
最好导出一个邮箱转发规则报告来完成这一切。
要在单独的窗口中获取交互式表中的报告,让我们使用网格视图cmdlet。另外,我们将其导出到文件夹路径中的 CSV 文件C:温度。
# Connect Exchange Online PowerShell
Connect-ExchangeOnline
# Change the export path to your desired location
$exportPath = "C:tempForwardingAddress.csv"
# Retrieve mailboxes with forwarding addresses
$mailboxes = Get-Mailbox -ResultSize Unlimited | Where-Object { $_.ForwardingAddress -ne $null -or $_.ForwardingSmtpAddress -ne $null }
# Select the desired properties for display
$mailboxProperties = $mailboxes | select DisplayName, UserPrincipalName, ForwardingAddress, ForwardingSmtpAddress, DeliverToMailboxAndForward
# Show the results in an Out-GridView
$mailboxProperties | Out-GridView -Title "Mailboxes with Forwarding Addresses"
# Export all the data to a CSV file
$mailboxProperties | Export-Csv -Path $exportPath -NoTypeInformation -Encoding UTF8
Write-Host "Mailbox data has been exported to $exportPath" -ForegroundColor Green
这就是它在单独窗口中的外观。
让我们打开 CSV 文件。
就是这样!
结论
您了解了如何在 Microsoft 365 中使用 PowerShell 获取邮箱转发规则。请始终检查组织中是否存在设置了外部转发的邮箱,如果发现任何可疑活动,请阻止这些帐户。
您喜欢这篇文章吗?您可能还喜欢在 Microsoft 365 中向外部电子邮件添加标签以提高安全性。不要忘记关注我们并分享这篇文章。
