Active Directory Forest Recovery After a Ransomware Attack

How is an Active Directory forest restored after a ransomware incident? Choosing a trustworthy backup, isolated recovery and the checks to make before returning to production are covered separately.
Technical summary
Technology
Active Directory Domain Services, DSRM, Windows Server Backup, DFSR SYSVOL, RID Master, KRBTGT, ntdsutil
Topic
Active Directory forest recovery after a cyber incident
Level
Advanced
Prerequisites
  • A system state backup of at least one DC for each domain
  • An out-of-band record of DSRM passwords
  • A recovery network and hardware isolated from production
In this article8 sections

In human-operated ransomware attacks, the attacker may have gained domain admin rights before encrypting. At that point Active Directory isn’t a trustworthy identity source: the KRBTGT key, administrator passwords and trust secrets may be in the attacker’s hands. Repairing a single DC, bringing back a deleted object and restoring the whole forest are different operations; this guide covers only the last one, the scenario where domain controllers have been compromised. The order and prerequisites are compiled from Microsoft’s forest recovery guide. The steps shouldn’t be applied in production without being tried in your organization’s isolated environment.

Why AD comes first in recovery

File servers, ERP, email, VPN and virtualization management largely depend on AD authentication. An application server restored before AD is up can be accessed with a local account, or not at all; service accounts don’t start and Group Policies aren’t applied. Worse: systems recovered with an untrustworthy AD are immediately taken over again with the credentials in the attacker’s hands. Dirty AD, dirty recovery.

That’s why, in the recovery plan, AD comes after core network services (including DNS) and before the first business service. Decisions such as which recovery point to use and how to isolate the recovery environment are covered in separate articles: choosing a clean recovery point and isolated recovery environment design. Routine AD backup and restore operations without an attack are the subject of the Active Directory backup and restore article.

The recovery decision: clean up or rebuild

The first decision: will the existing forest be recovered and cleaned, or will a new forest be built from scratch? The second route gives a clean start, but at a heavy price; every file permission and every application connection is rebuilt.

Criterion Forest recovery and cleanup Building a new forest
Recovery time Relatively short Long; all objects are recreated
Impact SIDs, groups and permissions are preserved File permissions and application connections are rebuilt
Clients and servers Don’t need to leave and rejoin the domain (except machine password issues) All are joined to the new domain
Persistence risk Traces left in AD objects may be carried over A clean start; but migrated data must still be checked
When it fits A trustworthy backup from before the attack exists No trustworthy backup, or the forest has been compromised for a long time

If a trustworthy backup exists, in practice forest recovery is applied first, and then AD goes through thorough hardening and cleanup. The new forest decision usually comes to the table when the attacker’s initial access date can’t be determined or when all backups date from after it.

Choosing the DC backup and restoring in an isolated environment

The basic principle of forest recovery is this: in each domain, only one writable DC is restored from backup, and all other DCs are built from scratch afterwards. When choosing the DC to restore, look at the following:

  • Is the backup’s date before or after the attacker’s initial access date?
  • Is the backup older than the tombstone lifetime? (Default 180 days; check the value in your forest from the tombstoneLifetime attribute.)
  • Is the DC in the forest root domain, and which FSMO roles did it hold?
  • Was the DC also a DNS server and global catalog?

The restore is done on an isolated network with no connection at all to the production network. A single replication round with compromised DCs re-dirties the cleaned data. Network separation isn’t negotiable. A system state restore to a physical or virtual server with Windows Server Backup is done in DSRM; on the first DC, SYSVOL must be marked authoritative:

REM On the server booted into DSRM, at an administrator command prompt
wbadmin get versions -backupTarget:E:
wbadmin start systemstaterecovery -version:03/14/2026-21:00 -backupTarget:E: -authsysvol

The version ID is taken from the output of wbadmin get versions. For DCs restored from a virtual machine image too, SYSVOL must be marked authoritative on DFSR; follow the DFSR steps in Microsoft’s guide. After the restore, you have to know the DSRM password; that’s why you should keep DSRM passwords in an out-of-band location. This is where people often get stuck: the DSRM password is a value nobody has known since installation.

Recovery steps: metadata cleanup, RID, KRBTGT

After the restored DC is started in the isolated environment and its data verified, the steps are carried out in the order below. The order follows the initial recovery steps in Microsoft’s forest recovery guide; the guide also includes recreating gMSA accounts and setting the time source of the PDC emulator in the forest root domain. Read the table as a summary; before applying it, compare it with the current version of the guide and your own runbook.

Sequence Step Purpose
1 Seizing the FSMO roles The remaining DC takes on all roles
2 Metadata cleanup of the other DCs Removing replication partners from AD
3 Cleaning up DNS records Deleting SRV and A records belonging to removed DCs
4 Raising the RID pool by 100,000, invalidating the current pool Preventing duplicate SIDs
5 Resetting the DC computer account password twice Changing the machine secret the attacker knows
6 Resetting the KRBTGT password twice; resetting administrator account passwords Invalidating forged Kerberos tickets and known passwords
7 In a multi-domain forest, removing the GC if the restored DC is a global catalog Preventing lingering objects; not needed in a single-domain forest

FSMO and metadata cleanup

Seizing roles can be done with PowerShell (Schema Master and Domain Naming Master are seized only on the DC in the forest root domain; in child domains, only the RID, PDC and Infrastructure roles): Move-ADDirectoryServerOperationMasterRole -Identity DC01 -OperationMasterRole SchemaMaster,DomainNamingMaster,PDCEmulator,RIDMaster,InfrastructureMaster -Force. When the other DCs’ objects are deleted through Active Directory Sites and Services or Active Directory Users and Computers, metadata cleanup is done automatically; on the command line, metadata cleanup in ntdsutil can be used.

