Excel: Scan Versleutelde Macros In Open XML Documents
π 2025-10-30
β’
β±οΈ 5 minuten lezen
β’
π’ Should-Have
πΌ Management Samenvatting
Scan versleutelde macros ingeschakeld zorgt dat Office decrypts macro code voordat execution zodat antivirus malware kan detecteren - zonder scan kunnen versleuteld macros AV bypassen.
Aanbeveling
IMPLEMENT
Risico zonder
Medium
Risk Score
6/10
Implementatie
1u (tech: 0.5u)
Van toepassing op:
β Microsoft Excel
versleuteld macros is AV blind spot: VBA project versleuteling (password-protected macros), Antivirus kan niet scan versleuteld code (opaque to AV), Malware obfuscation via versleuteling (bypass detectie). Attack: Macro malware met versleuteld VBA project β AV scans Excel file β versleuteld macros unreadable β malware not detected β user maakt mogelijk macros β infection. Scan versleutelde macros: Office decrypts macro code tijdelijk β AV can scan β malware detected voordat execution.
Implementatie
Scan versleutelde macros: Registry: ScanEncryptedMacros is 1 (ingeschakeld), Effect: Office decrypts VBA projects voor AV scanning, Antivirus integration (AMSI - Antimalware Scan Interface), versleuteld macros scanned voordat execution. Performance: Minimal overhead (decryption voor scan only).
Vereisten
Office 2016+
Antivirus met AMSI ondersteunen (Defender, third-party)
Intune configuration profile of GPO
Implementatie
Intune Settings Catalog: Excel\Security β Scan versleutelde macros in Excel Open XML workbooks: ingeschakeld (Standaard aanbevolen). Verifieer antivirus AMSI integration active (Defender automatically, derde partij verify).
monitoring
Gebruik PowerShell-script scan-encrypted-macros.ps1 (functie Invoke-Monitoring) β Controleren.
monitor AV detectie rates (versleuteld vs non-versleuteld macros), Verifieer AMSI alerts voor macro threats.
Compliance en Auditing
versleuteld macro scanning: CIS Office Benchmark (Schakel in versleuteld macro scan), BIO 12.02 (Malware detectie), ISO 27001 A.12.2.1.
Remediatie
Gebruik PowerShell-script scan-encrypted-macros.ps1 (functie Invoke-Remediation) β Herstellen.
Compliance & Frameworks
CIS M365: Control Office - versleuteld Macros (L1) -
BIO: 12.02.01 -
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).
PowerShell
<#
.SYNOPSIS
Dwingt scanning van gecodeerde macros in Excel Open XML werkbladen
.DESCRIPTION
Dit script implementeert CIS control O365-EX-000012 voor het scannen van gecodeerde macros
in Excel Open XML werkbladen in Microsoft Excel. Dit beschermt tegen verborgen schadelijke
macros in gecodeerde bestanden.
.REQUIREMENTS
- PowerShell 5.1 of hoger
- Lokale administrator rechten voor registry wijzigingen
- Microsoft Excel geΓ―nstalleerd
.PARAMETER Monitoring
Controleert de huidige compliance status
.PARAMETER Remediation
Past de aanbevolen configuratie toe
.PARAMETER Revert
Herstelt de originele configuratie
.PARAMETER WhatIf
Toont wat er zou gebeuren zonder wijzigingen door te voeren
.EXAMPLE
.\scan-encrypted-macros.ps1 -Monitoring
Controleert of gecodeerde macro scanning is ingeschakeld
.EXAMPLE
.\scan-encrypted-macros.ps1 -Remediation
Schakelt gecodeerde macro scanning in
.NOTES
Registry pad: HKCU:\Software\Policies\Microsoft\Office\16.0\Excel\Security
Waarden: ScanEncryptedMacros = 1, VBAWarnings = 1
CIS Control: O365-EX-000012
DISA STIG: Microsoft Office 365 ProPlus v3r3
#>#Requires -Version 5.1param(
[switch]$Monitoring,
[switch]$Remediation,
[switch]$Revert,
[switch]$WhatIf
)
# Globale variabelen$RegistryPath = "HKCU:\Software\Policies\Microsoft\Office\16.0\Excel\Security"
$ValueName1 = "ScanEncryptedMacros"
$ValueName2 = "VBAWarnings"
$ExpectedValue = 1$ControlID = "O365-EX-000012"
functionTest-Compliance {
try {
if (-not (Test-Path$RegistryPath)) {
return$false
}
$v1 = Get-ItemProperty -Path $RegistryPath -Name $ValueName1 -ErrorAction SilentlyContinue
$v2 = Get-ItemProperty -Path $RegistryPath -Name $ValueName2 -ErrorAction SilentlyContinue
return (($v1 -and $v1.$ValueName1 -eq $ExpectedValue) -or ($v2 -and $v2.$ValueName2 -ge $ExpectedValue))
}
catch {
return$false
}
}
function Invoke-Monitoring {
Write-Host "Monitoring ${ControlID}: Gecodeerde macro scanning inschakelen" -ForegroundColor Green
try {
if (-not (Test-Path$RegistryPath)) {
Write-Host "β Registry pad bestaat niet: $RegistryPath" -ForegroundColor Red
return$false
}
$v1 = Get-ItemProperty -Path $RegistryPath -Name $ValueName1 -ErrorAction SilentlyContinue
$v2 = Get-ItemProperty -Path $RegistryPath -Name $ValueName2 -ErrorAction SilentlyContinue
$scanEnabled = (($v1 -and $v1.$ValueName1 -eq $ExpectedValue) -or ($v2 -and $v2.$ValueName2 -ge $ExpectedValue))
if ($scanEnabled) {
Write-Host "β Control compliant: Gecodeerde macro scanning is ingeschakeld" -ForegroundColor Green
return$true
}
else {
Write-Host "β Control non-compliant: Gecodeerde macro scanning is uitgeschakeld" -ForegroundColor Red
return$false
}
}
catch {
Write-Host "β Fout bij controleren registry instellingen: $($_.Exception.Message)" -ForegroundColor Red
return$false
}
}
function Invoke-Remediation {
Write-Host "Remediating ${ControlID}: Gecodeerde macro scanning inschakelen" -ForegroundColor Yellow
try {
if ($WhatIf) {
Write-Host "WhatIf: Zou registry waarden instellen: ${ValueName1} = $ExpectedValue, ${ValueName2} = $ExpectedValue" -ForegroundColor Cyan
return$true
}
if (-not (Test-Path$RegistryPath)) {
Write-Host "Registry pad aanmaken: $RegistryPath" -ForegroundColor Yellow
New-Item -Path $RegistryPath -Force | Out-Null
}
Set-ItemProperty -Path $RegistryPath -Name $ValueName1 -Value $ExpectedValue -Type DWord -Force
Set-ItemProperty -Path $RegistryPath -Name $ValueName2 -Value $ExpectedValue -Type DWord -Force
Write-Host "β Registry waarden succesvol ingesteld" -ForegroundColor Green
Start-Sleep -Seconds 1return Invoke-Monitoring
}
catch {
Write-Host "β Fout bij configureren registry instellingen: $($_.Exception.Message)" -ForegroundColor Red
return$false
}
}
function Invoke-Revert {
Write-Host "Reverting ${ControlID}: Gecodeerde macro scanning herstellen" -ForegroundColor Yellow
try {
if ($WhatIf) {
Write-Host "WhatIf: Zou registry waarden verwijderen: ${ValueName1}, ${ValueName2}" -ForegroundColor Cyan
return$true
}
if (Test-Path$RegistryPath) {
Remove-ItemProperty -Path $RegistryPath -Name $ValueName1 -ErrorAction SilentlyContinue
Remove-ItemProperty -Path $RegistryPath -Name $ValueName2 -ErrorAction SilentlyContinue
Write-Host "β Registry waarden verwijderd" -ForegroundColor Green
}
return$true
}
catch {
Write-Host "β Fout bij herstellen registry instellingen: $($_.Exception.Message)" -ForegroundColor Red
return$false
}
}
# Hoofd uitvoeringtry {
if ($Monitoring) {
$result = Invoke-Monitoring
exit $(if ($result) { 0 } else { 1 })
}
elseif ($Remediation) {
$result = Invoke-Remediation
exit $(if ($result) { 0 } else { 1 })
}
elseif ($Revert) {
$result = Invoke-Revert
exit $(if ($result) { 0 } else { 1 })
}
else {
Write-Host "Gebruik: .\scan-encrypted-macros.ps1 [-Monitoring] [-Remediation] [-Revert] [-WhatIf]" -ForegroundColor Yellow
Write-Host " -Monitoring: Controleer huidige compliance status" -ForegroundColor White
Write-Host " -Remediation: Pas aanbevolen configuratie toe" -ForegroundColor White
Write-Host " -Revert: Herstel originele configuratie" -ForegroundColor White
Write-Host " -WhatIf: Toon wat er zou gebeuren" -ForegroundColor White
Write-Host ""
Write-Host "Handmatige configuratie:" -ForegroundColor Cyan
Write-Host "Group Policy: User Configuration > Administrative Templates > Microsoft Excel 2016" -ForegroundColor White
Write-Host "> Excel Options > Security > Trust Center > Macro Settings" -ForegroundColor White
Write-Host "> Scan encrypted macros in Excel Open XML workbooks: Enabled: Scan encrypted macros (default)" -ForegroundColor White
}
}
catch {
Write-Host "β Onverwachte fout: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
Risico zonder implementatie
Risico zonder implementatie
Medium: Medium: versleuteld macros bypass AV scanning. Malware obfuscation via VBA project versleuteling.
Management Samenvatting
Schakel in Scan versleutelde macros. Office decrypts VBA voor AV scanning. AMSI integration. Implementatie: 30 min. nul business impact.