Slither:第一款針對Solidity的靜態分析框架
Slither是第一個開源的針對Solidity語言的靜態分析框架。Slither速度非常快,準確性也非常高,它能夠在不需要使用者互動的情況下,在幾秒鐘之內找到真正的漏洞。該工具高度可配置,並且提供了多種API來幫助研究人員審計和分析Solidity程式碼。
目前,我們開源了Slither的核心分析引擎,這個核心提供了很多高階靜態分析功能。除此之外,我們還構建了很多檢測工具。
如果你是一名智慧合約的開發者,一名安全專家,或者是一名學術研究人員,你肯定能發現Slither的價值。
可自主整合其他功能
Slither擁有簡單的命令列介面,如果你想對一份Solidity檔案執行所有的檢測工具,你只需要執行:
$slither contract.sol
你可以在無需進行任何配置的情況下,將你自己設計的功能整合進Slither,不過你需要確保自己新增的程式碼不存在漏洞。
自動化安全審計
Slither提供了一個API來給研究人員通過自定義指令碼審計Solidity程式碼。我們可以使用Slither做到:
1、 識別能夠修改變數值的程式碼; 2、 隔離受特定變數值影響的條件邏輯語句; 3、 查詢能夠呼叫特定函式的其他函式;
比如說下面這段指令碼, myContract的function(s)函式會給狀態變數myVar寫入值:
#function_writing.py import sys from slither.slither import Slither iflen(sys.argv) != 2: print('python.pyfunction_writing.py file.sol') exit(-1) #Init slither slither= Slither(sys.argv[1]) # Getthe contract contract= slither.get_contract_from_name('myContract') # Getthe variable myVar= contract.get_state_variable_from_name('myVar') # Getthe functions writing the variable funcs_writing_myVar= contract.get_functions_writing_to_variable(myVar) #Print the result print('Functionsthat write to "myVar": {}'.format([f.name for f infuncs_writing_myVar]))
大家可以閱讀一下【 ofollow,noindex" target="_blank">API文件 】和【 樣本程式碼 】來初步瞭解Slither。
幫助理解智慧合約
Slither預定義了一套“printer”,它們可以顯示關於智慧合約的高階資訊,其中包括四個關於安全方面的關鍵資料:合約摘要、函式摘要、繼承圖和授權概述。
1、 合約摘要printer
這個printer可以快速顯示合約的大致資訊,並顯示函式和對應的可見度:
2、 函式摘要printer
顯示關於每個函式的資訊,例如狀態變數、讀寫操作和函式呼叫資訊:
3、 繼承圖printer
以圖表的形式輸出所有合約的繼承依賴關係:
4、 授權printer
顯示使用者對智慧合約的操作許可權:
大家可以檢視一下Slither的【 文件 】來了解如何新增自己的printer。
工具安裝
Slither要求Python 3.6+、 solc 和Solidity編譯器。
使用pip安裝:
$ pip install slither-analyzer
使用Git安裝:
$ git clone https://github.com/trailofbits/slither.git && cd slither
$ python setup.py install
工具使用
審計單一檔案:
$slither tests/uninitialized.sol # argument can be file, folder or glob, be sureto quote the argument when using a glob [..] INFO:Detectors:Uninitializedstate variables in tests/uninitialized.sol, Contract: Uninitialized, Vars:destination, Used in ['transfer'] [..]
如果目標是一個目錄的話,它將會審計目錄中的每一個.sol檔案。
專案地址
GitHub: https://github.com/trailofbits/slither
*參考來源: trailofbits ,FB小編Alpha_h4ck編譯,轉載請註明來自FreeBuf.COM