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

关于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  

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

 
 
  1. gokart scan   

查看帮助信息:

 
 
  1. gokart help 

项目地址

GoKart:【GitHub传送门】


网页名称:如何使用GoKart对Go代码进行静态安全分析
标题来源:http://gydahua.com/article/dhcdejd.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流