Windows 11 Güvenlik Duvarı LOLBin Engelleme Script'i
Bu PowerShell script'i, Windows 11 sistemlerinde Living Off the Land Binari...
Bu yapılandırma, Kullanıcı Bağlamında Uygulama Engelleme stratejisi ile LOLBins ve bilinen kötü amaçlı yazılımların çalıştırılmasını engelleyerek saldırı yüzeyini minimize eder.
# PowerShell ile GPO oluşturma
New-GPO -Name "W11-User-Application-Blocking" -Comment "LOLBins ve malware engellemesi"
# OU'ya bağlama
New-GPLink -Name "W11-User-Application-Blocking" `
-Target "OU=Users,DC=contoso,DC=local" `
-LinkEnabled Yes `
-Order 1
Computer Configuration → Policies → Administrative Templates → System → Group Policy
→ "Configure user Group Policy loopback processing mode" = Enabled (Merge mode)
# GPO Security Filtering ayarlama
$GPO = Get-GPO -Name "W11-User-Application-Blocking"
# Varsayılan "Authenticated Users" kaldır
Set-GPPermission -Name $GPO.DisplayName `
-TargetName "Authenticated Users" `
-TargetType Group `
-PermissionLevel None
# Standart kullanıcıları ekle
Set-GPPermission -Name $GPO.DisplayName `
-TargetName "Domain Users" `
-TargetType Group `
-PermissionLevel GpoApply
# Local Users ekle (SID kullanarak)
Set-GPPermission -Name $GPO.DisplayName `
-TargetName "S-1-5-32-545" `
-TargetType Group `
-PermissionLevel GpoApply
# Hariç tutulacak gruplar (Read only izni)
$ExcludedGroups = @(
"Domain Admins",
"Enterprise Admins",
"IT-Helpdesk",
"Security-Admins"
)
foreach ($group in $ExcludedGroups) {
Set-GPPermission -Name $GPO.DisplayName `
-TargetName $group `
-TargetType Group `
-PermissionLevel GpoRead
}
# Tam engelleme listesi
$BlockedApplications = @{
# Script Motorları ve Shell'ler
"ScriptEngines" = @(
"powershell.exe",
"pwsh.exe",
"powershell_ise.exe",
"wscript.exe",
"cscript.exe",
"mshta.exe",
"cmd.exe",
"bash.exe",
"wsl.exe"
)
# İndirme/C2 LOLBins
"DownloadC2" = @(
"bitsadmin.exe",
"certutil.exe",
"curl.exe",
"ftp.exe",
"tftp.exe",
"xwizard.exe"
)
# Kurulum/Proxy-Execution
"ProxyExecution" = @(
"msiexec.exe",
"installutil.exe",
"regsvr32.exe",
"rundll32.exe"
)
# Persistence/Lateral Movement
"PersistenceLateral" = @(
"schtasks.exe",
"wmic.exe",
"winrs.exe",
"cmdkey.exe",
"reg.exe"
)
# Bilinen Malware/Araçlar
"KnownMalware" = @(
"agenttesla.exe",
"darkcomet.exe",
"havoc.exe",
"masscan.exe",
"meterpreter.exe",
"mimikatz.exe",
"mimilib.dll",
"msfvenom.exe",
"mythic.exe",
"nanocore.exe",
"ncat.exe",
"netcat.exe",
"nmap.exe",
"nping.exe",
"pathping.exe",
"pcalua.exe",
"pubprn.vbs",
"remcos.exe",
"revenge_rat.exe",
"sekurlsa.exe",
"sliver.exe",
"teamserver.exe",
"token.exe",
"vbc.exe",
"wevtutil.exe",
"winexe.exe",
"wusa.exe",
"xwizard.exe",
"wlrmdr.exe",
"zmap.exe"
)
}
function Create-AppBlockingRegistry {
param(
[string]$GPOName = "W11-User-Application-Blocking"
)
$regPath = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer"
# Komut satırı erişimini engelle
Set-GPRegistryValue -Name $GPOName `
-Key $regPath `
-ValueName "DisableCMD" `
-Type DWORD `
-Value 2
# Registry editörlerini engelle
Set-GPRegistryValue -Name $GPOName `
-Key $regPath `
-ValueName "DisableRegistryTools" `
-Type DWORD `
-Value 1
# Run menüsünü devre dışı bırak
Set-GPRegistryValue -Name $GPOName `
-Key $regPath `
-ValueName "NoRun" `
-Type DWORD `
-Value 1
}
function Configure-SoftwareRestrictionPolicies {
param(
[string]$GPOName = "W11-User-Application-Blocking"
)
# SRP için temel path
$srpPath = "HKLM\SOFTWARE\Policies\Microsoft\Windows\Safer\CodeIdentifiers"
# Varsayılan güvenlik seviyesi (Unrestricted)
Set-GPRegistryValue -Name $GPOName `
-Key $srpPath `
-ValueName "DefaultLevel" `
-Type DWORD `
-Value 262144
# Her bir engellenecek uygulama için hash rule oluştur
$ruleGuid = 0
foreach ($category in $BlockedApplications.Keys) {
foreach ($app in $BlockedApplications[$category]) {
$ruleGuid++
$guidString = "{" + [guid]::NewGuid().ToString().ToUpper() + "}"
# Path rule oluştur
$rulePath = "$srpPath\0\Paths\$guidString"
Set-GPRegistryValue -Name $GPOName `
-Key $rulePath `
-ValueName "ItemData" `
-Type String `
-Value "*\$app"
Set-GPRegistryValue -Name $GPOName `
-Key $rulePath `
-ValueName "SaferFlags" `
-Type DWORD `
-Value 0
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<policyDefinitions xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
revision="1.0"
schemaVersion="1.0"
xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions">
<policyNamespaces>
<target prefix="w11block" namespace="Microsoft.Policies.W11ApplicationBlocking" />
</policyNamespaces>
<resources minRequiredRevision="1.0" />
<categories>
<category name="W11_App_Blocking" displayName="$(string.W11_App_Blocking)">
<parentCategory ref="windows:System" />
</category>
</categories>
<policies>
<policy name="BlockLOLBins"
class="User"
displayName="$(string.BlockLOLBins)"
explainText="$(string.BlockLOLBins_Help)"
key="Software\Policies\W11Block"
valueName="BlockLOLBins">
<parentCategory ref="W11_App_Blocking" />
<supportedOn ref="windows:SUPPORTED_Windows_10_0" />
<enabledValue>
<decimal value="1" />
</enabledValue>
<disabledValue>
<decimal value="0" />
</disabledValue>
</policy>
</policies>
</policyDefinitions>
function Test-ApplicationBlocking {
[CmdletBinding()]
param(
[string]$TestUser = "testuser@domain.local"
)
# Test edilecek uygulamalar
$testApps = @(
@{Name="PowerShell"; Path="powershell.exe"; Command="-NoProfile -Command Write-Host 'Test'"},
@{Name="CMD"; Path="cmd.exe"; Command="/c echo Test"},
@{Name="CertUtil"; Path="certutil.exe"; Command="-?"}
)
Write-Host "Testing Application Blocking for: $TestUser" -ForegroundColor Cyan
Write-Host "=" * 50
foreach ($app in $testApps) {
try {
# RunAs ile test
$credential = Get-Credential -UserName $TestUser
$process = Start-Process -FilePath $app.Path `
-ArgumentList $app.Command `
-Credential $credential `
-PassThru `
-Wait `
-ErrorAction Stop
if ($process.ExitCode -eq 0) {
Write-Host "❌ $($app.Name): NOT BLOCKED" -ForegroundColor Red
} else {
Write-Host "✅ $($app.Name): BLOCKED" -ForegroundColor Green
}
}
catch {
Write-Host "✅ $($app.Name): BLOCKED (Exception)" -ForegroundColor Green
}
}
}
function Emergency-Rollback {
param(
[string]$GPOName = "W11-User-Application-Blocking"
)
# GPO'yu devre dışı bırak
$GPO = Get-GPO -Name $GPOName
$GPO.GpoStatus = "AllSettingsDisabled"
# GPO linklerini kaldır
Get-GPOReport -Name $GPOName -ReportType Xml |
Select-Xml -XPath "//LinksTo/SOMPath" |
ForEach-Object {
Remove-GPLink -Name $GPOName -Target $_.Node.InnerText -Confirm:$false
}
# Kullanıcılarda zorla güncelleme
Invoke-Command -ComputerName (Get-ADComputer -Filter *).Name -ScriptBlock {
gpupdate /force
}
Write-Host "Emergency rollback completed!" -ForegroundColor Yellow
}
# AppLocker/SRP event monitoring
function Get-BlockedApplicationEvents {
param(
[int]$Hours = 24
)
$startTime = (Get-Date).AddHours(-$Hours)
# Event ID'ler
# 865: SRP blocked
# 866: SRP warning
# 8003: AppLocker blocked
Get-WinEvent -FilterHashtable @{
LogName = 'Application'
ID = 865, 866, 8003
StartTime = $startTime
} | Select-Object TimeCreated, Id, Message, UserId |
Export-Csv "BlockedApps_$(Get-Date -Format 'yyyyMMdd').csv"
}
rundll32.exe Engelleme
msiexec.exe Kısıtlaması
wevtutil.exe
<AppLockerPolicy Version="1">
<RuleCollection Type="Exe" EnforcementMode="Enabled">
<FilePublisherRule Id="a61c8b3c-a27f-4c8b-8e8a-8b4e62d8565f"
Name="MICROSOFT WINDOWS OPERATING SYSTEM"
Description=""
UserOrGroupSid="S-1-1-0"
Action="Allow">
<Conditions>
<FilePublisherCondition PublisherName="O=MICROSOFT CORPORATION, L=REDMOND, S=WASHINGTON, C=US"
ProductName="MICROSOFT® WINDOWS® OPERATING SYSTEM"
BinaryName="*">
<BinaryVersionRange LowSection="*" HighSection="*"/>
</FilePublisherCondition>
</Conditions>
<Exceptions>
<!-- LOLBins exception listesi -->
<FilePathCondition Path="%SYSTEM32%\certutil.exe"/>
<FilePathCondition Path="%SYSTEM32%\bitsadmin.exe"/>
</Exceptions>
</FilePublisherRule>
</RuleCollection>
</AppLockerPolicy>
Bu GPO tabanlı uygulama engelleme stratejisi:
Kritik Başarı Faktörleri: