This detection identifies adversaries leveraging the legacy sqlcmd.exe utility as a living-off-the-land execution mechanism to perform database reconnaissance or data exfiltration within Azure environments. Proactive hunting for this behavior is critical because attackers often repurpose standard administrative tools like SQLCMD to evade traditional security controls and establish persistent access to sensitive data repositories.
rule sig_238_sqlcmd {
meta:
description = "Disclosed hacktool set (old stuff) - file sqlcmd.exe"
author = "Florian Roth"
date = "23.11.14"
score = 40
hash = "b6e356ce6ca5b3c932fa6028d206b1085a2e1a9a"
strings:
$s0 = "Permission denial to EXEC command.:(" fullword ascii
$s3 = "by Eyas<[email protected]>" fullword ascii
$s4 = "Connect to %s MSSQL server success.Enjoy the shell.^_^" fullword ascii
$s5 = "Usage: %s <host> <uid> <pwd>" fullword ascii
$s6 = "SqlCmd2.exe Inside Edition." fullword ascii
$s7 = "Http://www.patching.net 2000/12/14" fullword ascii
$s11 = "Example: %s 192.168.0.1 sa \"\"" fullword ascii
condition:
4 of them
}
This YARA rule can be deployed in the following contexts:
This rule contains 7 string patterns in its detection logic.
Here are 4 specific false positive scenarios for the Disclosed hacktool set (old stuff) - file sqlcmd.exe detection rule, including suggested filters and exclusions:
Scenario: Scheduled Database Maintenance via SQL Agent
SQLSERVERAGENT) executes a nightly maintenance job that uses sqlcmd.exe to run backup scripts or update statistics on legacy databases. Since these are automated, scheduled tasks running under the system account, they often trigger “old stuff” alerts due to the tool’s age and frequent use in batch processing.sqlagent.exe (or specifically the SQL Server Agent service) and the user context is NT SERVICE\SQLAgent$[InstanceName]. Additionally, filter by file path if the executable resides strictly within the standard installation directory: C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Binn\sqlcmd.exe.Scenario: DevOps CI/CD Pipeline Deployment
sqlcmd.exe to execute migration scripts (e.g., Flyway or Liquibase) against the production database. These builds often run under a dedicated service account (e.g., DEVOPS-BUILD-SVC) and may utilize older versions of the tool inherited from legacy pipelines, triggering the “old stuff” heuristic.DOMAIN\DevOpsBuildSvc). Furthermore, filter based on the command line arguments containing keywords like /S, -b (batch mode), or specific database names known to be part of the deployment