安全矩阵

 找回密码
 立即注册
搜索
查看: 2547|回复: 0

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

[复制链接]

991

主题

1063

帖子

4319

积分

论坛元老

Rank: 8Rank: 8

积分
4319
发表于 2022-1-23 14:53:26 | 显示全部楼层 |阅读模式
原文链接:如何使用Whispers识别静态结构化文本中的硬编码敏感信息


关于Whispers Whispers是一款功能强大的静态代码分析工具,该工具可以帮助广大研究人员解析各种常见的数据格式,并搜索硬编码凭证和危险函数。Whispers支持在命令行终端中运行,或者也可以将其集成到CI/CD管道中。
检测功能
密码
API令牌
AWS密钥
私钥
凭证哈希
身份认证令牌
危险函数
敏感文件
支持的格式 Whispers本质上来说是一款结构化的问版本解析工具,而不是一个代码分析工具。
下面列出的是当前版本Whispers支持的数据格式:
YAML
JSON
XML
.npmrc
.pypirc
.htpasswd
.properties
pip.conf
conf / ini
Dockerfile
Dockercfg
Shell scripts
Python3
Python3文件会以AST进行解析,因为这是原生语言支持。
声明和赋值格式 该工具可以将下列语言文件解析为文本,并检测常见的变量声明和赋值模式:
JavaScript
Java
Go
PHP
特殊格式支持
AWS凭证文件
JDBC连接字符串
Jenkins配置文件
SpringFramework配置文件
Java属性文件
Dockercfg注册认证文件
GitHub令牌
工具安装 通过PyPI安装pip3 install whispers
GitHub安装
  1. git clone https://github.com/Skyscanner/whispers
  2. cd whispers
  3. make install
复制代码


工具使用 命令行接口ispers --help
  1. whispers --info
  2. whispers source/code/fileOrDir
  3. whispers --config config.yml source/code/fileOrDir
  4. whispers --output /tmp/secrets.yml source/code/fileOrDir
  5. whispers --rules aws-id,aws-secret source/code/fileOrDir
  6. whispers --severity BLOCKER,CRITICAL source/code/fileOrDir
  7. whispers --exitcode 7 source/code/fileOrDir
  8. Pythonfrom whispers.cli import parse_args
  9. from whispers.core import run

  10. src = "tests/fixtures"
  11. configfile = "whispers/config.yml"
  12. args = parse_args(["-c", configfile, src])
  13. for secret in run(args):
  14.   print(secret)
复制代码


工具配置 Whispers工具支持多种配置选项,我们可以根据需要来配置是否在结果中互殴文件路径、密钥或其他值等。config.yml的参考格式如下:

  1. include:
  2.   files:
  3.     - "**/*.yml"
  4. exclude:
  5.   files:
  6.     - "**/test/**/*"
  7.     - "**/tests/**/*"
  8.   keys:
  9.     - ^foo
  10.   values:
  11.     - bar$
  12. rules:
  13.   starks:
  14.     message: Whispers from the North
  15.     severity: CRITICAL
  16.     value:
  17.       regex: (Aria|Ned) Stark
  18.       ignorecase: True
复制代码

最快的配置方法就是将config.yml文件拷贝至一个新的文件中,然后直接将其以参数形式传递给Whispers:
  1. whispers --config config.yml --rules starks src/file/or/dir
复制代码



自定义规则
我们可以通过下列方式,在whispers/rules文件中添加和编辑自己的自定义规则
  1. rule-id:  # unique rule name
  2.   description: Values formatted like AWS Session Token
  3.   message: AWS Session Token  # report will show this message
  4.   severity: BLOCKER           # one of BLOCKER, CRITICAL, MAJOR, MINOR, INFO
  5.   key:        # specify key format
  6.     regex: (aws.?session.?token)?
  7.     ignorecase: True   # case-insensitive matching
  8.   value:      # specify value format
  9.     regex: ^(?=.*[a-z])(?=.*[A-Z])[A-Za-z0-9\+\/]{270,450}$
  10.     ignorecase: False  # case-sensitive matching
  11.     minlen: 270        # value is at least this long
  12.     isBase64: True     # value is base64-encoded
  13.     isAscii: False     # value is binary data when decoded
  14.     isUri: False       # value is not formatted like a URI
  15.   similar: 0.35        # maximum allowed similarity between key and value
  16.                        # (1.0 being exactly the same)
复制代码


插件
Whispers中所有的解析功能都是通过插件实现的,每一个插件都会使用pairs()方法实现一个类,并返回匹配规则的键值对:
  1. class PluginName:
  2.    def pairs(self, file):      
  3.      yield "key", "value"
复制代码


项目地址https://github.com/Skyscanner/whispers
参考资料https://github.com/Skyscanner/whispers/blob/master/whispers/config.ymlhttps://github.com/Skyscanner/whispers/blob/master/whispers/rules

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2025-4-24 00:02 , Processed in 0.012762 second(s), 18 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表