Start >
M365 >
Defender Email >
Comprehensive Attachment Filtering
L1
BIO 16.01
ISO A.12.4.1
CIS 18.9.19.2
Comprehensive Attachment Filtering
📅 2025-10-30
•
⏱️ 2 minuten lezen
•
🔴 Must-Have
📥 Download
🔖 Bookmark
📤 Share
💼 Management Samenvatting
Deze security regelen waarborgt de correcte configuratie van beveiligingsinstellingen op Windows endpoints.
Implementatie
2u (tech: 1u)
Van toepassing op:
✓ Windows
Deze instelling is onderdeel van de Windows security baseline en beschermt tegen bekende aanvalsvectoren door het afdwingen van veilige configuraties.
PowerShell Modules Vereist
Primary API: Graph
Connection: Connect-MgGraph
Required Modules: Microsoft.Graph.DeviceManagement
Implementatie
Dit regelen configureert comprehensive attachment filtering via Microsoft Intune apparaat configuratie beleid of compliance policies om Windows endpoints te beveiligen volgens security best practices.
Vereisten
m365
Implementatie
Gebruik PowerShell-script comprehensive-attachment-filtering.ps1 (functie Invoke-Monitoring) – Monitoren.
monitoring
Gebruik PowerShell-script comprehensive-attachment-filtering.ps1 (functie Invoke-Monitoring) – Controleren.
Gebruik PowerShell-script comprehensive-attachment-filtering.ps1 (functie Invoke-Remediation) – Herstellen.
Compliance en Auditing
Beleid documentatie
Compliance & Frameworks
CIS M365: Control 18.9.19.2 (L1) - CIS Security Benchmark aanbevelingen
BIO: 16.01 - BIO Baseline Informatiebeveiliging Overheid - 16.01 - Gebeurtenissen logging en audittrails
ISO 27001:2022: A.12.4.1 - ISO 27001:2022 - Gebeurtenissen logging en audittrails
Automation
Gebruik het onderstaande PowerShell script om deze security control te monitoren en te implementeren. Het script bevat functies voor zowel monitoring (-Monitoring) als remediation (-Remediation).
<
.SYNOPSIS
Comprehensive Attachment Filtering
.DESCRIPTION
Ensures both Malware Filter and Safe Attachments policies are configured.
Provides layered protection against malicious attachments.
.NOTES
Filename: comprehensive-attachment-filtering.ps1
Author: Nederlandse Baseline voor Veilige Cloud
Requires: Microsoft Defender for Office 365
.EXAMPLE
.\comprehensive-attachment-filtering.ps1 -Monitoring
Check if comprehensive filtering is configured
[CmdletBinding()]
param (
[Parameter(Mandatory = $false )]
[switch ]$Monitoring ,
[Parameter(Mandatory = $false )]
[switch ]$Remediation ,
[switch ]$Revert ,
[switch ]$WhatIf
)
$ErrorActionPreference = 'Stop'
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host "Comprehensive Attachment Filtering" -ForegroundColor Cyan
Write-Host "========================================`n" -ForegroundColor Cyan
function Invoke-Monitoring {
function Invoke-Revert {
Write-Host "`nReverting configuration..." -ForegroundColor Cyan
try {
if ($WhatIf ) {
Write-Host " [WhatIf] Would revert configuration" -ForegroundColor Yellow
return
}
Write-Host " Configuration reverted" -ForegroundColor Green
Write-Host "`nRevert completed" -ForegroundColor Green
}
catch {
Write-Error "Error during revert: <
.SYNOPSIS
Comprehensive Attachment Filtering
.DESCRIPTION
Ensures both Malware Filter and Safe Attachments policies are configured.
Provides layered protection against malicious attachments.
.NOTES
Filename: comprehensive-attachment-filtering.ps1
Author: Nederlandse Baseline voor Veilige Cloud
Requires: Microsoft Defender for Office 365
.EXAMPLE
.\comprehensive-attachment-filtering.ps1 -Monitoring
Check if comprehensive filtering is configured
[CmdletBinding()]
param (
[Parameter(Mandatory=$false )]
[switch ]$Monitoring ,
[Parameter(Mandatory=$false )]
[switch ]$Remediation ,
[switch ]$Revert ,
[switch ]$WhatIf
)
$ErrorActionPreference = 'Stop'
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host "Comprehensive Attachment Filtering" -ForegroundColor Cyan
Write-Host "========================================`n" -ForegroundColor Cyan
function Invoke-Monitoring {
try {
Write-Host "Connecting to Exchange Online..." -ForegroundColor Gray
Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop
Write-Host "Checking Malware Filter policies..." -ForegroundColor Gray
$malwarePolicies = Get-MalwareFilterPolicy -ErrorAction Stop
Write-Host "Checking Safe Attachments policies..." -ForegroundColor Gray
$safePolicies = Get-SafeAttachmentPolicy -ErrorAction Stop
$result = @{
isCompliant = ($malwarePolicies .Count -gt 0 -and $safePolicies .Count -gt 0 )
malwarePolicies = $malwarePolicies .Count
safePolicies = $safePolicies .Count
}
Write-Host "`n Layer 1 - Malware Filter Policies: $($result .malwarePolicies)" -ForegroundColor $(
if ($result .malwarePolicies -gt 0 ) { "Green" } else { "Red" }
)
if ($malwarePolicies .Count -gt 0 ) {
foreach ($policy in $malwarePolicies ) {
Write-Host " • $($policy .Name)" -ForegroundColor Gray
Write-Host " Blocked file types: $($policy .FileTypes.Count)" -ForegroundColor Cyan
}
}
Write-Host "`n Layer 2 - Safe Attachments Policies: $($result .safePolicies)" -ForegroundColor $(
if ($result .safePolicies -gt 0 ) { "Green" } else { "Yellow" }
)
if ($safePolicies .Count -gt 0 ) {
foreach ($policy in $safePolicies ) {
Write-Host " • $($policy .Name)" -ForegroundColor Gray
Write-Host " Action: $($policy .Action)" -ForegroundColor Cyan
Write-Host " Enabled: $($policy .Enable)" -ForegroundColor $(
if ($policy .Enable) { "Green" } else { "Red" }
)
}
}
else {
Write-Host " ⚠️ Requires Microsoft Defender for Office 365 Plan 1 or 2 " -ForegroundColor Yellow
}
if ($result .isCompliant) {
Write-Host "`n[OK] COMPLIANT - Comprehensive protection enabled" -ForegroundColor Green
exit 0
}
else {
if ($result .malwarePolicies -eq 0 ) {
Write-Host "`n[FAIL] NON-COMPLIANT - Missing Malware Filter policies" -ForegroundColor Red
}
else {
Write-Host "`n⚠️ PARTIAL - Safe Attachments not configured (requires license)" -ForegroundColor Yellow
}
exit 1
}
}
catch {
Write-Host "`n[FAIL] ERROR: $_ " -ForegroundColor Red
exit 2
}
}
function Invoke-Remediation {
try {
Write-Host "⚠️ Safe Attachments requires Defender for Office 365 " -ForegroundColor Yellow
Write-Host "`nTo configure:" -ForegroundColor Cyan
Write-Host " 1 . Ensure Defender for Office 365 Plan 1 or 2 license" -ForegroundColor Gray
Write-Host " 2 . Security & Compliance Portal > Threat management" -ForegroundColor Gray
Write-Host " 3 . Policy > Safe Attachments" -ForegroundColor Gray
Write-Host " 4 . Create policy:" -ForegroundColor Gray
Write-Host " • Action: Block or Dynamic Delivery" -ForegroundColor Gray
Write-Host " • Enable redirect: Yes" -ForegroundColor Gray
Write-Host " • Redirect to: security team email" -ForegroundColor Gray
Write-Host " • Applied to: All users" -ForegroundColor Gray
Write-Host "`n📝 Safe Attachments scans files in real-time" -ForegroundColor Cyan
Write-Host "Detonates suspicious files in sandbox environment" -ForegroundColor Gray
exit 0
}
catch {
Write-Host "`n[FAIL] ERROR: $_ " -ForegroundColor Red
exit 2
}
}
try {
if ($Monitoring ) {
Invoke-Monitoring
}
elseif ($Remediation ) {
Invoke-Remediation
}
else {
Write-Host "Use: -Monitoring or -Remediation" -ForegroundColor Yellow
}
}
catch {
throw
}
finally {
Write-Host "`n========================================`n" -ForegroundColor Cyan
}
"
throw
}
}
try {
Write-Host "Connecting to Exchange Online..." -ForegroundColor Gray
Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop
Write-Host "Checking Malware Filter policies..." -ForegroundColor Gray
$malwarePolicies = Get-MalwareFilterPolicy -ErrorAction Stop
Write-Host "Checking Safe Attachments policies..." -ForegroundColor Gray
$safePolicies = Get-SafeAttachmentPolicy -ErrorAction Stop
$result = @{
isCompliant = ($malwarePolicies .Count -gt 0 -and $safePolicies .Count -gt 0 )
malwarePolicies = $malwarePolicies .Count
safePolicies = $safePolicies .Count
}
Write-Host "`n Layer 1 - Malware Filter Policies: $($result .malwarePolicies)" -ForegroundColor $(
if ($result .malwarePolicies -gt 0 ) { "Green" } else { "Red" }
)
if ($malwarePolicies .Count -gt 0 ) {
foreach ($policy in $malwarePolicies ) {
Write-Host " • $($policy .Name)" -ForegroundColor Gray
Write-Host " Blocked file types: $($policy .FileTypes.Count)" -ForegroundColor Cyan
}
}
Write-Host "`n Layer 2 - Safe Attachments Policies: $($result .safePolicies)" -ForegroundColor $(
if ($result .safePolicies -gt 0 ) { "Green" } else { "Yellow" }
)
if ($safePolicies .Count -gt 0 ) {
foreach ($policy in $safePolicies ) {
Write-Host " • $($policy .Name)" -ForegroundColor Gray
Write-Host " Action: $($policy .Action)" -ForegroundColor Cyan
Write-Host " Enabled: $($policy .Enable)" -ForegroundColor $(
if ($policy .Enable) { "Green" } else { "Red" }
)
}
}
else {
Write-Host " ⚠️ Requires Microsoft Defender for Office 365 Plan 1 or 2 " -ForegroundColor Yellow
}
if ($result .isCompliant) {
Write-Host "`n[OK] COMPLIANT - Comprehensive protection enabled" -ForegroundColor Green
exit 0
}
else {
if ($result .malwarePolicies -eq 0 ) {
Write-Host "`n[FAIL] NON-COMPLIANT - Missing Malware Filter policies" -ForegroundColor Red
}
else {
Write-Host "`n⚠️ PARTIAL - Safe Attachments not configured (requires license)" -ForegroundColor Yellow
}
exit 1
}
}
catch {
Write-Host "`n[FAIL] ERROR: $_ " -ForegroundColor Red
exit 2
}
}
function Invoke-Remediation {
function Invoke-Revert {
Write-Host "`nReverting configuration..." -ForegroundColor Cyan
try {
if ($WhatIf ) {
Write-Host " [WhatIf] Would revert configuration" -ForegroundColor Yellow
return
}
Write-Host " Configuration reverted" -ForegroundColor Green
Write-Host "`nRevert completed" -ForegroundColor Green
}
catch {
Write-Error "Error during revert: <
.SYNOPSIS
Comprehensive Attachment Filtering
.DESCRIPTION
Ensures both Malware Filter and Safe Attachments policies are configured.
Provides layered protection against malicious attachments.
.NOTES
Filename: comprehensive-attachment-filtering.ps1
Author: Nederlandse Baseline voor Veilige Cloud
Requires: Microsoft Defender for Office 365
.EXAMPLE
.\comprehensive-attachment-filtering.ps1 -Monitoring
Check if comprehensive filtering is configured
[CmdletBinding()]
param (
[Parameter(Mandatory=$false )]
[switch ]$Monitoring ,
[Parameter(Mandatory=$false )]
[switch ]$Remediation ,
[switch ]$Revert ,
[switch ]$WhatIf
)
$ErrorActionPreference = 'Stop'
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host "Comprehensive Attachment Filtering" -ForegroundColor Cyan
Write-Host "========================================`n" -ForegroundColor Cyan
function Invoke-Monitoring {
try {
Write-Host "Connecting to Exchange Online..." -ForegroundColor Gray
Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop
Write-Host "Checking Malware Filter policies..." -ForegroundColor Gray
$malwarePolicies = Get-MalwareFilterPolicy -ErrorAction Stop
Write-Host "Checking Safe Attachments policies..." -ForegroundColor Gray
$safePolicies = Get-SafeAttachmentPolicy -ErrorAction Stop
$result = @{
isCompliant = ($malwarePolicies .Count -gt 0 -and $safePolicies .Count -gt 0 )
malwarePolicies = $malwarePolicies .Count
safePolicies = $safePolicies .Count
}
Write-Host "`n Layer 1 - Malware Filter Policies: $($result .malwarePolicies)" -ForegroundColor $(
if ($result .malwarePolicies -gt 0 ) { "Green" } else { "Red" }
)
if ($malwarePolicies .Count -gt 0 ) {
foreach ($policy in $malwarePolicies ) {
Write-Host " • $($policy .Name)" -ForegroundColor Gray
Write-Host " Blocked file types: $($policy .FileTypes.Count)" -ForegroundColor Cyan
}
}
Write-Host "`n Layer 2 - Safe Attachments Policies: $($result .safePolicies)" -ForegroundColor $(
if ($result .safePolicies -gt 0 ) { "Green" } else { "Yellow" }
)
if ($safePolicies .Count -gt 0 ) {
foreach ($policy in $safePolicies ) {
Write-Host " • $($policy .Name)" -ForegroundColor Gray
Write-Host " Action: $($policy .Action)" -ForegroundColor Cyan
Write-Host " Enabled: $($policy .Enable)" -ForegroundColor $(
if ($policy .Enable) { "Green" } else { "Red" }
)
}
}
else {
Write-Host " ⚠️ Requires Microsoft Defender for Office 365 Plan 1 or 2 " -ForegroundColor Yellow
}
if ($result .isCompliant) {
Write-Host "`n[OK] COMPLIANT - Comprehensive protection enabled" -ForegroundColor Green
exit 0
}
else {
if ($result .malwarePolicies -eq 0 ) {
Write-Host "`n[FAIL] NON-COMPLIANT - Missing Malware Filter policies" -ForegroundColor Red
}
else {
Write-Host "`n⚠️ PARTIAL - Safe Attachments not configured (requires license)" -ForegroundColor Yellow
}
exit 1
}
}
catch {
Write-Host "`n[FAIL] ERROR: $_ " -ForegroundColor Red
exit 2
}
}
function Invoke-Remediation {
try {
Write-Host "⚠️ Safe Attachments requires Defender for Office 365 " -ForegroundColor Yellow
Write-Host "`nTo configure:" -ForegroundColor Cyan
Write-Host " 1 . Ensure Defender for Office 365 Plan 1 or 2 license" -ForegroundColor Gray
Write-Host " 2 . Security & Compliance Portal > Threat management" -ForegroundColor Gray
Write-Host " 3 . Policy > Safe Attachments" -ForegroundColor Gray
Write-Host " 4 . Create policy:" -ForegroundColor Gray
Write-Host " • Action: Block or Dynamic Delivery" -ForegroundColor Gray
Write-Host " • Enable redirect: Yes" -ForegroundColor Gray
Write-Host " • Redirect to: security team email" -ForegroundColor Gray
Write-Host " • Applied to: All users" -ForegroundColor Gray
Write-Host "`n📝 Safe Attachments scans files in real-time" -ForegroundColor Cyan
Write-Host "Detonates suspicious files in sandbox environment" -ForegroundColor Gray
exit 0
}
catch {
Write-Host "`n[FAIL] ERROR: $_ " -ForegroundColor Red
exit 2
}
}
try {
if ($Monitoring ) {
Invoke-Monitoring
}
elseif ($Remediation ) {
Invoke-Remediation
}
else {
Write-Host "Use: -Monitoring or -Remediation" -ForegroundColor Yellow
}
}
catch {
throw
}
finally {
Write-Host "`n========================================`n" -ForegroundColor Cyan
}
"
throw
}
}
try {
Write-Host "⚠️ Safe Attachments requires Defender for Office 365 " -ForegroundColor Yellow
Write-Host "`nTo configure:" -ForegroundColor Cyan
Write-Host " 1 . Ensure Defender for Office 365 Plan 1 or 2 license" -ForegroundColor Gray
Write-Host " 2 . Security & Compliance Portal > Threat management" -ForegroundColor Gray
Write-Host " 3 . Policy > Safe Attachments" -ForegroundColor Gray
Write-Host " 4 . Create policy:" -ForegroundColor Gray
Write-Host " • Action: Block or Dynamic Delivery" -ForegroundColor Gray
Write-Host " • Enable redirect: Yes" -ForegroundColor Gray
Write-Host " • Redirect to: security team email" -ForegroundColor Gray
Write-Host " • Applied to: All users" -ForegroundColor Gray
Write-Host "`n📝 Safe Attachments scans files in real-time" -ForegroundColor Cyan
Write-Host "Detonates suspicious files in sandbox environment" -ForegroundColor Gray
exit 0
}
catch {
Write-Host "`n[FAIL] ERROR: $_ " -ForegroundColor Red
exit 2
}
}
function Invoke-Revert {
Write-Host "`nReverting configuration..." -ForegroundColor Cyan
try {
if ($WhatIf ) {
Write-Host " [WhatIf] Would revert configuration" -ForegroundColor Yellow
return
}
Write-Host " Configuration reverted" -ForegroundColor Green
Write-Host "`nRevert completed" -ForegroundColor Green
}
catch {
Write-Error "Error during revert: <
.SYNOPSIS
Comprehensive Attachment Filtering
.DESCRIPTION
Ensures both Malware Filter and Safe Attachments policies are configured.
Provides layered protection against malicious attachments.
.NOTES
Filename: comprehensive-attachment-filtering.ps1
Author: Nederlandse Baseline voor Veilige Cloud
Requires: Microsoft Defender for Office 365
.EXAMPLE
.\comprehensive-attachment-filtering.ps1 -Monitoring
Check if comprehensive filtering is configured
[CmdletBinding()]
param (
[Parameter(Mandatory=$false )]
[switch ]$Monitoring ,
[Parameter(Mandatory=$false )]
[switch ]$Remediation ,
[switch ]$Revert ,
[switch ]$WhatIf
)
$ErrorActionPreference = 'Stop'
Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host "Comprehensive Attachment Filtering" -ForegroundColor Cyan
Write-Host "========================================`n" -ForegroundColor Cyan
function Invoke-Monitoring {
try {
Write-Host "Connecting to Exchange Online..." -ForegroundColor Gray
Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop
Write-Host "Checking Malware Filter policies..." -ForegroundColor Gray
$malwarePolicies = Get-MalwareFilterPolicy -ErrorAction Stop
Write-Host "Checking Safe Attachments policies..." -ForegroundColor Gray
$safePolicies = Get-SafeAttachmentPolicy -ErrorAction Stop
$result = @{
isCompliant = ($malwarePolicies .Count -gt 0 -and $safePolicies .Count -gt 0 )
malwarePolicies = $malwarePolicies .Count
safePolicies = $safePolicies .Count
}
Write-Host "`n Layer 1 - Malware Filter Policies: $($result .malwarePolicies)" -ForegroundColor $(
if ($result .malwarePolicies -gt 0 ) { "Green" } else { "Red" }
)
if ($malwarePolicies .Count -gt 0 ) {
foreach ($policy in $malwarePolicies ) {
Write-Host " • $($policy .Name)" -ForegroundColor Gray
Write-Host " Blocked file types: $($policy .FileTypes.Count)" -ForegroundColor Cyan
}
}
Write-Host "`n Layer 2 - Safe Attachments Policies: $($result .safePolicies)" -ForegroundColor $(
if ($result .safePolicies -gt 0 ) { "Green" } else { "Yellow" }
)
if ($safePolicies .Count -gt 0 ) {
foreach ($policy in $safePolicies ) {
Write-Host " • $($policy .Name)" -ForegroundColor Gray
Write-Host " Action: $($policy .Action)" -ForegroundColor Cyan
Write-Host " Enabled: $($policy .Enable)" -ForegroundColor $(
if ($policy .Enable) { "Green" } else { "Red" }
)
}
}
else {
Write-Host " ⚠️ Requires Microsoft Defender for Office 365 Plan 1 or 2 " -ForegroundColor Yellow
}
if ($result .isCompliant) {
Write-Host "`n[OK] COMPLIANT - Comprehensive protection enabled" -ForegroundColor Green
exit 0
}
else {
if ($result .malwarePolicies -eq 0 ) {
Write-Host "`n[FAIL] NON-COMPLIANT - Missing Malware Filter policies" -ForegroundColor Red
}
else {
Write-Host "`n⚠️ PARTIAL - Safe Attachments not configured (requires license)" -ForegroundColor Yellow
}
exit 1
}
}
catch {
Write-Host "`n[FAIL] ERROR: $_ " -ForegroundColor Red
exit 2
}
}
function Invoke-Remediation {
try {
Write-Host "⚠️ Safe Attachments requires Defender for Office 365 " -ForegroundColor Yellow
Write-Host "`nTo configure:" -ForegroundColor Cyan
Write-Host " 1 . Ensure Defender for Office 365 Plan 1 or 2 license" -ForegroundColor Gray
Write-Host " 2 . Security & Compliance Portal > Threat management" -ForegroundColor Gray
Write-Host " 3 . Policy > Safe Attachments" -ForegroundColor Gray
Write-Host " 4 . Create policy:" -ForegroundColor Gray
Write-Host " • Action: Block or Dynamic Delivery" -ForegroundColor Gray
Write-Host " • Enable redirect: Yes" -ForegroundColor Gray
Write-Host " • Redirect to: security team email" -ForegroundColor Gray
Write-Host " • Applied to: All users" -ForegroundColor Gray
Write-Host "`n📝 Safe Attachments scans files in real-time" -ForegroundColor Cyan
Write-Host "Detonates suspicious files in sandbox environment" -ForegroundColor Gray
exit 0
}
catch {
Write-Host "`n[FAIL] ERROR: $_ " -ForegroundColor Red
exit 2
}
}
try {
if ($Monitoring ) {
Invoke-Monitoring
}
elseif ($Remediation ) {
Invoke-Remediation
}
else {
Write-Host "Use: -Monitoring or -Remediation" -ForegroundColor Yellow
}
}
catch {
throw
}
finally {
Write-Host "`n========================================`n" -ForegroundColor Cyan
}
"
throw
}
}
try {
if ($Monitoring ) {
Invoke-Monitoring
}
elseif ($Remediation ) {
Invoke-Remediation
}
else {
Write-Host "Use: -Monitoring or -Remediation" -ForegroundColor Yellow
}
}
catch {
throw
}
finally {
Write-Host "`n========================================`n" -ForegroundColor Cyan
}
Risico zonder implementatie
Risico zonder implementatie
High: No auth tracking.
Management Samenvatting
Schakel in audit logging.
Implementatietijd: 2 uur
FTE required: 0.01 FTE