“攻击面本身就是漏洞。在那里找到一个 bug 只是细节问题。”
-- Mark Dowd
“有些细节比其他的更重要。”
-- Fedor G. Pikus
我收集的 Semgrep 规则集合,用于辅助漏洞研究。
# high priority scan (quick wins)
semgrep --severity ERROR --config "p/0xdea"
# high and medium priority scan (recommended)
semgrep --severity ERROR --severity WARNING --config "p/0xdea"
# full scan (might include marginal findings and more false positives)
semgrep --config "p/0xdea"
或者,你也可以在本地克隆此 GitHub 仓库并运行:
# full scan
semgrep --config semgrep-rules/rules /path/to/source
# specific rule scan
semgrep --config semgrep-rules/rules/c/command-injection.yaml /path/to/source
[!TIP] 指定
--no-git-ignore开关可扫描文件,而不考虑 git 跟踪状态或.gitignore规则。
为了获得更流畅的体验,我建议将 Semgrep 扫描输出保存为 SARIF 格式,并在 VS code 中使用 SARIF Explorer:
semgrep --sarif --sarif-output=/path/to/source/SEMGREP.sarif --config semgrep-rules/rules /path/to/source
code /path/to/source # then open the SEMGREP.sarif file in VS code with SARIF Explorer
另请参阅随附的 SARIF 输出示例。
已使用 Semgrep CLI 1.169.0 测试。
经过实战检验的 C(有时也包括 C++)规则集。
gets。strcpy、stpcpy、strcat。sprintf 和 vsprintf。scanf 系列中可能不安全的 API 函数。strncat 传递了错误的大小参数。strncpy、memcpy、snprintf 及其变体传递了错误的大小参数。sizeof 运算符。strncpy 和 stpncpy 之后缺少显式的 NUL 终止。snprintf 和 vsnprintf 返回值的潜在不安全使用。strlcpy 和 strlcat 返回值的潜在不安全使用。strlen 的返回值强制转换为 short 可能很危险。alloca。free)。free)。free。malloc、calloc、realloc 等的返回码。putenv。system 或 popen 的潜在操作系统命令注入。access、stat、lstat 等。mktemp、tmpnam、tempnam。signal。