使用 CodeQL 弱點掃描 C#

安裝

# 建立資料夾
mkdir c:/codeql-home
cd c:/codeql-home

# 下載
curl -L https://github.com/github/codeql-cli-binaries/releases/download/v2.19.1/codeql-win64.zip --output codeql-win64.zip
curl -L https://github.com/github/codeql/archive/refs/tags/codeql-cli/v2.19.1.zip --output codeql-cli.zip

# 解壓縮
Expand-Archive -Path codeql-win64.zip -DestinationPath ./
Expand-Archive -Path codeql-cli.zip -DestinationPath ./
Move-Item ./codeql-codeql-cli-v2.19.1 ./codeql-repo 

設定

  • c:/codeql-home/codeql 加入環境變數 PATH

建立 CodeQL 資料庫

codeql database create {database-path} --language={lang} -s {source-path}

分析

codeql database analyze {database-path} --format=sarifv2.1.0 --output=results.sarif

Note: 目前如果 source code 有更動,需要重新建立資料庫,只能先刪除資料庫再建立。

參考