TMA-MSSQL-2.1
Ensure 'Ad Hoc Distributed Queries' Server Configuration Option is set to '0'
MediumLevel 1Automatedmssql
Description
Enabling Ad Hoc Distributed Queries allows users to query data and execute statements on external data sources. This functionality should be disabled. Both value and value_in_use must equal 0. Default: By default, this option is disabled (0). Runs one sqlcmd query with its defaults (Windows authentication to the local default instance); set SQLCMDSERVER, SQLCMDUSER and SQLCMDPASSWORD for another instance or SQL authentication. Needs VIEW SERVER STATE / sysadmin-level read access.
How it is checked
Audit method: SQL query
sql_query
sqlcmd -b -h -1 -W -Q "SET NOCOUNT ON; SELECT CASE WHEN CAST(value AS int) = 0 AND CAST(value_in_use AS int) = 0 THEN 'compliant' ELSE 'noncompliant' END FROM sys.configurations WHERE name = 'Ad Hoc Distributed Queries';"- Expected output
compliant
How it is fixed
Fix method: SQL statement
shell
sqlcmd -b -h -1 -W -Q "SET NOCOUNT ON; EXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'Ad Hoc Distributed Queries', 0; RECONFIGURE; EXEC sp_configure 'show advanced options', 0; RECONFIGURE;"Properties
- Operating systems
- Any
- Tags
- mssqldatabasesurface-area
- Reference
- CIS Microsoft SQL Server 2025 Benchmark v1.0.0 - 2.1 Ensure 'Ad Hoc Distributed Queries' Server Configuration Option is set to '0'
Check this host
Run this on a machine you are allowed to audit. The scan is read-only.
shell
tmaegis scan --target mssql