There is requirement that we need to perform database analysis on invalid entires into the database. We need to trace or track the entries performed in the database. But to do that we need a proper way to do it.

how to test#

In this guide we will make a test database in called Tweety in Microsoft SQL Server 2017 and connect to it using Microsoft SQL Server Management Studio.

testing environment#

server#

The test is being conducted in Microsoft Windows Server 2016. Version: 1607 (OS Build 14393.693)

sql server information#

Microsoft SQL Server Express (64-bit)
Version: 14.0.1000.169

access information#

username : sa password : abcd@1234

virtualization information#

The VM is running in ProxMox server with 4 core cpu and 4 gb of RAM having 50 GB of disk space on NVMe disk.

Theory#

Audit Specification#

We can create two types of audit specification.

Database Audit Specification#

Server Audit Specification#

experiments#

Below we will check how to detect various issues and try to detect them in the audit / log file.

enable audit#

To do this you need to first enable the database audit in the MSSQL server. To do this first you need to enable the “Audits” under the security tree after you login to the server using MSSQL Management Studio.

ad3d1cba6afb1b994f1bc4b0b0afc6a8.png

After you have clicked on the item, we will be able to see another windows.

7276a08db242d1123f8f889de4cac5ce.png

In this window, you need to enter only the path where the audit files will be stored. In production environment we can move the audit to another disk which might have a separate RAID system for maximum storage capacity. You can also change the parameters according to your needs. When all changes has been done, click on OK to move forward.

Now you have to enable the Audit. Right click on the newly created audit and click on the Enable Audit as shown below: e0cbd7274ef77dfda24ec72834599c75.png

If the audit has enabled successfully, you will see a success message box as below: fdc50d86d394e2085f2d2eb81e194d7f.png

As of now we have enabled the audit and can see record. By again right clicking on the newly created audit object and then selecting View Audit Logs from the menu as shown below: 797814c73302b624ea441aa8827790ff.png

The Log File Viewer will display some logs which will tell us that the Audit system has been successfully configured and running. The screenshot can be seen below: 704d156b99f364561f6b4bbd19c732c6.png

As of now, we have only configured the log part and nothing else. We have not selected which items we have to monitor. In the next step we will configure login failure audits.

login failure audit#

In the last step we have enabled audit and now we will enable a specific audit for login failure. In the last screenshot of Log Viewer we have also seen that no log for login success / failure was not seen.

We need to create a new specification by following the steps shown below: 6c0b4d62001545cef3b4ac7fbfca1d22.png

It will show a window called Create Server Audit Specification. In this window we will select Audit Action Type as FAILED_LOGIN_GROUP (Details [1]). For details please check the screenshot below: 5bd1f3c93080dc425ba341ddf0e00237.png

And from the Audit you will have to select our newly created audit. Now click OK to create a new specification.

Like last time, you will have to enable this specification in order to make it work. You will also shown a success if the specification was successfully enabled. 397f1c60b0b5e2824ddabde1fe544201.png

Now we will close the Management Studio and attempt to login using a incorrect password and then go back to the View Audit Logs window to check what is the reflection we can see in the audit logs.

f69f334e965f69bd4afaea45b1d54d45.png

As we can see that the Log File Viewer can successfully show us the log that an user tried to access the server using an incorrect password.

After selecting the log entry, details can also be seen in the bottom segment of the windows where we get the following information:

Statement		Login failed for user 'sa'. Reason: Password did not match that for the login provided. [CLIENT: <local machine>]

insert log#

In this section we will look into how to get a log if you are performing some insert operation in a database’s table.

Version information#

For this to work, you will have to have Microsoft SQL Server Enterprise edition where you can enable the Common Criteria compliance. How to enable this has been given below. 1fe93ba2d6c3fa24a0d5b857505c39e8.png

reference#

  1. https://docs.microsoft.com/en-us/sql/relational-databases/security/auditing/sql-server-audit-action-groups-and-actions?view=sql-server-ver15
  2. https://www.sqlshack.com/various-techniques-to-audit-sql-server-databases/