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

EOS智能合约远程代码执行漏洞
本文披露了EOS中一个严重的远程代码执行漏洞,该漏洞出现在解析WASM文件的过程中,导致越界写入。攻击者可通过上传恶意智能合约来利用此漏洞,进而控制EOS超级节点并进一步控制整个EOS网络。

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:

https://github.com/EOSIO/eos/wiki/Tutorial-Getting-Started-With-Contracts

  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

Spring Core Framework 的远程代码执行(Remote Code Execution, RCE)漏洞是近年来在 Spring 框架中发现的一个严重安全问题。该漏洞主要影响 Spring Framework 和 Spring Boot 的某些版本,攻击者可以通过特定的攻击向量在目标系统上执行任意代码,从而可能导致系统被完全控制。 ### 漏洞细节 该漏洞的核心在于 Spring Framework 的数据绑定机制中存在一个不安全的反序列化问题。具体来说,当应用程序使用了 `DataBinder` 或 `@InitBinder` 来处理用户输入,并且没有正确限制可绑定的字段类型时,攻击者可能通过构造恶意输入来触发反序列化漏洞,从而导致远程代码执行[^4]。 此漏洞通常与 Java 的反序列化机制有关,尤其是在处理不可信数据时,如果没有适当的防护措施,攻击者可以利用这一点注入恶意对象,进而执行任意命令。 ### 影响范围 该漏洞影响的版本包括但不限于: - Spring Framework < 5.3.18 - Spring Boot < 2.6.7 如果应用程序使用了受影响的版本并且暴露了可被攻击的端点,则可能受到威胁。尤其是那些依赖 Spring 的 Web MVC 模块进行数据绑定的应用程序更容易受到影响[^4]。 ### 漏洞影响 该漏洞可能导致以下安全风险: - **远程代码执行**:攻击者可以在目标服务器上执行任意命令,进而完全控制受影响的系统。 - **数据泄露**:攻击者可以访问敏感数据,包括数据库凭证、用户信息等。 - **服务中断**:攻击者可以破坏服务或植入恶意代码,导致系统不可用。 - **横向移动**:一旦入侵成功,攻击者可以利用受控系统作为跳板,进一步攻击内部网络中的其他系统。 ### 修复建议 为了缓解此漏洞,建议采取以下措施: 1. **升级 Spring Framework 和 Spring Boot 版本**: - 升级到 Spring Framework 5.3.18 或更高版本。 - 升级到 Spring Boot 2.6.7 或更高版本。 2. **限制数据绑定的字段类型**: - 避免在 `@InitBinder` 中允许绑定所有字段类型,建议显式指定允许的字段。 - 使用 `WebDataBinder` 时,调用 `setAllowedFields()` 方法限制可绑定的字段。 3. **避免反序列化不可信数据**: - 对于需要反序列化的数据,确保其来源可信,并考虑使用更安全的序列化格式(如 JSON)。 4. **启用安全防护机制**: - 使用 Web 应用防火墙(WAF)来检测和拦截恶意请求。 - 启用日志审计,监控异常行为。 ### 示例修复代码 ```java @Controller public class UserController { @InitBinder public void initBinder(WebDataBinder binder) { // 限制允许绑定的字段 binder.setAllowedFields("username", "email"); } } ``` 上述代码通过 `setAllowedFields()` 方法限制了可绑定的字段,从而减少了攻击面。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值