当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何获取 Microsoft 365 中的邮箱转发规则

作者:精品下载站 日期:2024-12-14 03:33:58 浏览:11 分类:玩电脑

如何获取 Microsoft 365 中的邮箱转发规则


攻击者获得邮箱帐户访问权限后要做的第一件事就是设置邮箱转发规则,允许他们将敏感数据泄露到外部电子邮件地址并将其用于恶意目的。因此,扫描您的环境并查看是否有任何规则处于活动状态并且不是为此类意图而设置的规则非常重要。在本文中,您将了解如何使用 PowerShell 在 Microsoft 365 - Exchange Online 中获取邮箱转发规则。

Microsoft 365 中的外部转发

Microsoft 365 中默认禁用外部转发,您应该保持这种状态。但是,如果由于某些原因需要启用外部转发,您应该创建出站策略并选择被授予转发外部邮件的用户和组。

重要提示:创建只有选定的用户和组才能转发外部邮件的出站策略。

Microsoft 365 中提供以下类型的自动转发:

  • 用户可以配置收件箱规则,将邮件自动转发给外部发件人
  • 管理员可以配置邮箱转发(也称为 SMTP 转发)以自动将邮件转发给外部收件人。管理员可以选择是简单转发邮件,还是在邮箱中保留转发邮件的副本。

连接到 Exchange Online PowerShell

在开始之前,您必须连接到 Exchange Online PowerShell。否则,命令将不起作用。

获取单个用户的邮箱转发规则

获取单个用户的邮箱转发规则。

Get-Mailbox "[email protected]" | Where { ($_.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

获取所有用户的邮箱转发规则

获取所有用户的邮箱转发规则

Get-Mailbox -ResultSize Unlimited | Where { ($_.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 报告脚本

最好导出一个邮箱转发规则报告来完成这一切。

要在单独的窗口中获取交互式表中的报告,请使用 Out-GridView cmdlet。另外,我们将其导出到文件夹路径 C:\temp 中的 CSV 文件。

# Connect Exchange Online PowerShell
Connect-ExchangeOnline

# Change the export path to your desired location
$exportPath = "C:\temp\ForwardingAddress.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

这就是它在单独窗口中的外观。

[玩转系统] 如何获取 Microsoft 365 中的邮箱转发规则

让我们打开 CSV 文件。

[玩转系统] 如何获取 Microsoft 365 中的邮箱转发规则

就是这样!

了解更多:从 Office 365 中的 Alias 发送 »

结论

您了解了如何在 Microsoft 365 中使用 PowerShell 获取邮箱转发规则。请始终检查组织中是否存在设置了外部转发的邮箱,如果发现任何可疑活动,请阻止这些帐户。

您喜欢这篇文章吗?您可能还喜欢在 Microsoft 365 中向外部电子邮件添加标签以提高安全性。不要忘记关注我们并分享这篇文章。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