https://codeql.github.com/docs/codeql-cli/analyzing-databases-with-the-codeql-cli/

语法

  1. codeql database analyze <database> <queries> --format=<format> --output=<output>

执行一个查询

使用示例

  1. codeql database analyze "C:\Users\loulan\Desktop\CodeQL\CorpCodebase\LUCKYEHRWEB-master\luckyehrweb-ql" "C:\Users\loulan\Desktop\CodeQL\vscode-codeql-starter\codeql-custom-queries-java\example.ql" --format=csv --output=luckyehrweb-xss-result.csv
  1. codeql database analyze "D:\CodeQL\corp-codebase\EHRWEB-AGG\ehrweb-agg-ql" example-xss.ql --format=sarif-latest --output=results.sarif
  1. codeql database run-queries "D:\CodeQL\corp-codebase\LUCKYEHRWEB-master\luckyehrweb-ql" "D:\CodeQL\corp-codebase\example\example.ql"

https://codeql.github.com/docs/codeql-overview/codeql-glossary/#bqrs-file
image.png

  1. codeql query run --database="D:\CodeQL\corp-codebase\LUCKYEHRWEB-master\luckyehrweb-ql" "D:\CodeQL\corp-codebase\example\example.ql"

执行GitHub代码扫描套件

执行多个查询

CodeQL CLI支持指定一个目录,CodeQL CLI会允许该目录下所有的CodeQL查询文件。
示例如下

  1. codeql database analyze <python-database> ../ql/python/ql/src/Functions/ --format=sarif-latest --output=python-analysis/python-results.sarif

扫描报告

image.png

使用CodeQL输出sarif格式的结果文档
首先在VSCode中安装扩展Sarif Viewer
然后使用database analyze查询数据库,指定输出格式

  1. codeql database analyze <python-database> <ql-file> --format=sarif-latest --output=python-analysis/python-results.sarif

注意:ql文件的元数据中必需要给id、kind、problem.severity配置上值
在VSCode中打开sarif文件时,会自动弹出两个界面如下所示
image.png
当打开的时候只有下面一个界面时,
image.png
可以右键-命令面板(Ctrl+Shift+P),然后输入show panel即可打开另一个面板
image.png
点击这些节点时,默认会提示无法找到这个文件
image.png
我们复制一个文件名,例如RoleServiceImple.java,然后Ctrl+P,输出这个文件名,进来以后,再去点击其他的节点时,就会发现可以自动识别了
image.png