Operator On The Wire
Join
← Back to Knowledge Base
BLUE TEAM / THREAT HUNT / ACTIVE DIRECTORY / MSSQL

Linked Servers

This note documents detection patterns related to MSSQL Linked Server Abuse within Active Directory environments.


Direct Indicators

LogEvent IDMeaningForensic ValueNotes
Security4624Successful logonMediumAuthentication associated with SQL service account or attacker account.
Security4688Process createdHighProcesses spawned due to command execution from SQL server context.
Sysmon1Process creationHighChild processes launched from sqlservr.exe due to linked server execution.
SQL Server LogsN/ALinked server query executionCriticalExecution of distributed queries across linked servers.
EDR TelemetryN/ACommand execution triggered by SQL serverCriticalIndicators of commands executed through SQL linked server abuse.
Network LogsN/AConnections between SQL serversHighNetwork activity between SQL servers used for pivoting.

Indirect Indicators

IndicatorWhat To Look ForForensic ValueNotes
Distributed queries between SQL serversEXEC AT or OPENQUERY statementsCriticalCommon linked server exploitation pattern.
Authentication using SQL service accountsService accounts authenticating to remote SQL serversHighMay indicate lateral movement.
sqlservr.exe spawning shell processescmd.exe or powershell.exe launched via SQL executionCriticalOften follows xp_cmdshell via linked server.
Unexpected network connections between SQL hostsSQL server communicating with additional SQL instancesHighPotential lateral movement.
SQL queries modifying server configurationEnabling xp_cmdshell remotelyHighUsed to escalate access through linked server.

Common Tools

ToolUsage
PowerUpSQLEnumerates and abuses SQL linked servers.
Impacket mssqlclientExecutes commands across SQL linked servers.
sqlcmdRuns distributed queries against linked servers.
Metasploit MSSQL modulesAutomates exploitation of SQL linked servers.
Custom SQL scriptsUsed for lateral movement across SQL infrastructure.

Relevant Artifacts

  • Windows Security logs (4624, 4688)
  • SQL Server query logs and audit logs
  • Sysmon logs (1 process creation)
  • EDR telemetry detecting suspicious SQL command execution
  • Network logs for communication between SQL servers
  • Prefetch artifacts for shell commands spawned by SQL processes
  • Database audit logs

MITRE ATT&CK References

  • T1021 Remote Services
  • T1047 Windows Management Instrumentation
  • T1505 Server Software Component

Decision Tree

  1. Is the suspicious event present?
    • Identify distributed SQL queries using linked servers.
  2. What host generated the event?
    • Determine which SQL server initiated the query.
  3. Is the account expected to perform this action?
    • Investigate whether account normally performs SQL administrative tasks.
  4. Pivot:
    • Source SQL server → inspect executed queries.
    • Destination SQL server → review command execution.
    • Network → analyze SQL communication between hosts.
  5. Confirm exploitation
    • Determine whether attacker used linked servers for lateral movement or command execution.

Example Detection Templates

KQL

DeviceProcessEvents
| where InitiatingProcessFileName == "sqlservr.exe"
| where FileName in ("cmd.exe","powershell.exe")
SecurityEvent
| where EventID == 4688
| where ParentProcessName has "sqlservr"

EQL

process where parent.name == "sqlservr.exe"

Sigma

title: MSSQL Linked Server Abuse
id: mssql-linked-server-abuse
status: experimental
description: Detects suspicious processes spawned from SQL Server which may indicate linked server abuse
logsource:
  product: windows
  category: process_creation
detection:
  selection:
    ParentImage|endswith: sqlservr.exe
    Image|endswith:
      - cmd.exe
      - powershell.exe
  condition: selection
fields:
  - Image
  - ParentImage
  - CommandLine
falsepositives:
  - Legitimate SQL administrative automation
level: high
tags:
  - attack.lateral_movement

Mitigation & Hardening

Control AreaMitigationEffectivenessNotes
SQL configurationRestrict linked server functionalityHighReduces lateral movement paths.
Access controlLimit SQL administrative privilegesHighPrevents unauthorized server access.
MonitoringAlert on sqlservr.exe spawning shellsHighStrong detection signal.
Network segmentationRestrict communication between SQL serversMediumLimits lateral movement.
Threat huntingReview distributed queries across serversMediumDetects suspicious activity.