Recovering SQL Server, Exchange & Databases After Ransomware

Ransomware Reverse Editorial TeamLast technical review:

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

ActionWhy it hurts
DBCC CHECKDB … REPAIR_ALLOW_DATA_LOSSMay deallocate rows, pages or ranges of pages; according to Microsoft, deallocated data is no longer accessible or recoverable.[7]
eseutil /p on the EDBHard repair at page and table level that may discard rows or entire tables.[9]
Attaching with a rebuilt log (FOR ATTACH_REBUILD_LOG) or via Management StudioRequires a clean shutdown, breaks the log backup chain and writes to the files.[8]
Starting the database engine on the original filesCrash recovery runs at startup and modifies data and log files.
innodb_force_recovery at 4 or higherAccording to the MySQL manual, can permanently corrupt data files.[13]
Renaming encrypted filesDoesn't undo the encryption, but alters metadata and traces.
Restoring "over" the encrypted databaseOverwrites regions that may still contain unencrypted pages.
Cleaning up, defragmenting or reclaiming space on the volumeDeleted 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.[1] For Medusa, CISA describes the encryptor terminating all services related to backups, security, databases, communication, file sharing and websites.[2]

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]
Not every file is fully encryptedFully encrypted: Content cannot be rebuilt without the key – backup or decryptor needed. File header only: Content survives; the header can often be rebuilt. Intermittent (every n-th block): Large files such as VMDKs or databases are often partly usable. Interrupted: The unencrypted remainder can be used directly. encryptednot encryptedFully encryptedContent cannot be rebuilt without thekey – backup or decryptor neededFile header onlyContent survives; the header can oftenbe rebuiltIntermittent (every n-thblock)Large files such as VMDKs or databasesare often partly usableInterruptedThe unencrypted remainder can be useddirectly © 2026 ransomware-reverse.de
Not every file is fully encryptedFully encrypted: Content cannot be rebuilt without the key – backup or decryptor needed. File header only: Content survives; the header can often be rebuilt. Intermittent (every n-th block): Large files such as VMDKs or databases are often partly usable. Interrupted: The unencrypted remainder can be used directly. encryptednot encryptedFully encryptedContent cannot be rebuilt without the key – backup ordecryptor neededFile header onlyContent survives; the header can often be rebuiltIntermittent (every n-th block)Large files such as VMDKs or databases are often partlyusableInterruptedThe unencrypted remainder can be used directly © 2026 ransomware-reverse.de
Not every file is fully encrypted. Many ransomware families encrypt only parts of large files to save time. Which pattern applies depends on family and configuration and only shows in an analysis of disk images.

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.[6] A single unencrypted page can therefore be recognised and assigned to a table – even if the file's allocation pages are encrypted. Arithmetically, an unencrypted 1 MiB section holds 128 such pages.

PostgreSQL also uses fixed-size pages, usually 8 kB.[15] InnoDB (MySQL) and Exchange's ESE engine organise their files in pages as well. That is why whole tables, or large parts of them, can often be extracted from partially encrypted databases – provided the pages are read out rather than thrown away by a repair.

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 .bak or 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 patternWhat is often still possibleWhat to avoid
MDF/NDF partially encryptedRead out unencrypted pages, map them to tables, export records into a new databaseAttach attempts, CHECKDB repair on the original
MDF intact, LDF missing or encryptedAttach a copy without the log if the shutdown was clean; otherwise page-based reconstructionRebuilding the log on the original file
.bak files encryptedAnalyse unencrypted sections; uncompressed backups hold data pages in clearRestoring damaged backups onto the production system
Exchange EDB encryptedReconstruct mailboxes and items from readable ESE pageseseutil /p, deleting log files
EDB readable but in Dirty ShutdownCheck the log chain on a copy, soft recovery on the copy"Tidying up" log files, hard repair on the original
MySQL: ibdata1 and .ibd encryptedPer-table analysis of the .ibd files, matched against the data dictionaryinnodb_force_recovery ≥ 4 on originals
PostgreSQL data directory encryptedReconstruction from relation files, WAL and system catalogueCopying individual files into another cluster
Database inside an encrypted VMFirst the VHDX/VMDK and guest file system, then the database filesConsolidating 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.[5] The extensions are recommendations, not rules – line-of-business products sometimes use other names. For analysis, what counts is securing every file of the database completely, even when they are spread across different drives.

