Automated static analysis for T-SQL to detect likely SQL injection and related risks. Parses T-SQL from jobs, procedures, triggers, plan cache and other sources with Microsoft ScriptDom, runs checks and exports results to Excel and trace files.
- Purpose: Find likely SQL injection and risky dynamic SQL patterns in captured T‑SQL.
- Primary language: PowerShell.
- Main engine:
Invoke-TSqlChecks.ps1(ScriptDom‑based analyzer).
- Collects T‑SQL from multiple sources (Agent jobs, stored procedures, triggers, plan cache, etc.) and analyzes statements.
- Uses
Microsoft.SqlServer.TransactSql.ScriptDomfor parsing. - Produces Excel reports and per‑statement trace files for triage and reporting.
- Includes helper and test scripts for validation and automation.
Invoke-TSqlChecks.ps1— main analyzer.Import-ScriptDom.ps1— helper to load or copy the ScriptDom DLL.Import-RequiredModules.ps1— helper to install/validate PowerShell modules.Test-Invoke-TSqlChecks.ps1,Test-TSqlInjection.ps1— example/test runners.Microsoft.SqlServer.TransactSql.ScriptDom.dll— parser assembly (included for convenience).- Bundled helper artifacts (e.g., ImportExcel, dbatools) where present.
- Windows or any host with PowerShell support.
- PowerShell 5.1 or later recommended.
Microsoft.SqlServer.TransactSql.ScriptDomassembly available (repository contains DLL for convenience).ImportExcelPowerShell module (or the included ImportExcel bundle) for Excel output.- Optional:
dbatoolsfor inventory and collection helpers.
git clone https://github.com/mcflyamorim/SQLInjectionCheck.git
cd SQLInjectionCheck
.\Import-RequiredModules.ps1
.\Import-ScriptDom.ps1Verify the ScriptDom assembly loads:
[Reflection.Assembly]::LoadFrom((Resolve-Path .\Microsoft.SqlServer.TransactSql.ScriptDom.dll)).FullNameInvoke-TSqlChecks.ps1 accepts parameters to control collection sources, output folder and analyzer behavior. See the script header comments and Test-Invoke-TSqlChecks.ps1 for examples.
Common knobs:
- SQL instance connection string or server and credential parameters.
- Which sources to scan (Jobs, Procedures, Triggers, PlanCache).
- Output folder for Excel and trace files.
- Allow/ignore lists for known-safe patterns.
Quick test run:
.\Test-Invoke-TSqlChecks.ps1 -SqlInstance "MYSERVER\INSTANCE" -OutputFolder "C:\temp\sqlcheck"Run the analyzer directly:
.\Invoke-TSqlChecks.ps1 -SqlInstance "MYSERVER\INSTANCE" -CollectFrom Jobs,Procedures -OutputFolder "C:\temp\sqlcheck"Use Test-TSqlInjection.ps1 to validate detection against known patterns.
- Excel workbook with summary and per-check details (requires ImportExcel).
- Per-statement trace files grouped under the output folder for manual review.
- Logs and exit codes suitable for automation.
- Run only in authorized, controlled environments. The tool reads object definitions and metadata. Do not run against production without approvals and backups.
- The analyzer is static and heuristic-based. Treat findings as indicators that require manual review.
- Keep ScriptDom and PowerShell modules up to date. Parser behavior can change across SQL Server versions.
- Add new checks in
Invoke-TSqlChecks.ps1to detect additional risky patterns. - Add collectors to capture T‑SQL from custom sources.
- Integrate results with CI pipelines or ticketing systems to automate triage.
- Fork the repository.
- Implement a focused change and add tests or examples.
- Submit a pull request with clear description and rationale.
Choose a license and add LICENSE file. MIT is a good default if you want permissive terms.
Maintainer: mcflyamorim (GitHub). Repository: https://github.com/mcflyamorim/SQLInjectionCheck.