#38146 [BC-Medium] nimbus-eth2 remote crash

Submitted on Dec 26th 2024 at 08:23:45 UTC by @gln for Attackathon | Ethereum Protocol

  • Report ID: #38146

  • Report Type: Blockchain/DLT

  • Report severity: Medium

  • Target: https://github.com/status-im/nimbus-eth2

  • Impacts:

    • Direct loss of funds

    • Shutdown of greater than or equal to 10% or equal to but less than 33% of network processing nodes without brute force actions, but does not shut down the network

Description

Brief/Intro

Nimbus-eth2 libp2p incorrectly parses protobuf messages. As a result it will lead to denial of service issue.

Vulnerability Details

First we need to see how Nim converts uint64 to int type.

Consider the following simple nim program:

If you compile and run it, you will receive the exception:

So, If the value of uint64 is larger than 0x7fffffff_ffffffff, fatal RangeDefect exception will be thrown and program will stop.

In gossipsub protocol RPC messages are encoded by using protobuf.

In case of nimbus-eth2 it is handled by custom protobuf library - miniprotobuf.nim

Let's look at the code https://github.com/vacp2p/nim-libp2p/blob/8855bce0854ecf4adad7a0556bb2b2d2f98e0e20/libp2p/varint.nim#L106

  1. If vtype is PB, there are no checks for parsed.val, it can be arbitrary large value

Now we need to see how protobuf parser is being used https://github.com/vacp2p/nim-libp2p/blob/8855bce0854ecf4adad7a0556bb2b2d2f98e0e20/libp2p/protocols/pubsub/rpc/protobuf.nim#L331

Let's look at the actual parser https://github.com/vacp2p/nim-libp2p/blob/8855bce0854ecf4adad7a0556bb2b2d2f98e0e20/libp2p/protobuf/minprotobuf.nim#L344

  1. Note that maxSize is equal to uint.high

  2. Varint is fetched from incoming stream

  3. Even if bsize is larger than 0x7fffffff_ffffffff, the check will pass because data.maxSize is equal to 0xffffffff_ffffffff

  4. Nim throws fatal exception when trying to convert bsize to 'int' type

Impact Details

Basically, attacker will be able to crash nimbus-eth2 nodes remotely with a single packet.

https://gist.github.com/gln7/e41de97351999a048e30436d05593dbd

Proof of Concept

Proof of Concept

How to reproduce:

  1. get nimbus-eth2 source code

  1. apply patch to nim-libp2p (see gist link)

  2. run localnet:

  1. after some time, you should see exception in local-testnet-minimal/logs/nimbus_beacon_node.1.jsonl

Was this helpful?