1. 程式人生 > >EOS Node Remote Code Execution Vulnerability — EOS WASM Contract Function Table Array Out of Bounds

EOS Node Remote Code Execution Vulnerability — EOS WASM Contract Function Table Array Out of Bounds

Vulnerability Credit

Yuki Chen of Qihoo 360 Vulcan Team

Zhiniang Peng of Qihoo 360 Core Security

Vulnerability Description

We found and successfully exploit a buffer out-of-bounds write vulnerability in EOS when parsing a WASM file.

To use this vulnerability, attacker could upload a malicious smart contract to the nodes server, after the contract get parsed by nodes server, the malicious payload could execute on the server and taken control of it.

After taken control of the nodes server, attacker could then pack the malicious contract into new block and further control all nodes of the EOS network.

Vulnerability Reporting Timeline

2018-5-11                  EOS Out-of-bound Write Vulnerability Found

2018-5-28                Full Exploit Demo of Compromise EOS Super Node Completed

2018-5-28                Vulnerability Details Reported to Vendor

2018-5-29                 Vendor Fixed the Vulnerability on Github and Closed the Issue

2018-5-29                   Notices the Vendor the Fixing is not complete

Some Telegram chats with Daniel Larimer:

We trying to report the bug to him.

He said they will not ship the EOS without fixing, and ask us send the report privately since some people are running public test nets

He provided his mailbox and we send the report to him

EOS fixed the vulnerability and Daniel would give the acknowledgement.

Technical Detail of the Vulnerability  

This is a buffer out-of-bounds write vulnerability

At libraries/chain/webassembly/binaryen.cpp (Line 78),Function binaryen_runtime::instantiate_module:

for (auto& segment : module->table.segments) {
Address offset = ConstantExpressionRunner<TrivialGlobalManager>(globals).visit(segment.offset).value.geti32();
assert(offset + segment.data.size() <= module->table.initial);
for (size_t i = 0; i != segment.data.size(); ++i) {
table[offset + i] = segment.data[i]; <= OOB write here !
}
}

Here table is a std::vector contains the Names in the function table. When storing elements into the table, the |offset| filed is not correctly checked. Note there is a assert before setting the value, which checks the offset, however unfortunately, |assert| only works in Debug build and does not work in a Release build.

The table is initialized earlier in the statement:

table.resize(module->table.initial);

Here |module->table.initial| is read from the function table declaration section in the WASM file and the valid value for this field is 0 ~ 1024.

The |offset| filed is also read from the WASM file, in the data section, it is a signed 32-bits value.

So basically with this vulnerability we can write to a fairly wide range after the table vector’s memory.

How to reproduce the vulnerability

  1. Build the release version of latest EOS code

./eosio-build.sh

  1. Start EOS node, finish all the necessary settings described at:
  1. Set a vulnerable contract:

We have provided a proof of concept WASM to demonstrate a crash.

In our PoC, we simply set the |offset| field to 0xffffffff so it can crash immediately when the out of bound write occurs.

To test the PoC:
cd poc
cleos set contract eosio ../poc -p eosio

If everything is OK, you will see nodeos process gets segment fault.

The crash info:

(gdb) c

Continuing.

Program received signal SIGSEGV, Segmentation fault.

0x0000000000a32f7c in eosio::chain::webassembly::binaryen::binaryen_runtime::instantiate_module(char const*, unsigned long, std::vector<unsigned char, std::allocator<unsigned char> >) ()

(gdb) x/i $pc

=> 0xa32f7c <_ZN5eosio5chain11webassembly8binaryen16binaryen_runtime18instantiate_moduleEPKcmSt6vectorIhSaIhEE+2972>:   mov    %rcx,(%rdx,%rax,1)

(gdb) p $rdx

$1 = 59699184

(gdb) p $rax

$2 = 34359738360

Here |rdx| points to the start of the |table| vector,

And |rax| is 0x7FFFFFFF8, which holds the value of |offset| * 8.

Exploit the vulnerability to achieve Remote Code Execution

