This detection identifies adversaries leveraging the osql command-line utility to execute SQL queries or scripts, a behavior often associated with reconnaissance and lateral movement within database-rich environments. Proactively hunting for this activity in Azure Sentinel is critical because legitimate administrative use of osql can mask malicious data exfiltration attempts that might otherwise go unnoticed due to the tool’s low-severity classification.
rule osql_tool
{
meta:
author = "@patrickrolsen"
reference = "O/I SQL - SQL query tool"
filetype = "EXE"
version = "0.1"
date = "1/30/2014"
strings:
$s1 = "osql\\src"
$s2 = "OSQLUSER"
$s3 = "OSQLPASSWORD"
$s4 = "OSQLSERVER"
condition:
uint16(0) == 0x5A4D and (all of ($s*))
}
This YARA rule can be deployed in the following contexts:
This rule contains 4 string patterns in its detection logic.
Here are 5 specific false positive scenarios for the osql tool detection rule in an enterprise environment, along with suggested filters or exclusions:
SQL Server Maintenance Plans Executing via osql
osql.exe to execute a batch file containing T-SQL commands for index optimization and log truncation.sqlservr.exe or the specific scheduled task name (e.g., \Microsoft\SQLServer\MaintenancePlan). Additionally, filter by the command line argument containing specific keywords like -b (batch mode) and a known script path (e.g., C:\Scripts\DailyMaintenance.sql).Third-Party Backup Solutions (e.g., Veeam or Commvault)
osql.exe as an intermediate step to verify database consistency and capture transaction log status before initiating a full backup job. This occurs during the standard backup window (02:00 AM – 04:00 AM).C:\Program Files\Veeam\Backup and Replication\Agent) or filter by the user account running as a dedicated service account (e.g., DOMAIN\svc_backup_agent).Automated Patching and Configuration Management Tools (e.g., Ansible or SCCM)