Detection rules › Splunk
Windows PowerShell Invoke-Sqlcmd Execution
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
| Tactic | Techniques |
|---|---|
| Execution | T1059.001 Command and Scripting Interpreter: PowerShell, T1059.003 Command and Scripting Interpreter: Windows Command Shell |
Event coverage
| Provider | Event ID | Title |
|---|---|---|
| PowerShell | 4104 | Creating 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.
| Field | Kind | Values |
|---|---|---|
EventCode | eq |
|
ScriptBlockText | eq |
|
risk_score | ge |
|
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.
- Potential PowerShell Obfuscation via Invalid Escape Sequences (drops 2 filters this rule applies)
- Potential PowerShell Obfuscation via Backtick-Escaped Variable Expansion (drops 2 filters this rule applies)
- Potential PowerShell Obfuscation via Character Array Reconstruction (drops 2 filters this rule applies)
- Potential PowerShell Obfuscation via Concatenated Dynamic Command Invocation (drops 2 filters this rule applies)
- Potential PowerShell Obfuscation via High Numeric Character Proportion (drops 2 filters this rule applies)
- Potential Dynamic IEX Reconstruction via Environment Variables (drops 2 filters this rule applies)
- Dynamic IEX Reconstruction via Method String Access (drops 2 filters this rule applies)
- PowerShell Obfuscation via Negative Index String Reversal (drops 2 filters this rule applies)
- Potential PowerShell Obfuscation via Reverse Keywords (drops 2 filters this rule applies)
- Potential PowerShell Obfuscation via String Concatenation (drops 2 filters this rule applies)
- Potential PowerShell Obfuscation via String Reordering (drops 2 filters this rule applies)
- Potential PowerShell Obfuscation via Special Character Overuse (drops 2 filters this rule applies)
- PowerShell 4104 Hunting (drops 1 filter this rule applies)