Detection rules › Splunk

Windows PowerShell Invoke-Sqlcmd Execution

Author
Michael Haag, Splunk
Source
upstream

This detection identifies potentially suspicious usage of Invoke-Sqlcmd PowerShell cmdlet, which can be used for database operations and potential data exfiltration. The detection looks for suspicious parameter combinations and query patterns that may indicate unauthorized database access, data theft, or malicious database operations. Threat actors may prefer using PowerShell Invoke-Sqlcmd over sqlcmd.exe as it provides a more flexible programmatic interface and can better evade detection.

MITRE ATT&CK coverage

TacticTechniques
ExecutionT1059.001 Command and Scripting Interpreter: PowerShell, T1059.003 Command and Scripting Interpreter: Windows Command Shell

Event coverage

ProviderEvent IDTitle
PowerShell4104Creating Scriptblock text (MessageNumber of MessageTotal).

Stages and Predicates

Stage 1: search

search EventCode=4104 ScriptBlockText="*invoke-sqlcmd*"

Stage 2: eval

eval ... using (ScriptBlockText)

Stage 3: eval

eval ... using (script_lower)

Stage 4: eval

eval ...

Stage 5: eval

eval ... using (has_admin_conn, has_cert_bypass, has_data_exfil, has_suspicious_auth, has_suspicious_query, has_url_input)

Stage 6: eval

eval ... using (1, script_lower)

Stage 7: eval

eval ... using (command_type, has_admin_conn, has_cert_bypass, has_data_exfil, has_suspicious_auth, has_suspicious_query, has_url_input)

Stage 8: eval

eval ... using (risk_factors)

Stage 9: where

where risk_score>=30

Stage 10: stats

stats BY EventCode, ScriptBlockText, UserID, Computer, risk_message, risk_score, command_type

Stage 11: rename

rename

Stage 12: search

search

Stage 13: search

search

Stage 14: search

search `macro`

Indicators

Each row is a field, operator, and value that the rule matches. The corpus column counts how many other rules in the catalog look for the same combination: high numbers point to widely-used, community-vetted indicators. Blank or 1 shows that the indicator is specific to this rule.

FieldKindValues
EventCodeeq
  • 4104 corpus 108 (splunk 108)
ScriptBlockTexteq
  • "*invoke-sqlcmd*"
risk_scorege
  • 30

Neighbors

Broader alternatives (more inclusive than this rule)

These rules match a superset of what this rule catches. They cover the same events plus more. Use them if you want wider coverage and can absorb more false positives.