liveBook · Manning

Control server permission

As explained in 100 SQL Server Mistakes and How to Avoid Them

The CONTROL SERVER permission is a SQL Server permission that grants control over the SQL Server instance.

Mistake 1: watching only sysadmin membership. CONTROL SERVER grants control over a SQL Server instance, and it can authorize xp_cmdshell use even when the principal is not sysadmin. Direct grants are easy to overlook, creating an opaque security path. section 14.4

The overlooked back door

A DBA may lack operating-system permissions but receive CONTROL SERVER to solve an operational problem. That access can become a back door from SQL Server to the operating system through xp_cmdshell. Review direct CONTROL SERVER grants, xp_cmdshell EXEC permissions, and IMPERSONATE paths—not only sysadmin membership. section 14.4

Lateral movement

Connects overlooked SQL Server permissions with lateral movement toward the operating system. section 14.4

Listing 14.5 Creating a trigger to prevent xp_cmdshell execution
EXEC sp_addmessage 50001, 16, 'Attempt to disable xp_cmdshell' ;
GO
 
CREATE TRIGGER prevent_xp_cmdshell
ON ALL SERVER
FOR ALTER_INSTANCE
AS
BEGIN
 DECLARE @Statement NVARCHAR(4000) ;
 
 SET @Statement = (SELECT EVENTDATA().value('(/EVENT_INSTANCE/TSQLCommand/CommandText)[1]', 
'nvarchar(4000)')) ;
 
 IF (CHARINDEX('sp_configure', @Statement) > 0)  
        AND (CHARINDEX('xp_cmdshell', @Statement) > 0)
 BEGIN
   RAISERROR(50001, 16, 1, 'Attempt to disable xp_cmdshell') WITH LOG ;
   ROLLBACK ;
 END
END ;
GO

Shows an event trigger that logs and rolls back attempts to configure xp_cmdshell. section 14.4

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Defines four authorization paths for xp_cmdshell and explains their security consequences without detailing permission-audit commands.
Examples
Uses a DBA back-door scenario and an event trigger that blocks xp_cmdshell configuration attempts.
What it assumes
Assumes familiarity with sysadmin and xp_cmdshell while clarifying that sysadmin is not the only authorization route.
What you can do after
Diagnose exposure by reviewing direct CONTROL SERVER grants and indirect impersonation or execution paths beyond sysadmin membership.
How it connects
Connects sysadmin, xp_cmdshell, EXEC permissions, xp_cmdshell proxy, IMPERSONATE, and lateral movement.

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.