{"id":2498,"date":"2019-03-31T15:01:59","date_gmt":"2019-03-31T12:01:59","guid":{"rendered":"http:\/\/kifarunix.com\/?p=2498"},"modified":"2019-03-31T19:23:19","modified_gmt":"2019-03-31T16:23:19","slug":"enable-mssql-server-and-database-level-auditing","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/enable-mssql-server-and-database-level-auditing\/","title":{"rendered":"Enable MSSQL Server and Database Level Auditing"},"content":{"rendered":"<p class=\"\">This guide describes how to enable MSSQL server and database level auditing. Database auditing basically involves capturing and\u00a0 monitoring database activities. The server-level audit involves server operations, such as management changes and logon and logoff operations while database level auditing involves actions such as data manipulation languages (DML) and data definition language (DDL) operations.<\/p>\n<h3>Enable MSSQL Server and Database Level Auditing<\/h3>\n<p>In this guide, we are going to learn how to enable MSSQL server and database level auditing using SQL server 2017 (evaluation copy) using SQL Server Management Studio.<\/p>\n<p>Login to your SQL server 2017 using SSMS.<\/p>\n<p><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/ssms.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2503\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/ssms.png\" alt=\"enable MSSQL server and database level auditing\" width=\"1507\" height=\"373\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/ssms.png 1507w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/ssms-768x190.png 768w\" sizes=\"(max-width: 1507px) 100vw, 1507px\" \/><\/a><\/p>\n<h4>Create SQL Database Level Audit<\/h4>\n<p>To create SQL database level audit, navigate to <code>Security<\/code> &gt; <code>Audits<\/code>. Right click on Audits and click <code>New Audit<\/code>.<\/p>\n<p><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/sql-new-audit.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2504\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/sql-new-audit.png\" alt=\"enable MSSQL server and database level auditing\" width=\"1025\" height=\"468\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/sql-new-audit.png 1025w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/sql-new-audit-768x351.png 768w\" sizes=\"(max-width: 1025px) 100vw, 1025px\" \/><\/a><\/p>\n<p>On the window that opens up, set the Audit name, Audit destination (File), Audit File path, maximum Audit file size and leave the other options with default settings. To see a description of each options, check <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/relational-databases\/security\/auditing\/create-a-server-audit-and-database-audit-specification?view=sql-server-2017\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n<p><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/new-audit-options.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2505\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/new-audit-options.png\" alt=\"enable MSSQL server and database level auditing\" width=\"675\" height=\"711\" title=\"\"><\/a><\/p>\n<p>Once you are done configuring the Audit options, click <code>Ok<\/code> to save it.<\/p>\n<p>Next, navigate to <code><strong>Databases<\/strong><\/code><strong> &gt; <code>Expand database you want to enable audit (card-data in my case)<\/code> &gt; <code>Security<\/code> &gt; <code>Database Audit Specifications<\/code><\/strong>.<\/p>\n<p>Right click on <code>Database Audit Specifications<\/code> and click <code>New Database Audit Specifications<\/code> to create new database audit. On the window that opens up, set the name of the database audit, Select the Audit you created above from the drop down. Next, select the audit type actions.<\/p>\n<p><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/database-audit-spec.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2506\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/database-audit-spec.png\" alt=\"enable MSSQL server and database level auditing\" width=\"672\" height=\"716\" title=\"\"><\/a><\/p>\n<p>For demonstration purposes, we selected the:<\/p>\n<ul>\n<li><code>DATABASE_PRINCIPAL_CHANGE_GROUP<\/code> which triggers an event when principals such as users are created, altered or dropped from a database.<\/li>\n<li><code>SCHEMA_OBJECT_CHANGE_GROUP<\/code> which triggers an event when a CREATE, ALTER, or DROP operation is performed on a schema.<\/li>\n<\/ul>\n<p>You can read more about Audit Action Groups and Actions <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/relational-databases\/security\/auditing\/sql-server-audit-action-groups-and-actions?view=sql-server-2017\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. Once done setting the audit actions and action groups, click Ok to save the audit.<\/p>\n<p>Be careful when selecting the audit actions and groups. Otherwise, you may end end up with millions of audit events.<\/p>\n<p>Now that we have the Audit itself and the database audit specification, they are disabled. To enable the audit, right click on the audit and select <code>Enable Audit<\/code>.<\/p>\n<p><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/enable-audit.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2508\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/enable-audit.png\" alt=\"enable MSSQL server and database level auditing\" width=\"731\" height=\"344\" title=\"\"><\/a><\/p>\n<p>Next, enable the database audit specification by right clicking on the database audit and selecting <code>Enable Database Audit Specification<\/code>.<\/p>\n<p><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/enable-db-specification.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2507\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/enable-db-specification.png\" alt=\"enable MSSQL server and database level auditing\" width=\"1005\" height=\"569\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/enable-db-specification.png 1005w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/enable-db-specification-768x435.png 768w\" sizes=\"(max-width: 1005px) 100vw, 1005px\" \/><\/a><\/p>\n<h3>Test Auditing<\/h3>\n<p>Now that you have created and enabled the database level auditing for your database, run some tests to verify if the events are being captured. To begin with,based on our audit action groups selected above, create and drop a database user and check the audit logs.<\/p>\n<p>Navigate to <strong>Security &gt; Logins &gt; Right click on Logins &gt; New Login<\/strong>. On the new window, enter the username, set define the authentication method (Using SQL Server authentication in my case). You can opt to enforce password policy. Under Default database, select the database on which we enabled audit from the drop-down. To map the user to your database, click on User Mappings and check the database you want to map the user to. Click Ok to save the user.<\/p>\n<p><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/newlogin.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2509\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/newlogin.png\" alt=\"enable MSSQL server and database level auditing\" width=\"701\" height=\"640\" title=\"\"><\/a><\/p>\n<p>Now, drop the database user created. Navigate to <strong>Databases &gt; your-database (card-data in my case) &gt;\u00a0 Security &gt; Users &gt; Right Click<\/strong> on user created &gt; <strong>Delete<\/strong> &gt; <strong>Ok<\/strong>.<\/p>\n<p>You should now be able to see two events, create and drop user. Navigate to <strong>Security &gt; Audits &gt; Right Click <\/strong>on audit you created &gt;<strong>View Audit Logs<\/strong>. Expand the log viewer to see more audit log details.<\/p>\n<p><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/audit-logs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2510\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/audit-logs.png\" alt=\"enable MSSQL server and database level auditing\" width=\"1033\" height=\"461\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/audit-logs.png 1033w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/audit-logs-768x343.png 768w\" sizes=\"(max-width: 1033px) 100vw, 1033px\" \/><\/a><\/p>\n<p>You can also query the audit log file saved under <code>C:\\Audits\\CardData<\/code>. The query below selects specific fields of the log file.<\/p>\n<pre>select event_time, action_id,server_principal_name,database_principal_name,database_name,object_name,statement,client_ip,application_name\r\nfrom sys.fn_get_audit_file ('C:\\Audits\\CardData\\*.sqlaudit',default,default) order by event_time DESC<\/code><\/pre>\n<p><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/query-audit-log.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2511\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/query-audit-log.png\" alt=\"enable MSSQL server and database level auditing\" width=\"1717\" height=\"494\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/query-audit-log.png 1717w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/query-audit-log-768x221.png 768w\" sizes=\"(max-width: 1717px) 100vw, 1717px\" \/><\/a><\/p>\n<p>To query all the fields, use <code>select * from sys.fn_get_audit_file ('C:\\Audits\\CardData\\*.sqlaudit',default,default)<\/code>.<\/p>\n<h3>Server-Level Audit<\/h3>\n<p>To enable server level audit, Navigate to <strong>Security &gt; Server Audit Specifications &gt; Right Click<\/strong> on Server Audit Specifications &gt; <strong>New Server Audit Specifications<\/strong>. Set the name of the audit, choose the audit created earlier on the drop down. Choose the audit action types. In my case, I would like to see the authentication events to the database. Hence, have selected <code>SUCCESSFUL_LOGIN_GROUP<\/code>, <code>FAILED_LOGIN_GROUP<\/code> and <code>LOGOUT_GROUP<\/code>.<\/p>\n<p><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/server-audits.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2512\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/server-audits.png\" alt=\"enable MSSQL server and database level auditing\" width=\"670\" height=\"715\" title=\"\"><\/a><\/p>\n<p>After that, enable the audit by right clicking the name of the server audit defined &gt; Enable Server Audit Specification.<\/p>\n<p>Perform the three events; successful, failed login and logout to the database. Ensure that you are using the SQL authentication method to login to the database.<\/p>\n<p><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/sql-auth.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2513\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/sql-auth.png\" alt=\"enable MSSQL server and database level auditing\" width=\"485\" height=\"321\" title=\"\"><\/a><\/p>\n<p>Under Options, select the database to login to. Once you have performed the three authentication events above, view the audit logs to check if any event was captured.<\/p>\n<p><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/autheneticationlogs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2514\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/autheneticationlogs.png\" alt=\"enable MSSQL server and database level auditing\" width=\"1027\" height=\"606\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/autheneticationlogs.png 1027w, https:\/\/kifarunix.com\/wp-content\/uploads\/2019\/03\/autheneticationlogs-768x453.png 768w\" sizes=\"(max-width: 1027px) 100vw, 1027px\" \/><\/a><\/p>\n<p>Well, that is all about how to enable MSSQL server and database level auditing. In our next article, we are going to learn about to monitor MSSQL database activities using AlienVault SIEM. Stay connected.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide describes how to enable MSSQL server and database level auditing. Database auditing basically involves capturing and\u00a0 monitoring database activities. The server-level audit involves<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[299,121,372],"tags":[373,303],"class_list":["post-2498","post","type-post","status-publish","format-standard","hentry","category-database","category-howtos","category-mssql","tag-database-audit","tag-mssql","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2498"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=2498"}],"version-history":[{"count":5,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2498\/revisions"}],"predecessor-version":[{"id":2520,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/2498\/revisions\/2520"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=2498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=2498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=2498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}