#38223 [BC-Insight] Attackers can disrupt the tag order of gossip messages to bypass signature verif

Submitted on Dec 28th 2024 at 07:32:03 UTC by @f4lc0n for Attackathon | Stacks

  • Report ID: #38223

  • Report Type: Blockchain/DLT

  • Report severity: Insight

  • Target: https://github.com/stacks-network/sbtc/tree/immunefi_attackaton_0.9/signer

  • Impacts:

    • Permanent freezing of funds (fix requires hardfork)

    • API crash preventing correct processing of deposits

Description

Brief/Intro

When the signer processes a gossip message, it verifies the signature of the source of the message. This prevents attackers from forwarding tampered messages.

The signer determines where the digest starts based on tag 1 of the message. However, an attacker can customize the position of tag 1 to customize the position where the digest starts.

Vulnerability Details

The decode_with_digest code is as follows.

The pre_hash_data is used to mark the beginning of the digest. As long as tag is 1, the pre_hash_data will be reassigned to the current buf. Therefore, we can determine that the expected message structure is:

However, the attacker can manipulate the digest content by disrupting the order of tags. As shown in the figure below.

The attacker can put tag 1 at the end of the message. Then when decode_with_digest finds tag 1, it will assign pre_hash_data to the current buf, which is the end of the message, and the digest content will be empty.

Fortunately, the signer will add a prefix to all digests. So, for an attacker, he needs to induce other signers to sign a signature with only a prefix like "SBTC_SIGNER_WITHDRAWAL_DECISION". Then the attacker can use this signature to forge any SignerWithdrawalDecision message.

Fix

It is recommended to put the signature field first in the message instead of allowing the message to customize the signature field position.

Impact Details

This bug allows a signer to spread gossip messages as other signers. He can spread wrong SignerDepositDecision, SignerWithdrawalDecision (which can freeze the user's sBTC) and WstsMessage (which can prevent new signer set) messages.

However, this bug requires the attacker to be one of the signers (only signers can forward gossip) and requires the signer to induce other signers to sign a signature with only the prefix. So, I consider this bug to be a Medium.

References

None

Proof of Concept

Proof of Concept

Add this test case to signer/src/ecdsa.rs. This PoC demonstrates that after obtaining the "SBTC_SIGNER_WITHDRAWAL_DECISION" signature, it is possible to forge any SignerWithdrawalDecision message.

Run the test case:

Last updated

Was this helpful?