This vulnerability could be leveraged to achieve remote code execution in the nodeos process, by uploading malicious contracts to the victim node and letting the node parse the malicious contract. In a real attack, the attacker may publishes a malicious contract to the EOS main network.

The malicious contract is first parsed by the EOS super node, then the vulnerability was triggered and the attacker controls the EOS super node which parsed the contract.

The attacker can steal the private key of super nodes or control content of new blocks. What’s more, attackers can pack the malicious contract into a new block and publish it. As a result, all the full nodes in the entire network will be controlled by the attacker.

We have finished a proof-of-concept exploit, and tested on the nodeos build on 64-bits Ubuntu system. The exploit works like this:

  1. The attacker uploads malicious contracts to the nodeos server.
  2. The server nodeos process parses the malicious contracts, which triggers the vulnerability.
  3. With the out of bound write primitive, we can overwrite the WASM memory buffer of a WASM module instance. And with the help of our malicious WASM code, we finally achieves arbitrary memory read/write in the nodeos process and bypass the common exploit mitigation techniques such as DEP/ASLR on 64-bits OS.
  4. Once successfully exploited, the exploit starts a reverse shell and connects back to the attacker.

You can refer to the video we provided to get some idea about what the exploit looks like, We may provide the full exploit chain later.

The Fixing of Vulnerability

Bytemaster on EOS’s github opened issue 3498 for the vulnerability that we reported:

And fixed the related code

But as the comment made by Yuki on the commit, the fixing is still have problem on 32-bits process and not so prefect.


http://blogs.360.cn/blog/eos-node-remote-code-execution-vulnerability/?from=timeline%26isappinstalled=0

相關推薦

EOS Node Remote Code Execution VulnerabilityEOS WASM Contract Function Table Array Out of Bounds

Vulnerability CreditYuki Chen of Qihoo 360 Vulcan TeamZhiniang Peng of Qihoo 360 Core SecurityVulnerability DescriptionWe found and successfully exploit a

CVE-2010-0483分析 Microsoft Internet Explorer 6/7/8 - 'winhlp32.exe' 'MsgBox()' Remote Code Execution

pre reat ctrl+ 進一步 calc 打開 find mman 客戶端   相關資料:https://www.exploit-db.com/exploits/11615/   目的是為了了解漏洞執行的流程。 根據資料準備服務端環境:   用一臺win7當做是服務器

CVE-2010-0265分析 Microsoft Movie Maker - Remote Code Execution (MS10-016)

-1 模塊 發現 ebo manage 一個 信息 虛函數 ges 相關鏈接:https://www.exploit-db.com/exploits/14886/ 環境介紹:XP Professional sp 3 Movie Maker 2.1.4026.

[EXP]Microsoft Windows MSHTML Engine - "Edit" Remote Code Execution

edi ast color author making special file b- test # Exploit Title: Microsoft Windows (CVE-2019-0541) MSHTML Engine "Edit" Remote Code E

[EXP]Microsoft Windows CONTACT - Remote Code Execution

com class efault windows 7 color uri creat .com init [+] Credits: John Page (aka hyp3rlinx) [+] Website: hyp3rlinx.altervista.

[EXP]Apache Superset < 0.23 - Remote Code Execution

class div chang upgrade logo man cred hang firefox # Exploit Title: Apache Superset < 0.23 - Remote Code Execution # Date: 2018-05-

CVE2017-12615漏洞復現( tomcat JSP Upload Bypass /Remote Code Execution)

CVE2017-12615漏洞復現( tomcat JSP Upload Bypass /Remote Code Execution) 一、漏洞原理 在windows伺服器下,將readonly引數設定為false時,即可通過PUT方式建立一個jsp檔案,並可以執行任意程式碼。Tomcat版本內web.x

(五)eos開發實戰dapp+遊戲--編譯eos.token table空,檢視使用者幣Error 3060003: Contract Table Query Exception

開言:此教材只是個人學習過程記錄自己理解和各種坑如有問題可提出修正,個人注重是開發動手,小白,寫也是為了重複加深印象,目標此教學習實現開發一個EOS小遊戲,堅持.......  環境: Mac+EOS-1.3.0 任務:發幣bug,上章發幣編譯自帶eos.token 發幣查

