Voorkom niet-vertrouwde query files Blokkeert .iqy, .dqy, .odc query files uit internet zone die database connections opzetten naar attacker-controlled servers voor Diefstal van inloggegevens en SQL injection.
Aanbeveling
IMPLEMENT
Risico zonder
High
Risk Score
7/10
Implementatie
2u (tech: 1u)
Van toepassing op:
β Microsoft Excel
Query files is database connection attacks: .IQY files (Internet Query - web data source), .ODC files (Office Data Connection - database connections), .DQY files (DBase Query). Attack: Phishing email β malicious .iqy attachment β user opens β Excel connects to attacker SQL server β credentials sent (SQL authentication) of attacker runs SQL injection queries. Zonder block: Query files van email attachments execute, Database credentials stolen, SQL injection possible (attacker-controlled queries).
Implementatie
Blokkeer niet-vertrouwde query files: Internet zone query files β blocked (MOTW detectie), Vertrouwde locaties query files β allowed, User prompt voor query files (with warning).
Vereisten
Office 2016+
Intune of GPO
Implementatie
Intune Settings Catalog: Excel\Security\Vertrouwenscentrum\External Content β Data Connection Files: Schakel uit niet-vertrouwde data connection files.
monitoring
Gebruik PowerShell-script prevent-untrusted-query-files.ps1 (functie Invoke-Monitoring) β Controleren.
Query file blocking: BIO 13.02 (Ungeautoriseerde database connections), ISO 27001 A.13.2.1.
Remediatie
Gebruik PowerShell-script prevent-untrusted-query-files.ps1 (functie Invoke-Remediation) β Herstellen.
Compliance & Frameworks
BIO: 13.02.01 -
ISO 27001:2022: A.13.2.1 -
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
Voorkomt openen van niet-vertrouwde Microsoft Query bestanden in Excel
.DESCRIPTION
Dit script implementeert CIS control O365-EX-000015 voor het voorkomen van het openen
van niet-vertrouwde Microsoft Query bestanden in Microsoft Excel. Dit beschermt tegen
potentieel schadelijke query bestanden van niet-vertrouwde bronnen.
.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
.\prevent-untrusted-query-files.ps1 -Monitoring
Controleert of niet-vertrouwde query bestanden worden geblokkeerd
.EXAMPLE
.\prevent-untrusted-query-files.ps1 -Remediation
Blokkeert niet-vertrouwde query bestanden
.NOTES
Registry pad: HKCU:\Software\Policies\Microsoft\Office\16.0\Excel\Security\TrustCenter
Waarde: PreventUntrustedQueryFiles = 1
CIS Control: O365-EX-000015
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\TrustCenter"
$ValueName = "PreventUntrustedQueryFiles"
$ExpectedValue = 1$ControlID = "O365-EX-000015"
functionTest-Compliance {
try {
if (-not (Test-Path$RegistryPath)) {
return$false
}
$currentValue = Get-ItemProperty -Path $RegistryPath -Name $ValueName -ErrorAction SilentlyContinue
return ($currentValue -and $currentValue.$ValueName -eq $ExpectedValue)
}
catch {
return$false
}
}
function Invoke-Monitoring {
Write-Host "Monitoring ${ControlID}: Niet-vertrouwde query bestanden blokkeren" -ForegroundColor Green
try {
if (-not (Test-Path$RegistryPath)) {
Write-Host "β Registry pad bestaat niet: $RegistryPath" -ForegroundColor Red
return$false
}
$currentValue = Get-ItemProperty -Path $RegistryPath -Name $ValueName -ErrorAction SilentlyContinue
if ($currentValue -and $currentValue.$ValueName -eq $ExpectedValue) {
Write-Host "β Control compliant: ${ValueName} = $ExpectedValue (Niet-vertrouwde query bestanden geblokkeerd)" -ForegroundColor Green
return$true
}
else {
$actualValue = if ($currentValue) { $currentValue.$ValueName } else { "Not Set" }
Write-Host "β Control non-compliant: ${ValueName} = $actualValue (Expected: $ExpectedValue)" -ForegroundColor Red
return$false
}
}
catch {
Write-Host "β Fout bij controleren registry instelling: $($_.Exception.Message)" -ForegroundColor Red
return$false
}
}
function Invoke-Remediation {
Write-Host "Remediating ${ControlID}: Niet-vertrouwde query bestanden blokkeren" -ForegroundColor Yellow
try {
if ($WhatIf) {
Write-Host "WhatIf: Zou registry waarde instellen: ${ValueName} = $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 $ValueName -Value $ExpectedValue -Type DWord -Force
Write-Host "β Registry waarde succesvol ingesteld: ${ValueName} = $ExpectedValue" -ForegroundColor Green
Start-Sleep -Seconds 1return Invoke-Monitoring
}
catch {
Write-Host "β Fout bij configureren registry instelling: $($_.Exception.Message)" -ForegroundColor Red
return$false
}
}
function Invoke-Revert {
Write-Host "Reverting ${ControlID}: Query bestanden blokkering herstellen" -ForegroundColor Yellow
try {
if ($WhatIf) {
Write-Host "WhatIf: Zou registry waarde verwijderen: ${ValueName}" -ForegroundColor Cyan
return$true
}
if (Test-Path$RegistryPath) {
Remove-ItemProperty -Path $RegistryPath -Name $ValueName -ErrorAction SilentlyContinue
Write-Host "β Registry waarde verwijderd: ${ValueName}" -ForegroundColor Green
}
return$true
}
catch {
Write-Host "β Fout bij herstellen registry instelling: $($_.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: .\prevent-untrusted-query-files.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 > Microsoft Query Settings" -ForegroundColor White
Write-Host "> Always prevent untrusted Microsoft Query files from opening: Enabled" -ForegroundColor White
}
}
catch {
Write-Host "β Onverwachte fout: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
Risico zonder implementatie
Risico zonder implementatie
High: Hoog: Query files is Diefstal van inloggegevens, SQL injection via attacker-controlled database connections.