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