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

安全 数据安全
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安装:

  1. pip3 install whispers 

GitHub安装:

  1. git clone https://github.com/Skyscanner/whispers  
  2. cd whispers  
  3. make install 

工具使用

命令行接口:

  1. whispers --help 
  2.  
  3. whispers --info 
  4.  
  5. whispers source/code/fileOrDir 
  6.  
  7. whispers --config config.yml source/code/fileOrDir 
  8.  
  9. whispers --output /tmp/secrets.yml source/code/fileOrDir 
  10.  
  11. whispers --rules aws-id,aws-secret source/code/fileOrDir 
  12.  
  13. whispers --severity BLOCKER,CRITICAL source/code/fileOrDir 
  14.  
  15. whispers --exitcode 7 source/code/fileOrDir 

Python:

  1. from whispers.cli import parse_args 
  2.  
  3. from whispers.core import run 
  4.  
  5.   
  6.  
  7. src = "tests/fixtures" 
  8.  
  9. configfile = "whispers/config.yml" 
  10.  
  11. args = parse_args(["-c", configfile, src]) 
  12.  
  13. for secret in run(args): 
  14.  
  15.   print(secret) 

工具配置

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

  1. include: 
  2.  
  3.   files: 
  4.  
  5.     - "**/*.yml" 
  6.  
  7.   
  8.  
  9. exclude: 
  10.  
  11.   files: 
  12.  
  13.     - "**/test/**/*" 
  14.  
  15.     - "**/tests/**/*" 
  16.  
  17.   keys: 
  18.  
  19.     - ^foo 
  20.  
  21.   values: 
  22.  
  23.     - bar$ 
  24.  
  25.   
  26.  
  27. rules: 
  28.  
  29.   starks: 
  30.  
  31.     message: Whispers from the North 
  32.  
  33.     severity: CRITICAL 
  34.  
  35.     value: 
  36.  
  37.       regex: (Aria|Ned) Stark 
  38.  
  39.       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.  
  3.   description: Values formatted like AWS Session Token 
  4.  
  5.   message: AWS Session Token  # report will show this message 
  6.  
  7.   severity: BLOCKER           # one of BLOCKER, CRITICAL, MAJOR, MINOR, INFO 
  8.  
  9.   
  10.  
  11.   key:        # specify key format 
  12.  
  13.     regex: (aws.?session.?token)? 
  14.  
  15.     ignorecase: True   # case-insensitive matching 
  16.  
  17.   
  18.  
  19.   value:      # specify value format 
  20.  
  21.     regex: ^(?=.*[a-z])(?=.*[A-Z])[A-Za-z0-9\+\/]{270,450}$ 
  22.  
  23.     ignorecase: False  # case-sensitive matching 
  24.  
  25.     minlen: 270        # value is at least this long 
  26.  
  27.     isBase64: True     # value is base64-encoded 
  28.  
  29.     isAscii: False     # value is binary data when decoded 
  30.  
  31.     isUri: False       # value is not formatted like a URI 
  32.  
  33.   
  34.  
  35.   similar: 0.35        # maximum allowed similarity between key and value 
  36.  
  37.                        # (1.0 being exactly the same) 

插件

Whispers中所有的解析功能都是通过插件实现的,每一个插件都会使用pairs()方法实现一个类,并返回匹配规则的键值对:

  1. class PluginName: 
  2.  
  3.     def pairs(self, file): 
  4.  
  5.         yield "key", "value" 

项目地址

Whispers:【GitHub传送门

 

责任编辑:赵宁宁 来源: FreeBuf
相关推荐

2014-03-14 09:52:15

非结构化数据

2021-12-12 08:37:18

结构化数据非结构化数据数据

2023-09-01 07:21:11

2023-07-25 17:21:20

综合布线结构化布线

2018-04-03 14:00:03

结构化数据非结构化数据数据库

2023-06-19 07:08:22

结构化数据ChatGPT

2021-11-14 20:29:56

web结构化数据

2023-03-29 18:41:27

综合布线

2023-12-25 15:00:18

结构化布线光纤

2015-12-04 10:26:31

java结构化集合运算

2024-02-19 08:19:25

结构化绑定C++17C++

2012-02-08 15:54:05

ibmdw

2017-12-06 15:46:31

深度学习结构化数据NLP

2014-02-09 09:53:05

2011-02-28 13:41:01

布线

2024-01-25 16:21:43

结构化布线网络通信

2009-12-28 14:28:24

Google GAE 结构化数据

2015-12-08 13:53:56

java结构对齐连接

2015-12-18 10:10:06

集算器Java结构化

2009-02-16 15:41:04

非结构化数据SQL Server SQL Server
点赞
收藏

51CTO技术栈公众号