The log contains no pages, but a series of variable-length log records.[6] It is not a substitute for an encrypted MDF, but it can supply the most recent changes.

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.[8] After an attack, whether the shutdown was clean is often unknown. Such attempts therefore belong exclusively on a copy, on an isolated test instance.

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.[7] Once the log has been rebuilt, Microsoft notes there is no full ACID guarantee; logical consistency has to be validated manually.[7]

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).[9] ESE protects transactions with a write-ahead log so that data stays consistent after a crash.[10] An Exchange database is therefore not just the EDB, but also its log files and checkpoint file. Secure the entire database and log directory.

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.[9]

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.[11] Alongside it sits the system tablespace, by default ibdata1.[12] If only some .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.[13]

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.[14] Crucial for recovery: individual table files are unusable without the commit status held in pg_xact.[16] The data directory must therefore always be secured in full, not just "the important files".

Oracle: an Oracle database consists of data files, control files and online redo log files.[17] If one of these components is missing or encrypted, the recovery path changes considerably. The same rule applies: secure every file, make no recovery attempts on the originals.

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.

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:

  1. Technical consistency on a copy: DBCC CHECKDB without a repair option for SQL Server, plus DBCC CHECKCONSTRAINTS where referential dependencies exist, as Microsoft recommends after repairs.[7] For other systems, the engine's own checking tools.
  2. 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?
  3. 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.
  4. Involve the software vendor: many applications spread data across multiple tables or files and have their own reorganisation and checking routines.
  5. 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.
  6. A new backup straight away: after migration, take a full backup and test the restore.

Who does what?

TaskResponsibility
Contain the attack, establish the entry point and compromised accountsIncident response, e.g. Cybernotfall24
Secure images, analyse and reconstruct encrypted database filesData recovery, e.g. DATA REVERSE
Rebuild database servers, restore, permissionsInternal IT or IT service provider, coordinated with incident response
Business review of the data, application logicUsers and the software vendor
Notification duties, e.g. GDPR Art. 33 within 72 hoursManagement 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.[18] Details are on the page database data recovery at DATA REVERSE (in German) (external link). It starts with an analysis of the unchanged files or images. Only then can anyone reliably say which tables or mailboxes can be recovered and how completely – there is no promise up front.

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

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

Read next

Sources and further reading

  1. [1]CISA – #StopRansomware: LockBit 3.0 (AA23-075A) cisa.gov
  2. [2]CISA – #StopRansomware: Medusa Ransomware (AA25-071A) cisa.gov
  3. [3]CISA – #StopRansomware: Play Ransomware (AA23-352A) cisa.gov
  4. [4]CISA – #StopRansomware: BlackSuit (Royal) Ransomware (AA23-061A) cisa.gov
  5. [5]Microsoft Learn – Database Files and Filegroups (SQL Server) learn.microsoft.com
  6. [6]Microsoft Learn – Page and Extent Architecture Guide (SQL Server) learn.microsoft.com
  7. [7]Microsoft Learn – DBCC CHECKDB (Transact-SQL) learn.microsoft.com
  8. [8]Microsoft Learn – CREATE DATABASE (Transact-SQL), FOR ATTACH_REBUILD_LOG learn.microsoft.com
  9. [9]Microsoft Learn – Eseutil /P Repair Mode (Exchange Server 2007, archived) learn.microsoft.com
  10. [10]Microsoft Learn – Extensible Storage Engine learn.microsoft.com
  11. [11]MySQL 8.4 Reference Manual – File-Per-Table Tablespaces dev.mysql.com
  12. [12]MySQL 8.4 Reference Manual – The System Tablespace dev.mysql.com
  13. [13]MySQL 8.4 Reference Manual – Forcing InnoDB Recovery dev.mysql.com
  14. [14]PostgreSQL Documentation – Database File Layout postgresql.org
  15. [15]PostgreSQL Documentation – Database Page Layout postgresql.org
  16. [16]PostgreSQL Documentation – File System Level Backup postgresql.org
  17. [17]Oracle Database 19c Concepts – Physical Storage Structures docs.oracle.com
  18. [18]DATA REVERSE – Database data recovery (German) datareverse-datenrettung.de
  19. [19]CISA – #StopRansomware: Akira Ransomware (AA24-109A) cisa.gov