痛苦的EOS資料同步,可能的EOS安全隱患

    以太坊中,每個區塊交易執行後,會更新狀態資料並生成一個merkle root(可以看成是狀態資料摘要),同時這個state merkle root也會儲存在BlockHeader裡,也就說以太坊的狀態資料是上鍊的。所以後面節點在replay block交易時可以很

EOS還有短帳戶?EOS賬戶競拍瞭解一下

通常情況下,EOS賬戶都是12位“數字+字母”的組合,即由小寫字母a-z和數字1-5組成,我們在各大錢包註冊賬戶的時候也只能註冊12位的賬戶地址。 不過,EOS系統中是有短賬戶存在的,根據EOS賬戶名的格式限制,小於12位的賬戶必須啟用競拍機制,我們可以在EOS系統中進行【賬戶競拍】,例

Run Node.js code in Jupyter Notebooks

Summary For years, academics and research scientists have used data science notebooks as scratchpads for writing code, refining algor

史上最全!支援EOS對映的交易所統計|關於EOS對映,你想知道的都在這

01EOS對映是什麼?為什麼要進行對映?EOS眾籌將在北京時間2018年6月2日06:59:59結束,主網上線在即,你的EOS做好映射了嗎?當下EOS主網還沒有上線,市場上流通的EOS只是基於以太坊網路的“臨時代幣”,並不是真正意義上的EOS。當主網上線後,這些代幣將完成自己

Microsoft IIS FTP Service CVE-2012-2532 Remote Command Injection Vulnerability

Copyright © 2017 Symantec Corporation. Permission to redistribute this alert electronically is granted as long as it is not edited in any way unless autho

EOS代碼分析1 理解EOS共識機制BFT-DPoS

.com 目前 DPoS 錯誤 eos 解決 gate pos 假設 EOS 最新的白皮書中已經將共識機制從 DPoS 升級為了 BFT-DPoS(Byzantine Fault Tolerance - Deligated Proof of Stake,帶有拜占庭容錯的委托

Error Code: 1786 Statement violates GTID consistency: CREATE TABLE ... SELECT.

1、錯誤描述 1 queries executed, 0 success, 1 errors, 0 warnings 查詢:call account_check_main('20180511') 錯誤程式碼: 1786 Statement violates GTID consistency: CR

[MySQL] Error Code: 1140. In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column; this

今天遇到這個Error 滿神奇的,只有出現在部份的 MySQL server 上。我的 SQL: update TABLE_A as c inner join (select count(*) as MY_COUNT, l1.device_id from TABLE_B as l1 where l1.log

(node.js)webpack打包報javaScript heap out of memory,記憶體溢位,如何解決

基於vue的專案在執行npm run dev的時候會報記憶體溢位,所以查了一些相關的資料總結了一下,下面會詳細說明這個問題具體怎麼解決。首先看我模擬出的報錯內容具體截圖如下: 裡面有句關鍵的話,CALL_AND_RETRY_LAST Allocation failed - JavaScri

Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option t

開發中進行資料請求時候報了這個錯誤 這是因為AFN網路請求返回資料格式為json,提示這個錯誤是因為返回資料非json格式。 解決辦法: 首先檢查一下網路請求方法中是否有這句程式碼 //設定返回資料格式為JSON manager.response

手機欄位儲存報錯 :Warning Code : 1264 Out of range value for column 'buyer_tpl' at row 1

企鵝上朋友問我: 我這明明是11位的int 為啥還說超出範圍了呢,然後發來報警截圖 我看到是 buyer_tpl int(13)  unsigned NOT NULL,就知道是怎麼回事了,開啟dev.mysql.com/doc,找到int的章節,截圖發給他 手

EOS區塊鏈開發IDE推薦使用Visual Studio Code和CLion

boa 合約 成了 ofo 現在 chang view pts ios 每一個開發人員都需要一個良好的IDE,EOS開發也是一樣,為項目開發過程構建一個良好的IDE環境是第一步。這就是為什麽我們要寫這個如何使用VS Code或者CLion進行EOS開發的快速教程的原因。 我