- Run SQL Management Studio and execute the following T-SQL code to create and enable a SQL Server audit and a SQL Server audit specification, adjusting the path to the logs as needed:
USE master ;
GO
-- Create the server audit.
CREATE SERVER AUDIT AuditSQL
TO FILE ( FILEPATH ='\\SQL\Audit\' )
WITH ( QUEUE_DELAY = 1000, ON_FAILURE = CONTINUE );
GO
-- Create the server audit specification.
CREATE SERVER AUDIT SPECIFICATION Change_Object_Permissions
FOR SERVER AUDIT AuditSQL
ADD (SCHEMA_OBJECT_PERMISSION_CHANGE_GROUP);
GO
-- Enable the server audit.
ALTER SERVER AUDIT AuditSQL
WITH (STATE = ON);
GO
-- Enable the server audit specification.
ALTER SERVER AUDIT SPECIFICATION Change_Object_Permissions
WITH (STATE = ON);
GO
-- Move it to the target database.
USE DBNAME;
GO
-- Create and enable the database audit specification.
CREATE DATABASE AUDIT SPECIFICATION Change_Object_Permissions
FOR SERVER AUDIT AuditSQL
ADD (SCHEMA_OBJECT_PERMISSION_CHANGE_GROUP)
WITH (STATE = ON);
GO
- To view object permissions changes, execute the following code in SQL Management Studio, adjusting the path to the logs as needed:
SELECT * FROM sys.fn_get_audit_file ('SQL\\Audit\*',default,default)
WHERE action_id like 'G'
- Open the file produced by the script in MS Excel.
- Run Netwrix Auditor → Navigate to "Search" → Click on "Advanced mode" if not selected → Set up the following filters:
- Filter = "Data Source"
Operator = "Equals"
Value = "SQL Server" - Filter – "Object type"
Operator – "Equals"
Value – "View"
- Filter = "Data Source"
- Click the "Search" button and review what changes were made to view permissions.