如何獲取 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 中向外部電子郵件添加標籤以提高安全性。不要忘記關注我們並分享這篇文章。
