Samsung/CredSweeper

GitHub: Samsung/CredSweeper

一款由三星开源的凭证泄露扫描工具,结合模式匹配与机器学习模型,用于在代码、配置文件和二进制资产中检测意外暴露的密码、API 密钥等敏感信息。

Stars: 200 | Forks: 47

# CredSweeper [![GitHub release (latestSemVer)](https://img.shields.io/github/v/release/Samsung/CredSweeper)](https://github.com/Samsung/CredSweeper/releases) [![文档状态](https://readthedocs.org/projects/credsweeper/badge/?version=latest)](https://credsweeper.readthedocs.io/en/latest/?badge=latest) [![许可证](https://img.shields.io/badge/licence-MIT-green.svg?style=flat)](LICENSE) [![PyPI](https://img.shields.io/pypi/v/credsweeper)](https://pypi.org/project/credsweeper/) [![Python](https://img.shields.io/pypi/pyversions/credsweeper.svg)](https://badge.fury.io/py/credsweeper) [![测试](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/c60149a6b3225549.svg)](https://github.com/Samsung/CredSweeper/actions/workflows/test.yml) [![codecov](https://codecov.io/gh/Samsung/CredSweeper/branch/main/graph/badge.svg)](https://codecov.io/gh/Samsung/CredSweeper) [![CII 最佳实践](https://bestpractices.coreinfrastructure.org/projects/6055/badge)](https://bestpractices.coreinfrastructure.org/projects/6055) [![OpenSSF 记分卡](https://api.securityscorecards.dev/projects/github.com/Samsung/CredSweeper/badge)](https://api.securityscorecards.dev/projects/github.com/Samsung/CredSweeper) - [CredSweeper](#credsweeper) - [简介](#introduction) - [如何使用](#how-to-use) - [主要要求](#main-requirements) - [安装](#installation) - [运行](#run) - [配置](#config) - [开发](#develop) - [测试](#tests) - [基准测试](#benchmark) - [整体架构](#overall-architecture) - [重新训练模型](#retrain-model) - [许可证](#license) - [如何参与](#how-to-get-involved) - [项目角色](#project-roles) - [贡献者](#contributor) - [维护者](#maintainer) - [联系方式](#how-to-contact) ## 简介 CredSweeper 是一款高级凭证检测工具,旨在识别源代码、配置文件、文档和二进制资产中暴露的凭证,例如密码、API 密钥、token 和其他敏感信息。 CredSweeper 可扫描常规文件、容器中嵌入的数据以及 Git 提交中添加的文件。 该工具结合了基于模式的检测、基于机器学习的验证和深度文件检查,为现代代码库和代码仓库提供全面且准确的安全扫描。 **核心功能:** - 检测源代码、配置文件、文档和压缩包中的凭证 - 使用算法过滤器和机器学习减少误报 - 扫描压缩文件、文档和二进制格式 - Git 仓库分析和差异扫描 完整文档可在此处找到: ## 如何使用 ### 主要要求 - Python 3.10, 3.11, 3.12, 3.13, 3.14 ### 安装 详情请见[此处](https://credsweeper.readthedocs.io/en/latest/install.html)。 ``` pip install credsweeper ``` ### 运行 [使用说明](https://credsweeper.readthedocs.io/en/latest/guide.html)。 运行 CredSweeper: ``` python -m credsweeper --path tests/samples/password.gradle --save-json output.json ``` ### JSON 输出 ``` [ { "rule": "Password", "severity": "high", "confidence": "moderate", "ml_probability": 0.993, "line_data_list": [ { "line": "password = \"cackle!\"", "line_num": 1, "path": "./tests/samples/password.gradle", "info": "", "variable": "password", "variable_start": 0, "variable_end": 8, "value": "cackle!", "value_start": 12, "value_end": 19, "entropy": 2.52164 } ] } ] ``` ### 配置 [credsweeper/secret/config.json](credsweeper/secret/config.json) - 用于 CredSweeper 预处理的配置文件。有关更多详细信息,请查看[此处](https://credsweeper.readthedocs.io/en/latest/overall_architecture.html#pre-processing)。 您可以如下所示设置要从扫描中排除的 `pattern`、`extension` 和 `path`。 ``` { "exclude": { "pattern": [ "AKIA[0-9A-Z]{9}EXAMPLE", ... ], "extension": [ "gif", "jpg", ... ], "path": [ "/.git/", "/openssl/", ... ] }, ... } ``` 您还可以如下所示设置 `source_ext`、`source_quote_ext`、`find_by_ext_list`、`check_for_literals`、`line_data_output` 和 `candidate_output`。 - `source_ext`:归类为源文件并进行扫描的扩展名列表。 - `source_quote_ext`:归类为使用引号的源文件并进行扫描的扩展名列表。 - `find_by_ext_list`:仅通过扩展名进行检测的扩展名列表。 - `check_for_literals`:布尔值,用于指示是否检查行中是否包含字符串字面量声明。 - `line_data_output`:用于输出的 [line_data](credsweeper/credentials/line_data.py) 属性列表。 - `candidate_output`:用于输出的 [candidate](credsweeper/credentials/candidate.py) 属性列表。 ``` { ... "source_ext": [ ".py", ".cpp", ... ], "source_quote_ext": [ ".py", ".cpp", ... ], "find_by_ext_list": [ ".pem", ".cer", ... ], "check_for_literals": true, "line_data_output": [ "line", "line_num", ... ], "candidate_output": [ "rule", "severity", ... ] } ``` [credsweeper/rules/config.yaml](credsweeper/rules/config.yaml) - 用于设置规则的配置文件。有关更多详细信息,请查看[此处](https://credsweeper.readthedocs.io/en/latest/overall_architecture.html#rule)。 ``` - name: Credential severity: medium confidence: moderate type: keyword values: - credential filter_type: GeneralKeyword use_ml: true min_line_len: 18 required_substrings: - credential target: - code ``` ## 开发 ### 测试 以随机顺序运行所有测试: ``` python -m pytest --cov=credsweeper --cov-report=term-missing --random-order --random-order-bucket=global -s tests/ ``` ### 基准测试 我们有一个用于测试凭证扫描器的数据集,名为 [CredData](https://github.com/Samsung/CredData)。 如果您想使用此数据集测试 CredSweeper,请查看[此处](https://github.com/Samsung/CredData/blob/main/README.md#benchmark)。 ## 整体架构 要查看 CredSweeper 的整体架构,请查看[此处](https://credsweeper.readthedocs.io/en/latest/overall_architecture.html)。 ## 重新训练模型 如果您想了解模型是如何训练的,或者想在自己的数据上重新训练它,请参阅 [experiment](experiment/README.md) 文件夹。 ## 许可证 CredSweeper 是一个基于 [MIT 许可证](https://opensource.org/licenses/mit-license.php) 条款发布的开源项目。 ## 如何参与 除了在开源许可证下进行开发外,该项目还遵循开源开发方法, 欢迎所有人参与、贡献并通过项目进行交流互动。 ### 项目角色 该项目承认以下正式角色:贡献者和维护者。 非正式地,社区可以自我组织,并授予必要的人员额外的权利和责任以实现其目标。 #### 贡献者 贡献者是指任何希望在任何层面上为项目做出贡献的人。贡献者被授予以下权利: - 贡献代码、文档、翻译、设计图、示例等。 - 报告缺陷和改进建议。 - 参与其他人贡献的审查过程。 如果您想参与项目开发,请提前查看[如何贡献指南](./docs/howto/how-to-contribute.md)。 展现出奉献精神和技能的贡献者将获得额外的权利和责任作为奖励。 在做出决策时,他们的意见在完全的精英管理制度下会更有分量。 #### 维护者 维护者是指同时负责了解、指导和预见特定模块需求的贡献者。 因此,维护者有权设置模块中源代码的整体组织结构, 并有权参与决策。维护者需要审查贡献者的请求并决定是否接受。 | 姓名 | 电子邮件 | |------------------------------------------------|------------------------| | [Jaeku Yun](https://github.com/silentearth) | jk0113.yun@samsung.com | | [Shinhyung Choi](https://github.com/csh519) | sh519.choi@samsung.com | | [Roman Babenko](https://github.com/babenek) | r.babenko@samsung.com | | [Yuliia Tatarinova](https://github.com/Yullia) | yuliia.t@samsung.com | ## 联系方式 请在 issues 中发布问题、[议题或建议](https://github.com/Samsung/CredSweeper/issues)。这是与开发者沟通的最佳方式。
标签:AI安全, Apex, API密钥, Chat Copilot, DLP, Homebrew安装, Python, SAST, StruQ, 三星开源, 密码扫描, 密钥泄露, 对抗攻击, 提示注入防御, 敏感信息检测, 无后门, 机器学习, 源代码安全, 盲注攻击, 网络安全, 逆向工具, 隐私保护, 静态应用安全测试