In short
Encrypted SQL Server, Exchange or other database files are not automatically lost: many ransomware families encrypt large files only in sections, and databases are made of fixed-size pages that can be analysed individually. What matters most is that nobody repairs, attaches or renames the original files before copies have been secured. Whether, and to what extent, tables or mailboxes can be reconstructed only becomes clear through analysis.
Encrypted database: the situation in a nutshell
The ERP system won't start, Outlook can't reach the server, and in the data directory Company.mdf or Mailbox01.edb suddenly carry an unfamiliar extension. For many organisations this is the real damage of a ransomware attack: not a handful of documents, but the central database holding orders, bookings, patient records or the entire mail history.
The good news: database files are large, rigidly structured containers. That makes them far more amenable to reconstruction than, say, an encrypted Word document. The bad news: well-meant repair attempts on the originals destroy exactly the structures a data recovery would build on. This page adds what specifically matters for SQL Server, Exchange and other databases to the overview on ransomware data recovery.
First steps: what to do and what to leave alone
Do now
- Isolate the affected database servers, but don't reinstall or reset them.
- Record the state of the services: are SQL Server instances, the Exchange Information Store, MySQL or PostgreSQL services still running? Since when have they been stopped? Screenshots or an export of the service list are enough.
- Save directory listings with file names, sizes and timestamps of the data, log and backup folders.
- Make a bit-for-bit copy of every affected file – database, logs, backups – or, better, an image of the whole volume or virtual disk.
- Set aside the ransom note and two or three encrypted sample files.
- Note which applications use which database, and who your contact at the software vendor is.
Never on the originals
| Action | Why it hurts |
|---|---|
DBCC CHECKDB … REPAIR_ALLOW_DATA_LOSS | May deallocate rows, pages or ranges of pages; according to Microsoft, deallocated data is no longer accessible or recoverable. |
eseutil /p on the EDB | Hard repair at page and table level that may discard rows or entire tables. |
Attaching with a rebuilt log (FOR ATTACH_REBUILD_LOG) or via Management Studio | Requires a clean shutdown, breaks the log backup chain and writes to the files. |
| Starting the database engine on the original files | Crash recovery runs at startup and modifies data and log files. |
innodb_force_recovery at 4 or higher | According to the MySQL manual, can permanently corrupt data files. |
| Renaming encrypted files | Doesn't undo the encryption, but alters metadata and traces. |
| Restoring "over" the encrypted database | Overwrites regions that may still contain unencrypted pages. |
| Cleaning up, defragmenting or reclaiming space on the volume | Deleted older versions and temporary files are lost. |
How to preserve evidence without getting in the way of recovery is covered in the guide on forensic evidence preservation.
Why databases are often partly recoverable
Attackers stop database services – with a side effect
While SQL Server or Exchange is running, its files are open and locked. Ransomware therefore deliberately terminates services and processes. For LockBit 3.0, CISA lists services and processes containing "sql" and "oracle" among those it kills.
For data recovery this has a flip side: if a service was shut down gracefully, its in-memory data was flushed to disk first. The unencrypted regions of such a file then often reflect a more consistent state than after a hard crash. Whether a service was stopped cleanly or killed can partly be reconstructed from logs and database headers – which is why documenting the service state matters.
Large files are often encrypted only in intervals
Fully encrypting a database of several hundred gigabytes takes time. Many families therefore encrypt only parts of a file:
- Play, according to CISA, uses intermittent encryption, encrypting every other file portion of 0x100000 bytes (1 MiB).
[3] - BlackSuit (Royal) lets the operators choose the percentage of a file to encrypt and lower it for larger files.
[4] - Akira, according to CISA, also supports full and partial encryption, with earlier versions taking an encryption-percentage parameter.
[19]
Which pattern applies depends on the family, variant and configuration. It has to be determined from the actual file, not from the group's name.
Fixed-size pages make fragments usable
SQL Server divides MDF and NDF files into 8 KiB pages; eight of them form a 64 KiB extent. Every page starts with a 96-byte header that includes the page number, page type and the ID of the owning object.
PostgreSQL also uses fixed-size pages, usually 8 kB.
Other sources besides the main file
- Transaction logs (LDF, Exchange log files, PostgreSQL WAL, MySQL redo log) hold recent changes and can partly fill gaps.
- Backup files such as SQL Server
.bakor log backups (.trn) often sit on other drives or shares and are sometimes only partly hit. - Log shipping targets, replicas and passive database copies occasionally live on servers that were not encrypted.
- Older versions in the file system – deleted previous versions, temporary export files, storage or hypervisor snapshots – may contain older, unencrypted database states.
Damage patterns and recovery paths
| Damage pattern | What is often still possible | What to avoid |
|---|---|---|
| MDF/NDF partially encrypted | Read out unencrypted pages, map them to tables, export records into a new database | Attach attempts, CHECKDB repair on the original |
| MDF intact, LDF missing or encrypted | Attach a copy without the log if the shutdown was clean; otherwise page-based reconstruction | Rebuilding the log on the original file |
.bak files encrypted | Analyse unencrypted sections; uncompressed backups hold data pages in clear | Restoring damaged backups onto the production system |
| Exchange EDB encrypted | Reconstruct mailboxes and items from readable ESE pages | eseutil /p, deleting log files |
| EDB readable but in Dirty Shutdown | Check the log chain on a copy, soft recovery on the copy | "Tidying up" log files, hard repair on the original |
MySQL: ibdata1 and .ibd encrypted | Per-table analysis of the .ibd files, matched against the data dictionary | innodb_force_recovery ≥ 4 on originals |
| PostgreSQL data directory encrypted | Reconstruction from relation files, WAL and system catalogue | Copying individual files into another cluster |
| Database inside an encrypted VM | First the VHDX/VMDK and guest file system, then the database files | Consolidating snapshots, rebooting the VM |
Whether a path works depends on the case. Combinations are common: an older, clean .bak plus tables reconstructed from the partially encrypted MDF for the period since.
SQL Server in detail
MDF, NDF and LDF
Every SQL Server database has at least one data file and one log file. The primary data file (recommended extension .mdf) holds startup information and points to the other files; secondary data files usually use .ndf, transaction logs .ldf.
The log contains no pages, but a series of variable-length log records.
When the log is missing
Microsoft only allows attaching a database with a rebuilt log (FOR ATTACH_REBUILD_LOG) if the database was shut down cleanly and all data files are available. The operation breaks the log backup chain.
DBCC CHECKDB: diagnosis yes, repair no
DBCC CHECKDB without a repair option is a useful tool – on a copy, for taking stock and later for validation. The repair options are a different matter. Microsoft describes REPAIR_ALLOW_DATA_LOSS as an emergency last-resort option that can lose more data than restoring from backup, and says physical copies of all database files must be made before any repair.
With a partially encrypted database it is even clearer: to CHECKDB, encrypted pages look like corrupt pages. A repair would deallocate them – along with references that could still have led to unencrypted data.
Backup files (.bak, .trn)
SQL Server backups are often encrypted themselves because they live on reachable shares or local drives. Uncompressed backups contain data pages essentially as they appear in the database; with partial encryption those regions remain usable. Compressed backups, or those created with backup encryption, are much harder to exploit when partly damaged. How backup infrastructure is attacked and validated in general is covered in recovering backups after ransomware. If your database backups live in Veeam repositories, see Veeam backup recovery after ransomware.
Exchange Server: EDB, logs and Dirty Shutdown
Exchange mailbox databases (.edb) are built on the Extensible Storage Engine (ESE).
A typical picture after an attack: the EDB is partly encrypted, or it is readable but in "Dirty Shutdown" because the Information Store was killed or logs are missing. This is the moment admins reach for eseutil /p. Microsoft describes this hard repair as fixing problems at page and table level, during which rows or even entire tables may be discarded. It advises backing up first, not leaving a repaired database in production for long, and not using repair when a restore without data loss is possible.
A better order: secure a copy, check the header and log chain on the copy, attempt soft recovery on the copy, and only then decide on further steps. If the EDB itself is encrypted, no Eseutil run will get you there. What remains is reconstructing mailboxes and items from readable pages.
MySQL/MariaDB, PostgreSQL, Oracle and line-of-business software
MySQL: by default, InnoDB creates each table in its own file-per-table tablespace – one .ibd file per table in the schema directory.ibdata1..ibd files are hit, the remaining tables can often be backed up normally. MariaDB follows a comparable principle, with details varying by version. According to the MySQL manual, innodb_force_recovery is for emergencies only; values of 4 or above can permanently corrupt data files and should only be used after testing on a separate physical copy.
PostgreSQL: the data directory (PGDATA) contains one subdirectory per database under base; tables and indexes are stored in files named after their filenode number and split into 1 GB segments; the WAL lives in pg_wal.pg_xact.
Oracle: an Oracle database consists of data files, control files and online redo log files.
Line-of-business software: many practice-management, accounting and ERP products ship their own database engines, for example based on Firebird, Pervasive/Actian or an embedded SQL Server instance. File formats and directory layouts vary widely. Bring in the vendor early: they know which files belong together and which consistency checks their application provides. DATEV environments have their own page: DATEV recovery after ransomware.
Databases in virtual machines and on storage
Most database servers today are virtualised. That adds a second layer: the ransomware may have encrypted the database files inside the guest, the virtual disk on the host, or both. Reconstruction follows the same order: first the datastore or volume, then the VHDX or VMDK, then the guest file system and finally the database files.
- For Hyper-V environments: Hyper-V recovery after ransomware
- For VMware: the guide on ransomware on VMware ESXi
- For RAID, NAS and server storage: the guide on ransomware on servers, NAS, RAID and VMware
Don't consolidate snapshots and don't reboot the VM. Both can overwrite older states that may contain an earlier, unencrypted version of the database. DATA REVERSE provides background on reconstructing virtual disks at recovery of virtual systems (in German) (external link) and on physical servers and arrays at server data recovery (in German) (external link).
Check for a decryptor first
Before investing in reconstruction, check whether a reputable decryptor exists for the specific family and variant. The ransomware decryption page and the ransomware database help with that. A decryptor should also only be tested on copies – faulty tools can damage files further.
Validation after recovery
A recovered database is only ready for use once it has been checked technically and from a business perspective. These steps have proven useful:
- Technical consistency on a copy:
DBCC CHECKDBwithout a repair option for SQL Server, plusDBCC CHECKCONSTRAINTSwhere referential dependencies exist, as Microsoft recommends after repairs.[7] For other systems, the engine's own checking tools. - Count and time reconciliation: compare record counts per table with known values and spot-check the latest bookings, documents or e-mails. Where does the recovered data end in time?
- Business plausibility checks by users: accounting, practice staff and sales check whether balances, records and open cases add up. Missing records often only surface here.
- Involve the software vendor: many applications spread data across multiple tables or files and have their own reorganisation and checking routines.
- A new, clean target system: move recovered data into a freshly built instance, not back onto a server whose clean-up hasn't been confirmed.
- A new backup straight away: after migration, take a full backup and test the restore.
Who does what?
| Task | Responsibility |
|---|---|
| Contain the attack, establish the entry point and compromised accounts | Incident response, e.g. Cybernotfall24 |
| Secure images, analyse and reconstruct encrypted database files | Data recovery, e.g. DATA REVERSE |
| Rebuild database servers, restore, permissions | Internal IT or IT service provider, coordinated with incident response |
| Business review of the data, application logic | Users and the software vendor |
| Notification duties, e.g. GDPR Art. 33 within 72 hours | Management with the data protection officer and specialist legal counsel |
Tax advisory firms, which are usually affected on several of these levels at once, have their own overview: ransomware at a tax advisory firm.
Request a professional analysis
DATA REVERSE reconstructs databases from Microsoft SQL Server, Exchange, SharePoint, Oracle and other systems.
Useful for the request: database system and version, size and number of files, the ransom note, details of the service state before and after the attack, and a list of steps already taken.
Data recovery by system
- NAS Encrypted by Ransomware: Data Recovery for NAS Systems
- QNAP NAS Encrypted by Ransomware: Data Recovery and First Steps
- Synology NAS Encrypted by Ransomware: Data Recovery and First Steps
- Veeam Backups Encrypted or Deleted by Ransomware: What Can Still Be Recovered
- Hyper-V After Ransomware: Recovering Encrypted VHDX Files and VMs
- Proxmox VE after Ransomware: Recovering VMs, ZFS and Backups
- DATEV Data Encrypted by Ransomware: Recovery and First Steps
- Ransomware on VMware ESXi: Attack Paths, First Response and Recovery
- Ransomware on Servers, NAS, RAID or VMware: What Can Be Recovered?
Frequently asked questions
Can an MDF file encrypted by ransomware be recovered?
Sometimes, at least partially. Many ransomware families only encrypt large files in sections, and SQL Server stores data in 8 KB pages that can be identified individually and mapped to tables. Whether enough unencrypted pages survive depends on the family, variant and file size, and can only be judged by analysing a copy.
Should I run DBCC CHECKDB with REPAIR_ALLOW_DATA_LOSS?
Not on the original files and not as a first step. Microsoft itself describes this option as a last resort that may discard rows or entire pages. On a partially encrypted database, the repair would remove exactly the pages a data recovery specialist could still analyse.
The LDF file is missing or encrypted. Is the database lost?
Not necessarily. The data itself lives in the MDF and NDF files. Without the log, however, uncommitted transactions are missing and the database may not be transactionally consistent. According to Microsoft, attaching with a rebuilt log requires a clean shutdown and should only ever be attempted on copies.
Our Exchange database is in Dirty Shutdown state. Will Eseutil /p help?
Eseutil /p is a hard repair that may discard database pages, rows or entire tables. Microsoft advises making copies first and not using repair when a restore without data loss is possible. After a ransomware attack it must never be run against the original file.
Does it help to rename the encrypted database back to its original extension?
No. The extension is just a label; the encryption is in the content. Renaming also changes timestamps and traces that may matter for forensics and analysis. Work with unchanged copies instead.
Who checks whether the recovered data is actually correct?
Technical consistency checks such as DBCC CHECKDB are run on a copy. Whether bookings, documents, customer or patient records are complete and plausible can only be judged by the users and, where relevant, the vendor of the line-of-business software. Plan for this review before going back into production.
Related ransomware profiles
- Lockbit 3.0
.lockbit - Play
.PLAY - BlackSuit
.blacksuit - MEDUSA
.medusa - Akira
.akira
Read next
Sources and further reading
- [1]CISA – #StopRansomware: LockBit 3.0 (AA23-075A) cisa.gov
- [2]CISA – #StopRansomware: Medusa Ransomware (AA25-071A) cisa.gov
- [3]CISA – #StopRansomware: Play Ransomware (AA23-352A) cisa.gov
- [4]CISA – #StopRansomware: BlackSuit (Royal) Ransomware (AA23-061A) cisa.gov
- [5]Microsoft Learn – Database Files and Filegroups (SQL Server) learn.microsoft.com
- [6]Microsoft Learn – Page and Extent Architecture Guide (SQL Server) learn.microsoft.com
- [7]Microsoft Learn – DBCC CHECKDB (Transact-SQL) learn.microsoft.com
- [8]Microsoft Learn – CREATE DATABASE (Transact-SQL), FOR ATTACH_REBUILD_LOG learn.microsoft.com
- [9]Microsoft Learn – Eseutil /P Repair Mode (Exchange Server 2007, archived) learn.microsoft.com
- [10]Microsoft Learn – Extensible Storage Engine learn.microsoft.com
- [11]MySQL 8.4 Reference Manual – File-Per-Table Tablespaces dev.mysql.com
- [12]MySQL 8.4 Reference Manual – The System Tablespace dev.mysql.com
- [13]MySQL 8.4 Reference Manual – Forcing InnoDB Recovery dev.mysql.com
- [14]PostgreSQL Documentation – Database File Layout postgresql.org
- [15]PostgreSQL Documentation – Database Page Layout postgresql.org
- [16]PostgreSQL Documentation – File System Level Backup postgresql.org
- [17]Oracle Database 19c Concepts – Physical Storage Structures docs.oracle.com
- [18]DATA REVERSE – Database data recovery (German) datareverse-datenrettung.de
- [19]CISA – #StopRansomware: Akira Ransomware (AA24-109A) cisa.gov