如何使用GoKart对Go代码进行静态安全分析

安全 数据安全
GoKart是一款针对Go代码安全的静态分析工具,该工具能够从Go源代码中查找使用了SSA(单一静态分配)形式的代码漏洞。

[[433167]]

关于GoKart

GoKart是一款针对Go代码安全的静态分析工具,该工具能够从Go源代码中查找使用了SSA(单一静态分配)形式的代码漏洞。GoKart能够跟踪变量和函数参数的来源,以确定输入源是否安全,与其他Go安全扫描程序相比,GoKart能够有效减少误报的数量。例如,与变量连接的SQL查询传统上可能标记为SQL注入,然而,GoKart可以确定变量实际上是常量还是类似常量的参数,在这种情况下GoKart不会报出漏洞。

工具安装

我们可以使用下列方式之一来安装GoKart。

(1) go install安装

广大研究人员可以使用下列命令安装GoKart:

  1. $ go install github.com/praetorian-inc/gokart@latest 

(2) Release安装

首先,我们需要访问该项目的【Releases页面】,并下载GoKart源码至本地系统。

接下来,我们可以下载checksums.txt文件来验证下载包的完整性:

  1. # Check the checksum of the downloaded archive 
  2.  
  3. $ shasum -a 256 gokart_${VERSION}_${ARCH}.tar.gz 
  4.  
  5. b05c4d7895be260aa16336f29249c50b84897dab90e1221c9e96af9233751f22  gokart_${VERSION}_${ARCH}.tar.gz 
  6.  
  7. $ cat gokart_${VERSION}_${ARCH}_checksums.txt | grep gokart_${VERSION}_${ARCH}.tar.gz 
  8.  
  9. b05c4d7895be260aa16336f29249c50b84897dab90e1221c9e96af9233751f22  gokart_${VERSION}_${ARCH}.tar.gz 

然后,提取已下载好的文档:

  1. $ tar -xvf gokart_${VERSION}_${ARCH}.tar.gz 

最后,将GoKart代码移动至我们的运行路径中:

  1. $ mv ./gokart /usr/local/bin/ 

(3) 源码安装

首先,我们需要使用下列命令将该项目源码克隆至本地:

  1. $ git clone https://github.com/praetorian-inc/gokart.git 

然后切换至项目根目录,并构建源码:

  1. $ cd gokart 
  2.  
  3. $ go build 

最后,将GoKart代码移动至我们的运行路径中:

  1. $ mv ./gokart /usr/local/bin 

Docker支持

构建Docker镜像:

  1. docker build -t gokart . 

运行容器,并执行本地扫描(本地扫描目录需要加载至容器镜像中):

  1. docker run -v /path/to/scan-dir:/scan-dir gokart scan /scan-dir 

运行容器,并执行远程扫描(指定私钥以作认证,并加载至容器中):

  1. docker run gokart scan -r https://github.com/praetorian-inc/gokart 
  2.   
  3. # specifying a private key for private repository ssh authentication 
  4.  
  5. docker run -v /path/to/key-dir/:/key-dir gokart scan -r git@github.com:praetorian-inc/gokart.git -k /key-dir/ssh_key 

工具使用

针对当前目录中的Go模块运行GoKart:

  1. # running without a directory specified defaults to '.' 
  2.  
  3. gokart scan <flags> 

扫描不同目录中的Go模块:

  1. gokart scan <directory> <flags> 

查看帮助信息:

  1. gokart help 

项目地址

GoKart:【GitHub传送门

 

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

2021-11-26 08:45:06

NetworKi网络安全分析安全工具

2015-09-11 15:41:08

2021-01-05 09:25:27

DockerSemgrep代码静态分析工具

2022-04-02 06:10:02

勒索软件PSRansom安全工具

2021-12-26 18:36:47

安全审查Inspection

2020-12-25 15:24:24

人工智能

2017-09-26 19:02:09

PythonInstagram数据分析

2014-05-14 00:50:18

JoyentNode

2010-05-17 16:25:05

MySQL数据

2021-09-27 16:39:10

PythonGif压缩

2021-11-08 10:58:08

变量依赖图排序

2009-10-16 10:38:41

2010-09-26 09:49:51

2021-01-26 09:30:32

加密虚拟机攻击

2017-12-12 13:17:36

机器学习代码单元测试

2012-12-25 13:37:29

Android代码混淆

2022-11-07 07:54:05

微服务数据库网关

2013-06-27 17:30:37

2013-04-08 10:47:42

Xcode静态代码分析

2021-06-08 13:56:34

工具静态代码
点赞
收藏

51CTO技术栈公众号