How to Enable Files & Folders Level Auditing in SQL Server? – Interview Question of the Week #176

Question: How can I find out who deleted a file from a SQL Server installation folder?

A missing file in an archive leaves a trail to an audit record

A client called when SQL Server would not start. We eventually found files missing from the instance’s Binn directory. It was the second time, so restoring the files was only half the job. The client wanted to know which account and process had removed them.

This is a Windows file-system question, not a SQL Server table audit. SQL Server Audit for database activity will not reconstruct a deletion that Windows never recorded. Enable Windows file-system auditing before the next incident, and limit it to the directory and rights you need to investigate.

Enable the Windows audit policy

On the server, use Advanced Audit Policy Configuration, then Object Access, then Audit File System. Enable success auditing for a confirmed deletion. Failure auditing is optional if you also need denied attempts. In a domain, check the effective Group Policy, because a local change can be overwritten. Make this change with the server’s security administrator and confirm the Security log has enough capacity for the added events.

Add a narrowly scoped audit entry to the folder

Open the target directory’s Properties, Security, Advanced, Auditing. Add an entry for the relevant principal and choose the folder, subfolders and files scope that matches the investigation. Under advanced permissions, select Delete and Delete subfolders and files. Avoid auditing every right for every account indefinitely: the Security log can grow rapidly.

Historical Windows Advanced Security Settings Auditing tab
The original screenshot shows where the Auditing tab and Add control were located in an older Windows release. Current labels may differ.
Historical Windows audit entry with Delete rights selected
The original screenshot clearly shows the two Delete rights. It used Everyone as the principal; choose an appropriately scoped principal for your environment.

Read the Security event and corroborate it

Filter the Windows Security log for Event ID 4663. Look for the target path in Object Name, DELETE (access mask 0x10000) in Accesses, and the account and process fields. Event 4663 reports use of an audited access right; it is evidence to investigate, not by itself proof of the final file state. Correlate time, handle and process information with Event 4660 when available, the file’s actual absence, and any deployment or security software activity. A rename can also involve delete rights, so do not accuse a person based on one line.

When you save an event for investigation, retain the full path, account, process and time in your incident record. Redact private server and account details before sharing it outside your organization.

The practical lesson from my client’s incident is to configure the audit before the next startup failure. Once the files are gone, an audit policy added afterward cannot tell you who removed the earlier ones.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

Policy Management, SQL Audit, SQL Error Messages, SQL Server, SQL Server Security, Transaction Log
Previous Post
How to Write Errors in Error Log? – Interview Question of the Week #175
Next Post
How to Find Cardinality or Uniqueness for any Column? – Interview Question of the Week #177

Related Posts

2 Comments. Leave new

  • Julian Valoo
    May 31, 2018 10:35 am

    HI Pinal

    Very good solution as always

    In my opinion , I think preventing this issue from happening is a better option. I normally restrict access to the SQL server folder to only the SQL Server service accounts , in this way there should be no delete taking place. Unless there is a SQL server job that’s deleting the files accidently or some malicious activity is happening, or the process/person that’s deleting the files is using NT Authority. This is also an external audit requirement for us to prevent access to the SQL server folder or drive. This is something that’s audited on a yearly basis by an external audit firm.

    Reply
  • Darren Onekhamphoui
    June 2, 2018 12:26 am

    Nice!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.