如何使用GoKart對Go代碼進行靜態(tài)安全分析
關(guān)于GoKart
GoKart是一款針對Go代碼安全的靜態(tài)分析工具,該工具能夠從Go源代碼中查找使用了SSA(單一靜態(tài)分配)形式的代碼漏洞。GoKart能夠跟蹤變量和函數(shù)參數(shù)的來源,以確定輸入源是否安全,與其他Go安全掃描程序相比,GoKart能夠有效減少誤報的數(shù)量。例如,與變量連接的SQL查詢傳統(tǒng)上可能標記為SQL注入,然而,GoKart可以確定變量實際上是常量還是類似常量的參數(shù),在這種情況下GoKart不會報出漏洞。
工具安裝
我們可以使用下列方式之一來安裝GoKart。
(1) go install安裝
廣大研究人員可以使用下列命令安裝GoKart:
- $ go install github.com/praetorian-inc/gokart@latest
(2) Release安裝
首先,我們需要訪問該項目的【Releases頁面】,并下載GoKart源碼至本地系統(tǒng)。
接下來,我們可以下載checksums.txt文件來驗證下載包的完整性:
- # Check the checksum of the downloaded archive
- $ shasum -a 256 gokart_${VERSION}_${ARCH}.tar.gz
- b05c4d7895be260aa16336f29249c50b84897dab90e1221c9e96af9233751f22 gokart_${VERSION}_${ARCH}.tar.gz
- $ cat gokart_${VERSION}_${ARCH}_checksums.txt | grep gokart_${VERSION}_${ARCH}.tar.gz
- b05c4d7895be260aa16336f29249c50b84897dab90e1221c9e96af9233751f22 gokart_${VERSION}_${ARCH}.tar.gz
然后,提取已下載好的文檔:
- $ tar -xvf gokart_${VERSION}_${ARCH}.tar.gz
最后,將GoKart代碼移動至我們的運行路徑中:
- $ mv ./gokart /usr/local/bin/
(3) 源碼安裝
首先,我們需要使用下列命令將該項目源碼克隆至本地:
- $ git clone https://github.com/praetorian-inc/gokart.git
然后切換至項目根目錄,并構(gòu)建源碼:
- $ cd gokart
- $ go build
最后,將GoKart代碼移動至我們的運行路徑中:
- $ mv ./gokart /usr/local/bin
Docker支持
構(gòu)建Docker鏡像:
- docker build -t gokart .
運行容器,并執(zhí)行本地掃描(本地掃描目錄需要加載至容器鏡像中):
- docker run -v /path/to/scan-dir:/scan-dir gokart scan /scan-dir
運行容器,并執(zhí)行遠程掃描(指定私鑰以作認證,并加載至容器中):
- docker run gokart scan -r https://github.com/praetorian-inc/gokart
- # specifying a private key for private repository ssh authentication
- 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:
- # running without a directory specified defaults to '.'
- gokart scan <flags>
掃描不同目錄中的Go模塊:
- gokart scan <directory> <flags>
查看幫助信息:
- gokart help
項目地址
GoKart:【GitHub傳送門】