1. Fortify Static Code Analyzer 是什么
是 Micro Focus 的一款代码安全扫描工具,属于 SAST(静态应用安全测试) 阶段, 支持 27 种开发语言的代码安全扫描, 可以通过 IDE 和 CI/CD 在本地无缝启动扫描
Fortify Static Code Analyzer 安装包
- Windows: Fortify_SCA_and_Apps__windows_x64.exe
- macOS: Fortify_SCA_and_Apps__osx_x64.app.zip
- Linux: Fortify_SCA_and_Apps__linux_x64.run
- Solaris: Fortify_SCA__solaris_x86.run or Fortify_SCA__solaris10_sparc.run
<version>
是软件发布版本
官方文档地址: https://www.microfocus.com/zh-cn/documentation/fortify-static-code-analyzer-and-tools/
2. 工具介绍
安装完成后目录结构
- Core\config\rules 下存放扫描规则包
- Core\config\customrules 下存放自定义规则和问题类型忽略配置
- bin 是存放工具类
3. 代码安全扫描实施步骤
使用 Fortify Static Code Analyzer 对代码进行安全扫描, 分为三个步骤
- 清理中间文件和构建记录
- 创建构建记录和生成中间文件
- 对构建记录发起扫描
3.1 清理
sourceanalyzer.exe -clean
命令用于清理中间文件和构建记录, 当使用-b
指定构建 ID 时, 只删除与该构建 ID 相关的文件和构建记录
清理所有构建记录 和 中间文件
sourceanalyzer.exe -clean
清理指定构建 ID 相关的中间文件和构建记录
sourceanalyzer.exe -clean -b test_project
3.2 构建
进入需要安全扫描的代码目录下, 对需要安全扫描的代码进行构建
- 最基础的构建命令
sourceanalyzer.exe -b <build_id>
将所有文件进行构建
sourceanalyzer.exe -b test_project
- 指定构建文件目录和文件类型
sourceanalyzer.exe -b test_project <file_specifiers>
对所有 java 文件进行构建
sourceanalyzer.exe -b test_project "**/*.java"
- 指定排除目录和文件不参与代码扫描构建
sourceanalyzer.exe -b <build_id> -exclude <file_specifiers>
对 test 目录下的所有文件不构建
sourceanalyzer.exe -b test_project -exclude "**/test/*"
3.3 扫描
- 对指定构建 ID 进行代码安全扫描
sourceanalyzer.exe -b <build_id> -scan
对构建ID test_project 进行安全扫描
sourceanalyzer.exe -b test_project -scan
- 指定结果筛选器文件,过滤问题
sourceanalyzer.exe -b <build_id> -scan -filter <file>
指定 xx/filter_ruleid.txt 文件筛选文件,过滤里面配置的漏洞
sourceanalyzer.exe -b test_project -scan -filter "xx/filter_ruleid.txt"
- 指定扫描结果文件路径和名称
指定代码扫描结果文件路径和文件名称
sourceanalyzer.exe -b test_project -scan -f <file>
sourceanalyzer.exe -b test_project -scan -f /home/code/test-project-result.fpr
配置扫描结果报告类型,提供几种格式报告: fpr, fvdl, fvdl.zip, text, and auto
sourceanalyzer.exe -b test_project -scan -format <format>
sourceanalyzer.exe -b test_project -scan -format fpr