To start using the client tool, you will need:
- Install Sarif.PatternMatcher.Cli
dotnet tool install --global Sarif.PatternMatcher.Cli --version x.y.z- Download Sarif.PatternMatcher.Security
nuget install Sarif.PatternMatcher.Security -Version x.y.z -OutputDirectory c:\folder-to-install-packages\After completing the steps above, execute in the terminal (cmd/powershell):
> spam --help
Sarif Pattern Matcher Cli 1.4.0-alpha.198+840f9cbd87
c Microsoft Corporation. All rights reserved.
analyze
analyze-database
validate
help Display more information on a specific command.
version Display version information.For each verb, you can use --help to retrieve the arguments:
❯ spam analyze --helpAlso, check in the c:\folder-to-install-packages if you can see the following structure:
c:\folder-to-install-packages
│───Sarif.PatternMatcher.Security.x.y.z
│ └───content
│ └───*.json
│ └───*.txt
│ └───*.dll
│ └───lib
│ └───*.dll
If you see that structure, copy the dll files from the lib folder to the content folder. With that, *.json and *.dll files should be in the same directory.
The following command will analyze a folder using one json file, filtering some results and outputting to a file:
spam analyze c:\path-to-analyze\ --recurse --output c:\analysis.sarif --log ForceOverwrite --level "Error;Warning" --kind "Fail" --plugin PATH\SEC101.SecurePlaintextSecrets.jsonanalyzethe pathc:\path-to-analyze\in recursive mode, which means that it will fetch all files and folders.--outputthe result of the analysis in thec:"\analysis.sarif.--log ForceOverwritereplace the file if exists.--levelfilter the results usingresultLevelwithErrororWarning.--kindfilter the results usingresultKindwithFail.--pluginwill use the following rules to analyze.
The following command will analyze a folder using two json files, filtering some results, file size and path based on a regex. Also, it will execute the dynamic validation:
spam analyze c:\path-to-analyze\ --recurse --deny-regex "\\\.git\\\\" --output c:\temp\spam.sarif --log ForceOverwrite --level "Error;Note" --kind "Fail" --file-size 2048 --dynamic-validation --threads 8 --insert "RegionSnippets;ContextRegionSnippets" --plugin PATH\SEC101.SecurePlaintextSecrets.json;PATH\SEC101.SomeRule.jsonanalyzethe pathc:\path-to-analyze\in recursive mode, which means that it will fetch all files and folders.--deny-regexfilter out files that matches the regex.--outputthe result of the analysis in thec:"\analysis.sarif.--log ForceOverwritereplace the file if exists.--levelfilter the results usingresultLevelwithErrororNote.--kindfilter the results usingresultKindwithFail.--max-file-size Xfilters out files with size larger that X KB. The default value is 1024 KB.--dynamic-validationif a result is found, it will trigger a second step to validate dynamically the result (if the rule implements it).--threads Xit will create X threads to parallelize the work. The default value isEnvironment.ProcessorCount.--insertif supplied, it will add more information to the output SARIF file.--pluginwill use the following rules to analyze.
Obs.:
--levelcan beError,Warning,Note, orNone. The full definition can be found in the SARIF specification.--kindcan beNone,NotApplicable,Pass,Fail,Review,Open, orInformational. The full definition can be found in the SARIF specification.
The following command will analyze a database using one json file, filtering some results and outputting to a file:
spam analyze-database c:\temp\ --connection "Some connection string" --data-type SqlLite --target "SELECT * FROM some_database" --identity Id --output c:\analysis.sarif --log ForceOverwrite --level "Error;Warning" --kind "Fail" --plugin PATH\SEC101.SecurePlaintextSecrets.jsonanalyze-databasethe database from the target.--connectionthe connection string to access the database.--data-typethe type of the connection string.--targetthe query that will return rows to be analyze.--identitythe identity column.--outputthe result of the analysis in thec:"\analysis.sarif.--log ForceOverwritereplace the file if exists.--levelfilter the results usingresultLevelwithErrororWarning.--kindfilter the results usingresultKindwithFail.--pluginwill use the following rules to analyze.
Obs.: the first argument is a path that won't be used.
Open the SARIF file using:
The viewer does not handle exceptions. With that, always take a look at runs -> invocations -> toolExecutionNotifications and check for the exceptions.