Loading

CodeQL CLI入门

CodeQL CLI — CodeQL (github.com)

创建CodeQL数据库

https://codeql.github.com/docs/codeql-cli/creating-codeql-databases/

codeql database create <database> --language=<language-identifier>

指定build命令

codeql database create java-database --language=java --command="mvn clean install"
codeql database create luckyehrweb-ql -l java --command="mvn clean package -Dmaven.test.skip=true -P test3"

多个语言

1631595174139-549dfdc0-8279-476c-81bb-6e21305e6ef3

使用CodeQL CLI 分析数据库

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

语法

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

执行一个查询

使用示例

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
codeql database analyze "D:\CodeQL\corp-codebase\EHRWEB-AGG\ehrweb-agg-ql" example-xss.ql --format=sarif-latest --output=results.sarif
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

1630318034192-279cb66e-c6fa-4821-895a-0769a3b577ec

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查询文件。

示例如下

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

扫描报告

1625213147520-4ed08384-d895-43ff-a7df-5f03338b543d

使用CodeQL输出sarif格式的结果文档

首先在VSCode中安装扩展Sarif Viewer

然后使用database analyze查询数据库,指定输出格式

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

注意:ql文件的元数据中必需要给id、kind、problem.severity配置上值

在VSCode中打开sarif文件时,会自动弹出两个界面如下所示

1632468500462-01ec513f-2911-40c0-9511-00735d8f4266

当打开的时候只有下面一个界面时,

1632468877687-8ea3dffd-460d-4435-afb5-eab6bfc70c89

可以右键-命令面板(Ctrl+Shift+P),然后输入show panel即可打开另一个面板

1632468926065-70035872-fadd-4058-b4e9-829580977cae

点击这些节点时,默认会提示无法找到这个文件

1632468997753-2deb52fc-0a79-43a1-a1a3-3794d429af36

我们复制一个文件名,例如RoleServiceImple.java,然后Ctrl+P,输出这个文件名,进来以后,再去点击其他的节点时,就会发现可以自动识别了

1632469151401-d99a9db9-b796-414d-9a2a-16a5eea7787c

更新CodeQL 数据库

codeql database upgrade <database>
posted @ 2022-04-25 20:57  我是面包  阅读(603)  评论(0编辑  收藏  举报