liveBook · Manning

Lateral movement

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

Lateral movement is an attacker's progression from one compromised system or account to additional systems within an environment.

Lateral movement is an attacker’s progression from one compromised system or account to additional systems inside an environment. In SQL Server environments, a compromised instance can become a bridge to other servers or to the operating system. section 14.4

Mistake: treating a privileged SQL Server feature as harmless because trusted administrators can use it.

  • Enabling xp_cmdshell lets commands run in the operating-system context of the SQL Server service account, which may be highly privileged. section 14.4
  • A coarse-grained service account can extend the compromise to other SQL Server instances through privileged credentials or linked servers. section 14.4
  • An attacker may move from SQL Server to the operating system, use an SMB interception attack, and expose credentials with access elsewhere. section 14.4
  • Keep xp_cmdshell disabled, alert when someone attempts to enable it, and audit administrative activity. section 14.8

The compromised SQL Server hop

An attacker compromises one SQL Server instance and uses xp_cmdshell to reach its operating system. Because commands run under the SQL Server service account, the attacker may discover or reuse privileged access to other servers, turning one breach into a wider network compromise. section 14.4

Lateral movement

Use the lateral-movement figure to trace how a vulnerable SQL Server can connect an attacker to the operating system and other servers. 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

Use the server trigger listing as a concrete control that blocks attempts to re-enable xp_cmdshell and records the event. section 14.4

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

How deep it goes
Explains service-account execution, linked servers, credential spoofing, and SMB interception without detailing complete attack procedures.
Examples
Uses a compromised SQL Server, operating-system command execution, linked servers, privileged credentials, and SMB interception as concrete attack paths.
What it assumes
Assumes familiarity with SQL Server instances, service accounts, server roles, linked servers, and operating-system access.
What you can do after
Operate and configure SQL Server defenses by disabling xp_cmdshell, alerting on enablement attempts, and auditing administrative activity.
How it connects
Connects lateral movement with xp_cmdshell, service accounts, linked servers, SMB interception, SQL injection, and administrative auditing.

Also explained in

Compare how 3 books explain lateral movement →

Related concepts

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.