sast-flawfinder

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SAST Scan with Flawfinder (C/C++)

使用Flawfinder进行SAST扫描(C/C++)

You are a security engineer running static analysis on C/C++ code using Flawfinder.
你是一名安全工程师,正在使用Flawfinder对C/C++代码执行静态分析。

When to use

适用场景

Use this skill when asked to perform a SAST scan or security review on C or C++ code.
当需要对C或C++代码执行SAST扫描或安全审查时,使用本技能。

Prerequisites

前提条件

  • Flawfinder installed (
    pip install flawfinder
    )
  • Verify:
    flawfinder --version
  • 已安装Flawfinder(
    pip install flawfinder
  • 验证安装:
    flawfinder --version

Instructions

操作步骤

  1. Identify the target — Determine the C/C++ source file(s) or directory to scan.
  2. Run the scan:
    bash
    flawfinder --json <target-path> > flawfinder-results.json
    • With minimum risk level:
      flawfinder --minlevel=3 --json <target>
    • With column info:
      flawfinder --columns --json <target>
    • CSV output:
      flawfinder --csv <target> > results.csv
  3. Parse the results — Read JSON output and present findings:
| # | Risk Level (0-5) | CWE | File:Line:Column | Function | Finding | Remediation |
|---|-------------------|-----|------------------|----------|---------|-------------|
  1. Summarize — Provide total hits by risk level, critical findings (level 4-5) first, safe alternatives.
  1. 确定目标 — 确定要扫描的C/C++源文件或目录。
  2. 运行扫描
    bash
    flawfinder --json <target-path> > flawfinder-results.json
    • 指定最低风险等级:
      flawfinder --minlevel=3 --json <target>
    • 包含列信息:
      flawfinder --columns --json <target>
    • 输出CSV格式:
      flawfinder --csv <target> > results.csv
  3. 解析结果 — 读取JSON输出并呈现检测结果:
| 序号 | 风险等级(0-5) | CWE | 文件:行:列 | 函数 | 检测结果 | 修复建议 |
|---|-------------------|-----|------------------|----------|---------|-------------|
  1. 总结 — 按风险等级统计总检测数,优先展示严重检测结果(等级4-5),并提供安全替代方案。

Key Risk Categories

核心风险类别

CategoryDangerous FunctionsSafe Alternatives
Buffer overflow
strcpy
,
strcat
,
gets
,
sprintf
strncpy
,
strncat
,
fgets
,
snprintf
Format string
printf(user_input)
printf("%s", user_input)
Race condition
access()
+
open()
(TOCTOU)
open()
with proper flags
Integer overflow
atoi
, unchecked
malloc
strtol
with bounds checking
Memory
memcpy
without bounds
Bounded
memcpy_s
or size checks
Crypto
rand()
,
srand()
getrandom()
,
/dev/urandom
类别危险函数安全替代方案
缓冲区溢出
strcpy
,
strcat
,
gets
,
sprintf
strncpy
,
strncat
,
fgets
,
snprintf
格式化字符串
printf(user_input)
printf("%s", user_input)
竞争条件
access()
+
open()
(TOCTOU)
带正确标志的
open()
整数溢出
atoi
, 未检查的
malloc
带边界检查的
strtol
内存操作无边界的
memcpy
带边界的
memcpy_s
或尺寸检查
加密
rand()
,
srand()
getrandom()
,
/dev/urandom