TMA-MSSQL2022-5.4
Ensure 'SQL Server Audit' is set to capture both 'failed' and 'successful logins'
Description
SQL Server Audit is capable of capturing both failed and successful logins and writing them to one of three places: the application event log, the security event log, or the file system. We will use it to capture any login attempt to SQL Server, as well as any attempts to change audit policy, changes in privileged role memberships and changes to server settings. This will also serve to be a second source to record failed login attempts. By utilizing Audit instead of the traditional setting under the Security tab to capture successful logins, we reduce the noise in the ERRORLOG. This keeps it smaller and easier to read for DBAs who are attempting to troubleshoot issues with the SQL Server. Also, the Audit object can write to the security event log, though this requires operating system configuration. This gives an additional option for where to store login events, especially in conjunc...
How it is checked
Audit method: SQL query
sqlcmd -b -h -1 -W -Q "SET NOCOUNT ON; SELECT CASE WHEN COUNT(DISTINCT SAD.audit_action_id) >= 6 + CASE WHEN EXISTS (SELECT 1 FROM sys.databases WHERE containment = 1) THEN 2 ELSE 0 END THEN 'compliant' ELSE 'noncompliant' END FROM sys.server_audit_specification_details AS SAD JOIN sys.server_audit_specifications AS SA ON SAD.server_specification_id = SA.server_specification_id JOIN sys.server_audits AS S ON SA.audit_guid = S.audit_guid WHERE S.is_state_enabled = 1 AND SA.is_state_enabled = 1 AND SAD.audited_result LIKE '%SUCCESS%' AND SAD.audited_result LIKE '%FAILURE%' AND (SAD.audit_action_id IN ('CNAU','LGFL','LGSD','ADDP','ADSP','OPSV') OR (SAD.audit_action_id IN ('DAGS','DAGF') AND EXISTS (SELECT 1 FROM sys.databases WHERE containment = 1)));"- Expected output
compliant
How it is fixed
Fix method: Guidance or infrastructure patch
For AWS RDS Instances, please refer to the documentation for configuring SQL Server Audit here: SQL Server Audit Perform either the GUI or T-SQL method shown: GUI Method 1. Expand the SQL Server in Object Explorer. 2. Expand the Security Folder 3. Right-click on the Audits folder and choose New Audit... 4. Specify a name for the Server Audit. 5. Specify the audit destination details and then click OK to save the Server Audit. 6. Right-click on Server Audit Specifications and choose New Server Audit Specification... 7. Name the Server Audit Specification 8. Select the just created Server Audit in the Audit drop-down selection. 9. Click the drop-down under Audit Action Type and select AUDIT_CHANGE_GROUP. 10. Click the new drop-down Audit Action Type and select FAILED_LOGIN_GROUP. 11. Click the new drop-down under Audit Action Type and select SUCCESSFUL_LOGIN_GROUP. 12. Click the new drop-down under Audit Action Type and select DATABASE_ROLE_MEMBER_CHANGE_GROUP. 13. Click the new drop-down under Audit Action Type and select SERVER_ROLE_MEMBER_CHANGE_GROUP. 14. Click the new drop-down under Audit Action Type and select SERVER_OPERATION_GROUP. 15. Click the new drop-down under Audit...
Properties
- Operating systems
- Any
- Tags
- loggingmssqlsqlserver-2022
- Reference
- CIS Microsoft SQL Server 2022 Benchmark v1.3.0 - 5.4 Ensure 'SQL Server Audit' is set to capture both 'failed' and 'successful logins'
Check this host
Run this on a machine you are allowed to audit. The scan is read-only.
tmaegis scan --target mssql