0x00 下载codeql cli
https://github.com/github/codeql-cli-binaries/releases/latest/download/codeql.zip
下载并解压缩,其中可以看到适用于各个平台的执行码。
tips: 建议将codeql路径添加到PATH环境变量中,方便各处调用codeql命令。
0x01 下载Visual Studio Code
https://code.visualstudio.com/Download
0x02 安装插件CodeQL
在IDE中安装插件CodeQL,并进行插件配置。
“Code QL › Cli: Executable Path”配置为codeql cli所在路径,如:个人的mac电脑配置为“/Users/xxx/sast/codeql/codeql”,其中最后一个codeql表示可执行文件。
0x03 下载vscode-codeql示范demo工程,并在vscode中打开(open project)
git clone --recursive https://github.com/github/vscode-codeql-starter/
0x04 在目标代码目录中生成database
进入目标代码目录,然后
codeql database create <database> --language=<language-identifier>
eg:
codeql database create java-shirotest --language=java
0x05 运行查询
1)在CodeQL插件中,选择数据库;
2)在Explorer中,打开codeql-custom-queries-java中的example.ql,右键“CodeQL: Run Query”执行查询;
3)亦可在相同路径新建新的ql文件并运行。
import java
select "hello world"
References
https://help.semmle.com/codeql/codeql-for-vscode/procedures/setting-up.html#starter-workspace