> For the complete documentation index, see [llms.txt](https://docs.blusapphire.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.blusapphire.io/log-forwarding/03_log-forwarding-guide/log-forward/microsoft/mssql-audit-logs-integration.md).

# MSSQL Audit logs integration

Integration Guide for **MSSQL Audit logs integration** with **BluSapphire SIEM**

#### Prerequisites

information:

• SQL Server admin / Windows admin privileges

• Access to SQL Server Management Studio

• Access to command line or PowerShell

• Access to SQL Server Configuration Manager

The Microsoft Corporation SQL Server allows setting up of auditing of server and

database activities by configuring a server audit object and then defining and

associating server audit specification and database audit specifications to it.

The Server Audit specification includes server events such as login events and server

principal changes Database Audit Specification, which includes SQL statements

executed, such as DDL and DML commands. The Database Audit specification includes

SQL statements such as DDL and DML commands.

Varying levels of auditing can be configured for the server audit and database audit

specifications and are typically configured using audit action groups. Below are

important audit action groups that are required to be configured for the purposes of

the SIEM integration.

#### Server-level audit action groups

The following list includes important audit action groups that are required to be

configured for the purposes of the SIEM integration:

• APPLICATION\_ROLE\_CHANGE\_PASSWORD\_GROUP

• AUDIT\_CHANGE\_GROUP

• DATABASE\_CHANGE\_GROUP

• DATABASE\_PRINCIPAL\_CHANGE\_GROUP

• DATABASE\_PERMISSION\_CHANGE\_GROUP

• DATABASE\_PRINCIPAL\_IMPERSONATION\_GROUP

• DATABASE\_ROLE\_MEMBER\_CHANGE\_GROUP

• FAILED\_DATABASE\_AUTHENTICATION\_GROUP

• FAILED\_LOGIN\_GROUP

• LOGIN\_CHANGE\_PASSWORD\_GROUP

• SERVER\_PERMISSION\_CHANGE\_GROUP

• SERVER\_PRINCIPAL\_CHANGE\_GROUP

• SERVER\_PRINCIPAL\_IMPERSONATION\_GROUP

• SERVER\_ROLE\_MEMBER\_CHANGE\_GROUP

• SERVER\_STATE\_CHANGE\_GROUP

• SUCCESSFUL\_DATABASE\_AUTHENTICATION\_GROUP

• USER\_CHANGE\_PASSWORD\_GROUP

#### Database-level audit action groups

• APPLICATION\_ROLE\_CHANGE\_PASSWORD\_GROUP

• AUDIT\_CHANGE\_GROUP

• DATABASE\_CHANGE\_GROUP

• DATABASE\_OBJECT\_ACCESS\_GROUP

• DATABASE\_OBJECT\_CHANGE\_GROUP

• DATABASE\_OBJECT\_PERMISSION\_CHANGE\_GROUP

• DATABASE\_PERMISSION\_CHANGE\_GROUP

• DATABASE\_PRINCIPAL\_CHANGE\_GROUP

• DATABASE\_PRINCIPAL\_IMPERSONATION\_GROUP

• DATABASE\_ROLE\_MEMBER\_CHANGE\_GROUP

• FAILED\_DATABASE\_AUTHENTICATION\_GROUP

• SUCCESSFUL\_DATABASE\_AUTHENTICATION\_GROUP

• USER\_CHANGE\_PASSWORD\_GROUP

• SELECT

• EXECUTE

• DELETE

• UPDATE

### Create a Server Audit Specification and Database Audit Specification

#### Configuring SQL Server auditing

The first step to set up SQL auditing is to create a Server Audit object which defines the audit destination, i.e., a file or Windows Event Log. Then add a Server Audit Specification object to start auditing server events, such as logon attempts or principal changes, or a Database Audit Specification object to audit SQL statements.

**Creating a SQL Server Audit object**

* 1. Open SQL Server Management Studio and connect to the relevant database instance.
  2. Expand Security, right-click on Audits, and select New Audit.
  3. Enter a name for the audit object in the Create Audit dialog.
  4. In the Audit destination drop-down list, choose Security log or File. We do not suggest using the Application log for security reasons.
  5. Click OK to create the Server Audit object.
  6. A red arrow will be displayed next to the new object’s name, which indicates a disabled object. Right-click on the audit object and select Enable audit.

*SQL script*

Alternatively, create the Server Audit object via SQL by executing the CREATE SERVER AUDIT and ALTER SERVER AUDIT commands. For example:

CREATE SERVER AUDIT myaudit\
TO \<SECURITY LOG|FILE>\
WITH (QUEUE\_DELAY=100, ON\_FAILURE=CONTINUE);\
ALTER SERVER AUDIT myaudit WITH (STATE=ON)

**Creating a SQL Server Audit Specification**

* 1. Open SQL Server Management Studio and connect to the relevant database instance.
  2. Expand Security, right-click on Server Audit Specifications, and select New Audit.
  3. Choose the Server Audit object created earlier and select the actions you want to audit.
  4. Click OK to create the Server Audit Specification object.
  5. A red arrow will be displayed next to the new object’s name, which indicates the object is disabled. Right-click on the audit object and select Enable audit.

*SQL script*

Alternatively, create the Server Audit Specification object via SQL by executing the CREATE SERVER AUDIT SPECIFICATION and ALTER SERVER AUDIT SPECIFICATION commands. For example:

CREATE SERVER AUDIT SPECIFICATION srv\_audit\_spec\
FOR SERVER AUDIT myaudit\
ADD (FAILED\_LOGIN\_GROUP)\
ALTER SERVER AUDIT SPECIFICATION srv\_audit\_spec\
FOR SERVER AUDIT myaudit\
WITH (STATE=ON)

**Creating a SQL Server Database Audit Specification**

* 1. Open SQL Server Management Studio and connect to the relevant database instance.
  2. Expand Databases > \[database\_name] > Security.
  3. Right-click on Database Audit Specifications and select New Audit.
  4. Choose the Server Audit object created earlier and select the actions you want to audit.
  5. Click OK to create the Database Audit Specification object.

*SQL script*

Alternatively, create the Database Audit Specification object via SQL by executing the CREATE DATABASE AUDIT SPECIFICATION and ALTER DATABASE AUDIT SPECIFICATION commands. For example:

CREATE DATABASE AUDIT SPECIFICATION mydb\_audit\_spec\
FOR SERVER AUDIT myaudit\
ADD (SELECT ON OBJECT::\[Production].\[Product] BY \[Peter])\
ALTER DATABASE AUDIT SPECIFICATION mydb\_audit\_spec\
FOR SERVER AUDIT myaudit\
ADD (SELECT\
ON OBJECT::dbo.Table1\
by dbo)\
WITH (STATE = ON);

#### Verifying SQL Server audit logs

Check the Security and Application logs for SQL Server auditing events. If the Security log doesn’t contain any SQL Server auditing events, check the Application log for event ID 33204, which indicates a failure to write to the Security log.

There are three key requirements for SQL Server to write events to the Security log:

* The Audit object access security policy and Audit Application Generated advanced audit policy must be enabled. These settings are usually controlled by the domain group policy, which overwrites the local policy settings.
* The SQL Server service account must be able to write to the Security log. The LOCAL SERVICE and NETWORK SERVICE accounts have permission by default.
* The SQL Server service account must be able to create an entry under the HKEY\_LOCAL\_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Security registry key. To grant the account permission:

1. Open the Registry Editor (regedit.exe).
2. Navigate to HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Security.
3. Right-click on the key name and select Permissions…
4. Add the SQL Server service user and assign it Full Control.
5. Disable, then re-enable the Server Audit object so SQL Server attempt to recreate the MSSQLSERVER$AUDIT sub-key.
6. Once the key is created, you may remove the Full Control access permission since it is no longer required.
