前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Intercept:一套强大的代码静态分析审计策略

Intercept:一套强大的代码静态分析审计策略

作者头像
FB客服
发布2020-06-17 20:42:36
4780
发布2020-06-17 20:42:36
举报
文章被收录于专栏:FreeBuf

INTERCEPT是一套强大的代码静态分析审计策略,这套策略集简单易用,占用空间小,可以通过快速且强大的多行扫描工具来扫描你的代码库。除此之外,广大研究人员还可以将其作为数据采集器和检查器,或把它当作一款跨平台的武器化ripgrep来使用。

功能介绍

代码即策略;

细粒度正则策略;

多个执行级别;

静态分析,无守护进程;

低占用空间,可自我更新的二进制文件;

易于集成在任何CI/CD管道上;

声明式策略,以降低复杂性;

无自定义策略语言;

代码即策略

“代码即策略”的思想来源于策略的管理和自动化实现这方面,通过将策略以YAML文件代码的形式来呈现,是已经过验证的软件开发最佳实践,有助于研究人员实现版本控制、自动测试和自动部署。

工作机制

1、拦截和分析命令行接口代码; 2、YAML文件策略实施;

INTERCEPT会整合环境标记、YAML策略和可选参数来生成一个全局配置文件,它可以递归扫描目标路径以查找违反策略的代码,并生成人类可读的详细扫描及分析报告。

扫描报告输出样本:

工具构建

代码语言:javascript
复制
# Standard package (intercept + ripgrep) for individual platforms-- core-intercept-rg-*.zip# Cross Platform Full package (intercept + ripgrep)-- x-intercept.zip# Build package to build on all platforms (Development)-- setup-buildpack.zip# Package of the latest compatible release of ripgrep (doesn't include intercept)-- i-ripgrep-*.zip

快速开始

首先,根据自己的平台下载最新版本的INTERCEPT:

代码语言:javascript
复制
--- Darwincurl -fSL https://github.com/xfhg/intercept/releases/latest/download/intercept-darwin_amd64 -o intercept--- Linuxcurl -fSL https://github.com/xfhg/intercept/releases/latest/download/intercept-linux_amd64 -o intercept--- Windowscurl -fSL https://github.com/xfhg/intercept/releases/latest/download/intercept-windows_amd64 -o intercept.exe

获取样本进行快速扫描:

代码语言:javascript
复制
curl -fSLO https://github.com/xfhg/intercept/releases/latest/download/_examples.zip

现在,我们需要分析的代码已经存储在一个examples/文件夹中了,在开始之前,我们需要查看策略文件中的可选策略类型:

代码语言:javascript
复制
- scan : where we enforce breaking rules on matched patterns- collect : where we just collect matched patterns

我们给出的演示样例将会做以下几件事情:

1、扫描目标代码中是否存在私钥:我们需要保证策略的fatal:true,并且不接受任何异常,即enforcement:true。设置环境:保证此策略将在所有环境上强制执行。

2、扫描模块是否来自兼容源而不是本地或git:我们需要保证策略的fatal:true,并且环境必须为PROD,即environment:prod。这个策略可以接受本地异常:enforcement:false。

3、收集模块使用之外的terraform资源实例。

包含上述扫描策略和收集策略的策略文件如下(examples/policy/simple.yaml):

代码语言:javascript
复制
# This banner is shown on the start of the scanning report,# use it to point out important documentation/warnings/contacts
代码语言:javascript
复制
Banner:| Banner text here, drop documentation link or quick instructions on how to react to the reportRules:# This is the main policy block, all rules will be part of this array# This is a rule structure block# Each rule can have one or more patterns (regex)# The rule is triggered by any of the patterns listed#
代码语言:javascript
复制
# Essential settings :# id : ( must be unique )# type : ( scan | collect )# fatal : ( true | false )# enforcement : ( true | false )# environment : ( all | anystring)# All other settings are free TEXT to complement your final report- name: Private key committed in codeid: 1description: Private key committed to code version controlsolution:error: This violation immediately blocks your code deploymenttype: scanenforcement: trueenvironment: allfatal: true
代码语言:javascript
复制
patterns:- \s*(-----BEGIN PRIVATE KEY-----)- \s*(-----BEGIN RSA PRIVATE KEY-----)- \s*(-----BEGIN DSA PRIVATE KEY-----)- \s*(-----BEGIN EC PRIVATE KEY-----)- \s*(-----BEGIN OPENSSH PRIVATE KEY-----)- \s*(-----BEGIN PGP PRIVATE KEY BLOCK-----)
代码语言:javascript
复制
# Another scan rule- name: Compliant module sourceid: 5description: Modules should not be sourced locally nor from giterror: This breach blocks your deployment on production environmentstype: scansolution:environment: prodfatal: trueenforcement: falsepatterns:- source\s*.*\.git"- \s+source\s*=\s*"((?!https\:).)
代码语言:javascript
复制
# A different type of policy rule that just collects findings matched with the patterns listed- name: Collect sparse TF resources outside of modules.description: The following resources were detected outside of compliant module usagetype: collectpatterns:- (resource)\s*"(.*)"
代码语言:javascript
复制
# These are the messages displayed at the end of the report# Clean for no finds# Warning for at least one non-fatal find# Critical for at least one fatal findExitCritical: "Critical irregularities found in your code"ExitWarning: "Irregularities found in your code"ExitClean: "Clean report"

项目地址

INTERCEPT:【GitHub传送门】

其他引用项目

1、Ripgrep 2、Hashicorp Sentinel 3、Open Policy Agent

*参考来源:xfhg,FB小编Alpha_h4ck编译,来自FreeBuf.COM

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-06-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 FreeBuf 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 功能介绍
  • 代码即策略
  • 工作机制
    • 扫描报告输出样本:
    • 工具构建
    • 快速开始
    • 获取样本进行快速扫描:
    • 项目地址
    • 其他引用项目
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档