<# .SYNOPSIS Microsoft Secure Score Hardening — Exchange Online & Defender for Office 365 (18 Kontrol) .DESCRIPTION Kod Güvenlik Sınıfı : Üretim ortamında uygulanabilir değişiklik (Exchange Online PowerShell) Yetki Gereksinimi : Exchange Administrator + Security Administrator (veya Sertifikalı App-Only) Ön Koşul : ExchangeOnlineManagement v3.9+ (PowerShell 7) Kapsanan Secure Score Maddeleri (Toplam ~+60 Puan): - #5, #7, #22 : Anti-Phishing Impersonated User Protection + Quarantine + Safety Tips - #9 : External Calendar Sharing Disabled (Default Sharing Policy) - #10 : OWA Additional Storage Providers Restricted - #11,#12,#40,#41 : Anti-Spam Default (HighConfidenceSpam/Phish -> Quarantine, 30d, BCL 6) - #13,#24,#42 : Outbound Spam (AutoForwardingMode=Off, NotifyAdmin, BlockUser) - #18, #19 : MailTips Enabled & Unified Mailbox Auditing Enabled - #20 : Outlook Add-Ins Installation Blocked (Default Role Assignment Policy) - #36 : Customer Lockbox Enabled .EXAMPLE pwsh -ExecutionPolicy Bypass -File "D:\Lab\Scripts\01-Apply-SecureScore-EXO-MDO.ps1" -AdminUpn "admin@contoso.onmicrosoft.com" -ProtectedUser "Admin Name;admin@contoso.onmicrosoft.com" #> [CmdletBinding(SupportsShouldProcess = $true)] param( [string]$AdminUpn, [string]$AppId, [string]$CertificateThumbprint, [string]$Organization, [Parameter(Mandatory = $true)] [string]$ProtectedUser, [Parameter(Mandatory = $true)] [string]$NotifyRecipient, [string]$AntiPhishPolicyName = 'MDO-03-AntiPhishing-ZeroTrust' ) $ErrorActionPreference = 'Stop' Import-Module ExchangeOnlineManagement -ErrorAction Stop if ($AppId -and $CertificateThumbprint -and $Organization) { Write-Host "[0/9] Exchange Online sertifikalı (App-Only) oturum açılıyor ($Organization)..." -ForegroundColor Cyan Connect-ExchangeOnline -AppId $AppId -CertificateThumbprint $CertificateThumbprint -Organization $Organization -ShowBanner:$false } elseif ($AdminUpn) { Write-Host "[0/9] Exchange Online etkileşimli oturum açılıyor ($AdminUpn)..." -ForegroundColor Cyan Connect-ExchangeOnline -UserPrincipalName $AdminUpn -ShowBanner:$false } else { throw "AdminUpn veya (AppId + CertificateThumbprint + Organization) parametreleri gereklidir." } # 1. Anti-Phishing Impersonated User Protection & Safety Tips (#5, #7, #21, #22, #23) Write-Host "[1/9] Anti-Phishing ($AntiPhishPolicyName): Impersonated User Protection + Quarantine + Safety Tips..." -ForegroundColor Cyan if ($PSCmdlet.ShouldProcess($AntiPhishPolicyName, "Enable Impersonated User Protection & Safety Tips")) { Set-AntiPhishPolicy -Identity $AntiPhishPolicyName ` -EnableTargetedUserProtection $true ` -TargetedUsersToProtect @($ProtectedUser) ` -TargetedUserProtectionAction Quarantine ` -EnableOrganizationDomainsProtection $true ` -TargetedDomainProtectionAction Quarantine ` -EnableMailboxIntelligence $true ` -EnableMailboxIntelligenceProtection $true ` -MailboxIntelligenceProtectionAction Quarantine ` -EnableSimilarUsersSafetyTips $true ` -EnableSimilarDomainsSafetyTips $true ` -EnableUnusualCharactersSafetyTips $true ` -EnableFirstContactSafetyTips $true ` -PhishThresholdLevel 3 } # 2. External Calendar Sharing Disabled (#9) Write-Host "[2/9] Default Sharing Policy devre dışı bırakılıyor (External Calendar Sharing = Off)..." -ForegroundColor Cyan if ($PSCmdlet.ShouldProcess("Default Sharing Policy", "Disable external calendar sharing")) { Set-SharingPolicy -Identity 'Default Sharing Policy' -Enabled $false } # 3. OWA Additional Storage Providers Restricted (#10) Write-Host "[3/9] OWA harici depolama sağlayıcıları kapatılıyor..." -ForegroundColor Cyan if ($PSCmdlet.ShouldProcess("OwaMailboxPolicy-Default", "Disable AdditionalStorageProvidersAvailable")) { Set-OwaMailboxPolicy -Identity 'OwaMailboxPolicy-Default' -AdditionalStorageProvidersAvailable $false } # 4. Inbound Anti-Spam Default Hardening (#11, #12, #40, #41) Write-Host "[4/9] Inbound Anti-Spam (Default): HighConfidenceSpam/Phish -> Quarantine, 30 gün, BCL <= 6..." -ForegroundColor Cyan if ($PSCmdlet.ShouldProcess("HostedContentFilterPolicy Default", "Harden inbound spam & phish actions")) { Set-HostedContentFilterPolicy -Identity 'Default' ` -HighConfidenceSpamAction Quarantine ` -PhishSpamAction Quarantine ` -HighConfidencePhishAction Quarantine ` -QuarantineRetentionPeriod 30 ` -BulkThreshold 6 } # 5. Outbound Spam Filter Hardening (#13, #24, #42) Write-Host "[5/9] Outbound Spam (Default): AutoForwardingMode=Off, NotifyAdmin, BlockUser..." -ForegroundColor Cyan if ($PSCmdlet.ShouldProcess("HostedOutboundSpamFilterPolicy Default", "Block auto-forwarding & enable outbound notifications")) { Set-HostedOutboundSpamFilterPolicy -Identity 'Default' ` -AutoForwardingMode Off ` -NotifyOutboundSpam $true ` -NotifyOutboundSpamRecipients @($NotifyRecipient) ` -ActionWhenThresholdReached BlockUser } # 6. MailTips Enabled (#18) Write-Host "[6/9] MailTips tüm uç kullanıcılar için etkinleştiriliyor..." -ForegroundColor Cyan if ($PSCmdlet.ShouldProcess("OrganizationConfig", "Enable MailTips")) { Set-OrganizationConfig ` -MailTipsAllTipsEnabled $true ` -MailTipsExternalRecipientsTipsEnabled $true ` -MailTipsGroupMetricsEnabled $true ` -MailTipsLargeAudienceThreshold 25 } # 7. Mailbox Auditing Enabled (#19) Write-Host "[7/9] Posta kutusu denetimi (Mailbox Auditing) kiracı genelinde etkinleştiriliyor..." -ForegroundColor Cyan if ($PSCmdlet.ShouldProcess("OrganizationConfig", "Enable Mailbox Auditing")) { Set-OrganizationConfig -AuditDisabled $false } # 8. Outlook Add-Ins Installation Restricted (#20) Write-Host "[8/9] Default Role Assignment Policy üzerinden kullanıcı Outlook eklentisi kurulumu kapatılıyor..." -ForegroundColor Cyan $addInRoles = @('My Custom Apps', 'My Marketplace Apps', 'My ReadWriteMailbox Apps') foreach ($role in $addInRoles) { $assignment = Get-ManagementRoleAssignment -RoleAssignee 'Default Role Assignment Policy' -Role $role -ErrorAction SilentlyContinue if ($assignment -and $PSCmdlet.ShouldProcess("Default Role Assignment Policy", "Remove role $role")) { $assignment | Remove-ManagementRoleAssignment -Confirm:$false } } # 9. Customer Lockbox Enabled (#36) Write-Host "[9/9] Customer Lockbox etkinleştiriliyor..." -ForegroundColor Cyan if ($PSCmdlet.ShouldProcess("OrganizationConfig", "Enable Customer Lockbox")) { Set-OrganizationConfig -CustomerLockBoxEnabled $true } Write-Host "`n=== CANLI DOĞRULAMA ÖZETİ (SALT OKUNUR) ===" -ForegroundColor Green $ap = Get-AntiPhishPolicy -Identity $AntiPhishPolicyName $sp = Get-SharingPolicy -Identity 'Default Sharing Policy' $owa = Get-OwaMailboxPolicy -Identity 'OwaMailboxPolicy-Default' $hcf = Get-HostedContentFilterPolicy -Identity 'Default' $hos = Get-HostedOutboundSpamFilterPolicy -Identity 'Default' $org = Get-OrganizationConfig $remRoles = (Get-ManagementRoleAssignment -RoleAssignee 'Default Role Assignment Policy' | Where-Object { $_.Role -in $addInRoles }).Role [pscustomobject]@{ AntiPhish_UserProt = "$($ap.EnableTargetedUserProtection) ($($ap.TargetedUserProtectionAction))" AntiPhish_SafetyTips = "$($ap.EnableSimilarUsersSafetyTips)/$($ap.EnableSimilarDomainsSafetyTips)/$($ap.EnableUnusualCharactersSafetyTips)" ExternalCalendarSharing = $sp.Enabled OWA_ExternalStorage = $owa.AdditionalStorageProvidersAvailable Inbound_HighConfSpam_Phish = "$($hcf.HighConfidenceSpamAction)/$($hcf.PhishSpamAction) (BCL:$($hcf.BulkThreshold), Ret:$($hcf.QuarantineRetentionPeriod)d)" Outbound_AutoForwarding = "$($hos.AutoForwardingMode) | Notify:$($hos.NotifyOutboundSpam) | LimitAction:$($hos.ActionWhenThresholdReached)" MailTips_Audit_Lockbox = "MailTips:$($org.MailTipsAllTipsEnabled) | AuditDisabled:$($org.AuditDisabled) | Lockbox:$($org.CustomerLockBoxEnabled)" Remaining_OutlookAddInRoles = if ($remRoles) { $remRoles -join ', ' } else { 'None (Blocked)' } } | Format-List Disconnect-ExchangeOnline -Confirm:$false