如何使用Whispers识别静态结构化文本中的硬编码敏感信息

发布时间:2025-04-26 点击:4
关于whisperswhispers是一款功能强大的静态代码分析工具,该工具可以帮助广大研究人员解析各种常见的数据格式,并搜索硬编码凭证和危险函数。whispers支持在命令行终端中运行,或者也可以将其集成到ci/cd管道中。
检测功能 密码 api令牌 aws密钥 私钥 凭证哈希 身份认证令牌 危险函数 敏感文件 支持的格式whispers本质上来说是一款结构化的问版本解析工具,而不是一个代码分析工具。
下面列出的是当前版本whispers支持的数据格式:
yaml json xml .npmrc .pypirc .htpasswd .properties pip.conf conf / ini dockerfile dockercfg shell scripts python3python3文件会以ast进行解析,因为这是原生语言支持。
声明和赋值格式该工具可以将下列语言文件解析为文本,并检测常见的变量声明和赋值模式:
javascript java go php 特殊格式支持 aws凭证文件 jdbc连接字符串 jenkins配置文件 springframework配置文件 java属性文件 dockercfg注册认证文件 github令牌 工具安装通过pypi安装:
pip3 install whispers github安装:
git clone https://github.com/skyscanner/whispers cd whispers make install 工具使用命令行接口:
whispers --help whispers --info whispers source/code/fileordir whispers --config config.yml source/code/fileordir whispers --output /tmp/secrets.yml source/code/fileordir whispers --rules aws-id,aws-secret source/code/fileordir whispers --severity blocker,critical source/code/fileordir whispers --exitcode 7 source/code/fileordir python:
from whispers.cli import parse_args from whispers.core import run src = "tests/fixtures" configfile = "whispers/config.yml" args = parse_args(["-c", configfile, src]) for secret in run(args): print(secret) 工具配置whispers工具支持多种配置选项,我们可以根据需要来配置是否在结果中互殴文件路径、密钥或其他值等。config.yml的参考格式如下:
include: files: - "**/*.yml" exclude: files: - "**/test/**/*" - "**/tests/**/*" keys: - ^foo values: - bar$ rules: starks: message: whispers from the north severity: critical value: regex: (aria|ned) stark ignorecase: true 最快的配置方法就是将config.yml文件拷贝至一个新的文件中,然后直接将其以参数形式传递给whispers:
whispers --config config.yml --rules starks src/file/or/dir 自定义规则我们可以通过下列方式,在whispers/rules文件中添加和编辑自己的自定义规则:
rule-id: # unique rule name description: values formatted like aws session token message: aws session token # report will show this message severity: blocker # one of blocker, critical, major, minor, info key: # specify key format regex: (aws.?session.?token)? ignorecase: true # case-insensitive matching value: # specify value format regex: ^(?=.*[a-z])(?=.*[a-z])[a-za-z0-9\+\/]{270,450}$ ignorecase: false # case-sensitive matching minlen: 270 # value is at least this long isbase64: true # value is base64-encoded isascii: false # value is binary data when decoded isuri: false # value is not formatted like a uri similar: 0.35 # maximum allowed similarity between key and value # (1.0 being exactly the same) 插件whispers中所有的解析功能都是通过插件实现的,每一个插件都会使用pairs()方法实现一个类,并返回匹配规则的键值对:
class pluginname: def pairs(self, file): yield "key", "value" 项目地址whispers:【github传送门】
原文地址:https://www.freebuf.com/sectool/317584.html


做网站要避免犯这几种错误
怎么安排策划一个网站的栏目安排
如何增加网站的收录量呢?
网站建设谈选购网站空间需要掌握的几大要点
网站制作方法技巧
做seo优化需要了解哪些重点知识?
购买服务器好吗?相比租用哪个划算?
浅谈前端开发中Cookie的一些事