Have you ever experienced a scenario, where a file has been deleted from a machine and you are wondering who deleted the file and had no idea who was the culprit? Good luck! In this article, I will try to explain a technique available on the Windows machine to find out who deleted the file.

Solving the Mystery - Who deleted that file

Motivation

The urge for writing this article comes from an issue in our production environment and it might be useful for readers if ever they encounter such an issue. Our problem started when one of our production servers went out of the load balancer. We had recently deployed an Asp.net core 2.x application, which was deployed as a Self-Contained Application. In a self-contained deployment, the complete .net core framework is bundled in a folder and it also includes your asp.net core Exe which is launched by the IIS server. In our scenario, the exe was being deleted, which was causing 502.5 process error as the Host Process couldn't be started. Since the production server has restricted access, it wasn't possible that a user was deleting the file. It was a sporadic delete operation and happened on some servers while others were working fine. This was the inspiration for identifying how the exe was getting deleted. If you are interested in more details, then refer the GitHub issue.

If you couldn't follow the above reasoning, you may be able to possibly relate to the following scenario where the need to find out who deleted the file is important.

What does Windows OS offer?

Windows offers the built-in Audit feature using various policies which allow us to audit the access requests, audit login, process tracking, and more.

How to know who deleted the file?

The following 3 step process would help us in identifying who deleted the file.

  1. Turn on the File Auditing Process on the System.
  2. Configure the Audit process on the File/Folder to be monitored.
  3. Verify the Audit Logs to get details of who deleted the file.

Note
You will require the Admin permissions on the machine where the File Auditing needs to be set up.

Let's dig into these steps further in detail.

Turn on the File Auditing Process on the System.

Operating Systems offers the functionality to track various file operations. These features are configurable and can be turned Off/On using Policies. Windows uses the concepts of Policies to manage various settings which influence what can be done on the machine.

Wikipedia defines the Group Policy as, "a feature of the Microsoft Windows NT family of operating systems that controls the working environment of user accounts and computer accounts."

There are Group Policies which apply to all computers in a domain and Local Policies which apply to the local computer only. Group Policies are configured by Network admins. In this instance, we are going to change the Local Policy. Please note that windows Policies wouldn't work for Windows Home edition. You need to have a professional or enterprise edition of Windows.

Solving the Mystery - Who deleted that file

The Local Group Policy will appear as shown below.

Solving the Mystery - Who deleted that file

With the above-mentioned steps, we have enabled the File System Auditing on the Operating System. Next, we will explore how to set up logging for the Folder which needs to be monitored.

Solving the Mystery - Who deleted that file

Configure the Audit process on the File/Folder to be monitored.

Basically, in this step, we will define what kind of File System Access (Read/Write/Delete) needs to be monitored and what Users & Roles need to be tracked.

Solving the Mystery - Who deleted that file

Solving the Mystery - Who deleted that file

Solving the Mystery - Who deleted that file

Solving the Mystery - Who deleted that file
Solving the Mystery - Who deleted that file

Everyone is the name of the special group in Windows which includes almost all users.

Also, select what permissions need to be audited. Since we are looking for the Delete operation, we need to click on the "Show Advanced Permission" link and then select "Delete & Delete Subfolders and Files" checkbox and click OK button as shown below.

Solving the Mystery - Who deleted that file

Solving the Mystery - Who deleted that file

Verify the Audit Logs to get details of who deleted the file.

We have set up the Audit Policy on the Operating System and the folders in the above steps. Now, it's the time for action. The File Audit Policy will monitor and once the file is deleted from the folder along with the entry being logged into the Event Viewer. The following steps would provide more details on how to find the entry in the Event Viewer.

For demonstration purposes, I will be deleting a few files under the folder D:\FileAudit\Demo.

Solving the Mystery - Who deleted that file

What are Event IDs 4660 and 4663

4660 - This event is generated when an object is deleted. 4663 - This event indicates that a specific operation was performed on an object.

Solving the Mystery - Who deleted that file

Solving the Mystery - Who deleted that file

We can also see the object name as shown in below screenshot which was accessed. The file at location D:\FileAudit\Demo\New Text Document.txt was accessed.

Solving the Mystery - Who deleted that file
Solving the Mystery - Who deleted that file

We can get more details of the event by double-clicking the event. In the following screenshot, we can see that the Windows explorer process was used to delete the File by User Abhinav Galodha.

Solving the Mystery - Who deleted that file
Solving the Mystery - Who deleted that file

So, finally, we tracked who deleted the file.

Conclusion

This article provides a technique to add the File Auditing on the machine and then steps to identify the user who deleted the file. This technique can be extended to a similar scenario like "Who has made an unsuccessful attempt to delete a file". Also, there are various other file permissions which can be audited. Additionally, we can attach the task to an event ID. As an example, we can add a task to send the email whenever we see the file has been deleted. The event viewer is a handy tool to gather information on the System.