Case Study: Recovering a Ransomware-Encrypted Dynamics 365 Finance & Operations Database (AxDB)
In October 2026 a paint manufacturer in Saudi Arabia was hit by ransomware. The attack encrypted the servers of its on-premises Microsoft Dynamics 365 Finance & Operations (F&O) installation, including the SQL Server data file of AxDB, the database that holds every customer, vendor, item, order, invoice, ledger entry and worker of the business. The backups had been encrypted with it.
The only clean copy of the database the company still had was from March 2025. Restoring it would have meant losing 19 months of sales, purchasing, inventory, finance and payroll. This post explains, step by step, how we recovered that period from what the attack had left behind, made the database acceptable to Dynamics 365 again, and put it back into production on the client's own servers. The client is not named.
What we had to work with
No single source was complete, so the recovery used every piece of the system that still existed:
1. The encrypted AxDB data file (MDF, about 49 GB). Ransomware of this kind does not encrypt every byte of a large file: it encrypts blocks of it, so part of the database pages were intact and part were unreadable.
2. An unencrypted older copy of AxDB, with data up to 26 March 2025. Useful as a structure donor and as the source for everything before that date.
3. The disk image of the F&O SQL server: a 321 GB Hyper-V VHDX whose first 48 MB (the VHDX headers, region table and block allocation table) were encrypted, so it could not be mounted. The SQL pages inside it were still there.
4. The original transaction log (LDF, 6.4 GB), fragmented, covering about two days of activity in October 2026.
5. A 47.9 GB SQL Server backup (.bak) from June 2026 that SQL Server refused to restore: its header was encrypted and parts of the file were encrypted or overwritten.
6. The client's F&O deployable packages (application code and their own custom model), needed later to synchronise the database schema.
Step 1: page-level recovery of the encrypted MDF
SQL Server cannot attach a partly encrypted MDF, so we did not try to. A SQL Server data file is made of 8 KB pages, and each data page identifies the table it belongs to. We read the encrypted file page by page, kept every page whose header and checksum were valid, and decoded the rows of each table using the table definitions from the March 2025 copy, which has the same structure.
The surviving rows were merged into a new database, newest version first, with the March 2025 copy filling the earlier period. The result passed DBCC CHECKDB with zero errors. Sales and purchase documents from 2021 to March 2025 were 98 to 100 percent complete. For the period after March 2025 the gaps were large: about 44 percent of 2025 sales invoices and only 23 percent of 2026 invoices were present, because the rest existed only in encrypted pages. More sources were needed.
Step 2: carving AxDB out of the damaged server VHDX
The SQL server's virtual disk could not be mounted, but the pages inside it could be found. We scanned the whole 321 GB image for SQL Server pages and found 6.28 million AxDB pages, many of them in several versions: the database file had moved and grown over the years, and older copies of pages were left behind on the disk.
Our first attempt was to assemble a complete, attachable MDF from the newest version of every page. It did not work: the newest copy of a page was not always the current one, and about 10 percent of the system-table page links pointed into other objects. A database assembled from mixed points in time cannot be trusted even if SQL Server opens it, so we abandoned that approach.
Instead we compared every page with what we had already recovered and kept only the pages that held newer data: 230,813 pages across 456 business tables. Batch, queue, temporary and event tables were left out. Those pages were decoded row by row and inserted into the recovered database insert-only, matched on RECID (the unique record ID every F&O table has). No existing row was overwritten, and the database was backed up before the merge.
Step 3: the transaction log and the broken June backup
The 6.4 GB log file was fragmented. We parsed it log block by log block, rebuilt the page-compressed row images using the table layouts of the old copy, and kept only changes from transactions that had committed and were not deleted later. That added 45 rows, including complete vouchers whose debit and credit lines balance to zero. The workflow changes in the log had all been rolled back, so none of them were used.
The June 2026 backup turned out to be more valuable. A .bak file stores the database pages in order, so even when SQL Server refuses the file, the pages can be found. We scanned 3.4 million pages out of it, matched them to AxDB tables by their allocation unit IDs, and decoded 368 tables. This gave us original rows for records that were still missing, and the original versions of records we had had to rebuild in the next step.
Step 4: fixing referential integrity, without inventing data
Dynamics 365 has very few foreign keys in SQL Server; most relations exist only in the application. After a recovery from several sources, that means a ledger line can exist without its journal header, an inventory transaction without its origin, or an invoice line without its invoice. F&O does not cope with that well, so we checked 37 key relations and found orphans throughout the post-March 2025 data: for example 45,717 general journal lines whose headers were missing, 22,298 inventory transactions without an origin and 7,786 invoice lines without an invoice journal.
Where the June backup or the VHDX had the missing parent row, the original was inserted. Where no source had it, we rebuilt the parent only when its content could be derived from surviving rows: a general journal entry from its subledger links and tax transactions, an inventory transaction origin from its link tables, a customer invoice header from its lines, the customer transaction and the tax transactions. Every rebuild rule was first tested against existing, intact rows, where it reproduced 99 to 100 percent of the values. Each rebuilt row is marked and logged in a separate audit table, so the client can always tell recovered rows from rebuilt ones.
What we did not do is invent amounts. 577 vouchers remain unbalanced because no source contains their missing lines; they were left as they are and reported to the client. Across 21.8 million related rows, 99.9 percent of relations are complete, and 59,102 of 59,117 customer invoice journals were recovered.
Step 5: why Dynamics 365 would not open the recovered database
A database with the right data is not yet a database Dynamics 365 accepts. The first test failed even though the March 2025 copy worked, and the difference was configuration, not data: read committed snapshot isolation and snapshot isolation were off, change tracking was off (F&O expects it on 54 tables), and the database had no users apart from dbo.
We also corrected the RECID sequences (some restarted at the highest existing value instead of the next one, which would have caused duplicate-key errors on the first new record), re-validated 1,229 CHECK constraints that bulk loading had left untrusted, restored 14 missing foreign keys, and fixed stale number sequences that would otherwise have reissued purchase order and lot numbers that were already used.
Each fix was written as a numbered, repeatable SQL script, tested on a restored copy and delivered in a kit, so the client's own team could see and rerun every step.
Step 6: database synchronisation and the custom models
Before F&O runs on a database, the database is synchronised with the application code: tables, fields, indexes and views are brought in line with the installed models. We ran the F&O sync engine offline against a copy, using the client's own packages, until it completed with zero errors. We then tested an upgrade to version 10.0.49 on a separate Dynamics 365 test environment, where we posted sales orders, purchase orders and payments to confirm the database worked end to end.
This uncovered the most dangerous trap of the project. The database contained data from two customisations, a sales and logistics extension and a payroll extension: 83 tables and 143 extra fields on standard tables, including payroll contracts and order remarks. The code for those models had been lost in the attack. A database sync removes tables and fields that no installed model defines, so a normal sync would have deleted that data without warning.
We therefore archived all 83 tables and the 143 fields, with their definitions, indexes and sequences, into a separate archive database before the database went live. When the client's servers ran their own automatic sync, the data stayed safe in the archive, and it can be restored as soon as the models are rebuilt.
Step 7: going live on the client's servers
The final database was restored remotely on the client's on-premises F&O environment, with the previous database kept alongside it. Starting the application servers triggered an automatic database sync, which completed. Report deployment then failed twice: the SSRS server could no longer read its encrypted content, and the F&O service account had no SSRS permissions. After both were fixed, all 1,189 reports deployed without a failure.
Sign-in failed next with 'not authorized'. The client had rebuilt their ADFS server after the attack with a new identifier, while the user records in AxDB still pointed to the old one. After backing up the user table, we updated the identity provider of 131 users and regenerated their security IDs with the same algorithm F&O uses, verified by reproducing the old IDs exactly. The administrator signed in and the company dashboard opened with its 2026 data.
Finally we tuned SQL Server memory, moved the database to the simple recovery model to bring a 17.9 GB log under control until regular backups are in place, and handed over a checklist: daily full backups, a backup of the archive database and the SSRS encryption key, a proper SQL Server licence instead of the evaluation edition used for the emergency rebuild, and no package deployment or sync without checking the custom models first.
The result: 100% successful recovery
The project ended in complete success: the company is running its business on Dynamics 365 again, sign-in works, all 1,189 reports work, and the client accepted the recovered database for production.
Dynamics 365 Finance & Operations is back in production with about 58.4 million rows, including the 2025 and 2026 sales, purchasing, inventory, finance and payroll data that existed only in encrypted files when we started. Everything that was rebuilt rather than recovered is listed in an audit table, and nothing was paid to the attackers.
Lessons for Dynamics 365 F&O on-premises owners
Keep at least one backup of AxDB offline or immutable, where a domain administrator account cannot reach it. Ransomware operators look for backups first, and here they found them.
Keep your deployable packages and the source code of your custom models outside the production environment too. Without them, a database sync after any recovery or upgrade can delete the data of those models.
After an attack, do not run REPAIR_ALLOW_DATA_LOSS, restore over the encrypted files or reinstall the servers before copying everything: the encrypted MDF, the LDF, the VHDX files and every backup, even backups that will not restore. In this case each of them contributed rows that existed nowhere else.
And do not start the application servers on a recovered database until it has been checked: an on-premises F&O environment synchronises the database by itself when it starts.
Dynamics 365, AX or SQL Server database encrypted?
We recover Dynamics 365 Finance & Operations, Dynamics AX 2012 and other ERP databases after ransomware, disk failure and failed upgrades, remotely or in our lab, for clients in India, the Gulf and worldwide. Send us the details for a free assessment: we will tell you which tables and how many records are recoverable before any work starts. No data, no charge.
Facing this problem? Contact us now.
We have already solved 656+ ransomware and data recovery cases: encrypted and corrupted SQL Server, Oracle and MySQL databases, Tally, Busy and Marg ERP data, Veeam backups, VMware and Hyper-V virtual machines, RAID and NAS. Send us the details and we tell you what we can recover.
- ✓ Free assessment before you pay anything
- ✓ No data, no charge
- ✓ NDA on request
Email: info [at] asittech.com · Mon–Fri, 9:00–18:00 IST