0
点赞
收藏
分享

微信扫一扫

多线程回顾、集合Collection、Set、List等基本知识

攻城狮Chova 2023-09-16 阅读 38
golang漏洞

Golang代码漏洞扫描工具介绍——trivy

Trivy

Trivy介绍

Trivy是不是是一款功能强大的漏洞扫描工具,它的应用场景不仅仅在代码层面,还有镜像层面,而且不仅仅能够扫描Golang,还能扫描Bundler、Composer、Pipenv、Poetry、npm、yarn、Cargo、NuGet、Maven等语言。事实上,Trivy主要是检测:

操作系统包(Alpine、Red Hat Universal Base Image、Red Hat Enterprise Linux、CentOS、Oracle Linux、Debian、Ubuntu、Amazon Linux、openSUSE Leap、SUSE Enterprise Linux、Photon OS 和 Distroless等)和应用程序依赖(Bundler、Composer、Pipenv、Poetry、npm、yarn、Cargo、NuGet、Maven 和 Go等)的漏洞以及配置错误。

Trivy使用场景

事实上,Trivy 很容易使用,只要安装了二进制文件,就可以扫描了。所以一般建议使用在CI的流水线上,而且,由于具有代码扫描和镜像扫描两个能力,所以可以分别在代码合入发起时和接口用例测试前两个步骤进行添加

关于安装:

推荐一个万能的安装方式

1.在https://> github.com/aquasecurity/trivy/releases

找到最新的release包,并下载

2.解压:tar -xzf ./trivy.tar.gz

3.给可执行文件增加权限:chmod +x ./trivy

4.放入Path:mv ./trivy /usr/local/bin/

5.将其他的文件放到一个固定的地方:

在这里插入图片描述

后面会讲到为什么这么做

其他在linux各个版本、mac等环境安装,docker启动等方式参考:

1.https://github.com/aquasecurity/trivy

2.https://aquasecurity.github.io/trivy/v0.45/getting-started/installation/

关于使用:

trivy能够扫描的对象包括

  • Container Image
  • Filesystem
  • Git Repository (remote)
  • Virtual Machine Image
  • Kubernetes
  • AWS

trivy能够发现的问题包括

  • OS packages and software dependencies in use (SBOM)
  • Known vulnerabilities (CVEs)
  • IaC issues and misconfigurations
  • Sensitive information and secrets
  • Software licenses

这次主要介绍的是SBOM。也就是依赖包的漏洞情况

1.基本命令使用:

trivy -h

得到下图:
在这里插入图片描述

具体的介绍可以参考:

https://aquasecurity.github.io/trivy/v0.37/docs/references/cli/sbom/

代码扫描使用

扫描镜像示例:

trivy image 8bcba6ed2605

结果如下:

在这里插入图片描述

扫描文件系统示例:

trivy fs ./

结果如下:

在这里插入图片描述

Git 存储库漏洞扫描示例:

trivy repo https://github.com/test/text.git

结果如下:

在这里插入图片描述

这里可以根据需要增加参数,比如:

只希望扫出来已修复的漏洞:

trivy repo https://github.com/test/text.git --ignore-unfixed

希望扫出来的结果以json形式展示:

trivy repo https://github.com/test/text.git -f json

希望扫出来的结果以网页的形式展示:

trivy repo https://github.com/test/text.git --format template --template "@./trivy/contrib/html.tpl" -o qapm_report.html

这里用到模版,也就前面讲到除了可执行文件之外要保存的文件夹,里面的–template 后面的地址就是官方的模版,这里用到的就是网页模版
在这里插入图片描述

参考资料:

https://www.cnblogs.com/layzer/articles/trivy.html

https://cloud.tencent.com/developer/article/1814500

举报

相关推荐

0 条评论