RID pool

The available RID pool is kept in the rIDAvailablePool attribute of the CN=RID Manager$,CN=System object. An example for reading the value and raising it by 100,000:

$dn = 'CN=RID Manager$,CN=System,DC=corp,DC=example'
$v  = (Get-ADObject $dn -Properties rIDAvailablePool).rIDAvailablePool
"Current value: $v"
Set-ADObject $dn -Replace @{rIDAvailablePool = ($v + 100000)}

Then the DC’s current RID pool is invalidated. Microsoft’s guide describes this as running the invalidateRidPool operation on RootDSE with Ldp, using the domain SID. Verification is simple: after these two steps, create a test object and look at its RID value. If the value didn’t jump, the operation didn’t take.

KRBTGT

The KRBTGT account’s password is the source of the key that signs all Kerberos tickets in the domain. If the attacker has this key, they can produce tickets for any user; this is called a golden ticket. Because DCs accept both the current and the previous password, the reset is done twice. In normal operation, you wait between the two resets for replication to complete and for the longest ticket lifetime (10 hours by default) to pass; in forest recovery, because there’s only one DC in the domain, the second reset can be done without waiting for replication. The KRBTGT reset script published by Microsoft can be used to do this in a controlled way. The separate KRBTGT accounts belonging to RODCs should also be included; the RODCs will be rebuilt anyway.

Resetting privileged accounts and trusts

KRBTGT alone isn’t enough. Other secrets you have to assume the attacker knows:

  • The built-in Administrator and all members of privileged groups: The passwords of Domain Admins, Enterprise Admins, Schema Admins, Administrators, Account Operators, Backup Operators and accounts with delegated privileged rights are reset; unnecessary memberships are removed.
  • Service accounts: Especially service accounts that carry SPNs and have high privileges; accounts whose passwords will change are planned together with the relevant application owners.
  • Trusts: If the recovery is being done because of a security breach, the passwords of intra-forest and external trusts are reset too. Microsoft’s guide describes this with the /resetOneSide parameter of the netdom trust command; verify the steps and the number of repetitions against the current procedure in the guide.
  • DSRM passwords: Renewed on all DCs after recovery is complete and recorded out of band again.
  • Entra Connect and similar synchronization accounts: In a hybrid environment, privileges on the cloud side are reviewed too.

This stage is also the right time to redesign administrator accounts according to enterprise cybersecurity principles. Returning to the recovered forest with the old flat administrator model opens the same attack path again. Same model, same incident; the tiered administration approach is covered in the Active Directory tier model article.

Rebuilding the other DCs

After the cleaned DC is verified, new servers built from scratch in the isolated environment are promoted to DCs. The old DCs’ disks aren’t restored or reused; they can be kept as evidence. After the new DCs are promoted, these checks are run:

repadmin /replsummary
repadmin /showrepl * /csv > C:\Recovery\replication.csv
dcdiag /e /v /f:C:\Recovery\dcdiag.txt
dfsrmig /getglobalstate

If replication is error-free, the SYSVOL share is published on all DCs and DNS records are correct, the DCs are connected to the production network in a controlled way. If one is missing, they aren’t connected. Member servers and clients are connected gradually until the compromised systems on the production network have been cleaned. On machines with secure channel problems, Test-ComputerSecureChannel -Repair can be used.

Preparations to make in advance

Forest recovery can’t be done with a document read for the first time during the incident. Microsoft’s guide is long and isn’t a text to read on a tense night. A preparation list:

  • Is there a system state backup of at least one DC from each domain, in an immutable or offline copy and within the tombstone lifetime?
  • Are DSRM passwords recorded outside the domain, accessible out of band?
  • Is an isolated network, hardware or separate hypervisor capacity defined for recovery?
  • Are the forest topology, FSMO owners, trusts and DNS zones documented and up to date?
  • Have the recovery steps been written as a runbook specific to the organization’s environment and tried at least once in an isolated environment?
  • Is the reference state of privileged objects in AD (group memberships, AdminSDHolder permissions, GPO list) being exported for comparison?

To see the risks in your current AD setup before an incident, the Active Directory security controls article is a starting point. If you want to prepare your forest recovery runbook or test it in an isolated environment, take a look at the scope of our Active Directory security audit and cyber incident response readiness and exercises services.

Primary source: Microsoft Active Directory Forest Recovery Guide.

Frequently asked questions

Can’t we clean one of the compromised DCs and keep using it?

It isn’t recommended. It’s usually impossible to fully verify whether the attacker left persistence on the DC. The forest recovery approach relies on restoring only one DC per domain from a backup that predates the attack and cleaning it, and replacing all other DCs with new servers built and promoted from scratch.

Why is the KRBTGT password reset twice?

Domain controllers keep both the current and the previous password for KRBTGT. With a single reset, the old password the attacker knows remains valid as the previous password, and tickets produced with this key can still be validated. The second reset removes the value the attacker knows from the history entirely.

How old can the backup be?

The restored DC backup can’t be older than the forest’s tombstone lifetime; this lifetime is 180 days by default in forests created with Windows Server 2003 SP1 and later. From a cyber incident standpoint, the real limit is the attacker’s initial access date: the backup should predate this date, or the persistence mechanisms in it must be checked one by one.

Why is raising the RID pool necessary?

The restored DC is unaware of RID values handed out by other DCs after the backup. If the RID pool isn’t raised, a newly created user or group may get the same SID as an object created after the backup. Microsoft recommends raising the available RID pool by 100,000 and invalidating the current pool.

Support

Contact us for support or a discovery session on this topic.

Contact form
[email protected]

Eretek Cybersecurity

Firewall, VPN, endpoint security and threat prevention. We reduce the attack surface and measure and report the risks.

Knowledge Center

Other articles