Skip to content
DoS Disclosed report Intermediate

DoS through PeerExplorer

The peer discovery implementation in RSKj fails to remove challenge entries when a peer does not respond to a challenge ping, allowing an attacker to create unlimited in-memory entries. An attacker could exhaust memory and crash any RSKj node with peer discovery enabled.

z3t Follow

Originally disclosed on HackerOne

Bounty$4,000 High 7.7 View original
  • Triaged in 3 days
  • Fixed in 5 days
  • Paid in 5 days
  • Disclosed after 15 months

Summary: The peer discovery implementation is vulnerable to a Denial of Service attack due to improper management of connections.

Description: The two main files of interest in detailing this vulnerability are PeerExplorer.java and NodeChallengeManager.java. To explain the flow of execution I'll be mentioning two theoretical nodes: an attacker, "N1" and a target, "N2".

When N1 sends an initial "ping" message to N2, N2 will reply with a "pong" message and a subsequent ping message to continue the handshake. After this, when N1 replies with a pong message, N2 will attempt to add N1 to its structure holding established connections. The relevant code snippets from PeerExplorer.java are below:

public void handlePong(String ip, PongPeerMessage message) {
	PeerDiscoveryRequest request = this.pendingPingRequests.get(message.getMessageId());

	if (request != null && request.validateMessageResponse(message)) {
		this.pendingPingRequests.remove(message.getMessageId());
		NodeChallenge challenge = this.challengeManager.removeChallenge(message.getMessageId());
		if (challenge == null) {
			this.addConnection(message, ip, message.getPort());
		}
	}
}
...
private void addConnection(PongPeerMessage message, String ip, int port) {
	Node senderNode = new Node(message.getNodeId().getID(), ip, port);
	if (!StringUtils.equals(senderNode.getHexId(), this.localNode.getHexId())) {
		OperationResult result = this.distanceTable.addNode(senderNode);

		if (result.isSuccess()) {
			NodeID senderId = senderNode.getId();
			this.establishedConnections.put(senderId, senderNode);
			logger.debug("New Peer found ip:[{}] port[{}]", ip, port);
		} else {
			this.challengeManager.startChallenge(result.getAffectedEntry().getNode(), senderNode, this);
		}
	}
}

The addConnection method first attempts to add N1 to the NodeDistanceTable - a structure designed to hold a limited number of nodes (by default, 4096). If this insertion fails due to the target NodeDistanceTable bucket already being full, the attempted connection is instead added to NodeChallengeManager. The relevant code snippets from NodeChallengeManager.java are below:

public NodeChallenge startChallenge(Node challengedNode, Node challenger, PeerExplorer explorer) {
	PingPeerMessage pingMessage = explorer.sendPing(challengedNode.getAddress(), 1, challengedNode);
	String messageId = pingMessage.getMessageId();
	NodeChallenge challenge = new NodeChallenge(challengedNode, challenger, messageId);
	activeChallenges.put(messageId, challenge);
	return challenge;
}

public NodeChallenge removeChallenge(String challengeId) {
	return activeChallenges.remove(challengeId);
}

Through the startChallenge method N2 will send N1 another ping message, adding a "challenge" to activeChallenges with that new ping message's messageId. The issue here is that the entry is only ever removed from activeChallenges if N1 replies with a pong that has the same messageId as the new ping message - as seen in PeerExplorer.handlePong. Thus, N1 is able to create an arbitrary number of entries in activeChallenges by never sending N2 a pong with the challenge ping's messageId.

It should be noted that there is a slight limitation as to how this could be exploited by a single host. The relevant code snippets from PeerExplorer.java are below:

public PingPeerMessage sendPing(InetSocketAddress nodeAddress, int attempt, Node node) {
	PingPeerMessage nodeMessage = checkPendingPeerToAddress(nodeAddress);

	if (nodeMessage != null) {
		return nodeMessage;
	}
	....
}
...
private PingPeerMessage checkPendingPeerToAddress(InetSocketAddress address) {
	for (PeerDiscoveryRequest req : this.pendingPingRequests.values()) {
		if (req.getAddress().equals(address)) {
			return (PingPeerMessage) req.getMessage();
		}
	}

	return null;
}

The sendPing method will only ever actually send a new ping to N1 if there are no pending pings to its InetSocketAddress (which is deemed equal if the host and port match) - as seen in checkPendingPeerToAddress. However, pending pings have a set expiry time (by default, 30 seconds) and those that have expired are cleared by PeerExplorerCleaner at a fixed rate (by default, every 60 seconds). So due to this limitation, with the default configuration settings a single host can only complete 65,535 handshakes (one per port) every minute - imposing a (perhaps unreachable) limit on the time it takes to exhaust the target node's memory. Though this can obviously be circumvented by using multiple hosts to attack a target node.

Because most peer discovery functionality identifies nodes by their NodeID and not by host/port, it's trivial to send a flood of requests with unique NodeIDs to fill NodeDistanceTable and subsequently make an unrestricted amount of in-memory insertions into NodeChallengeManager.activeChallenges. This is further aided by the fact that NodeChallengeManager is never purged, so the request flood does not have to occur within a short period of time. Memory exhaustion will eventually occur as the NodeChallenge objects begin taking up a significant amount of memory and are not eligible for garbage collection. This is expected to eventually disable node functionality as individual threads die when they throw OutOfMemoryErrors, but in my testing it ended up crashing the whole JVM after reaching ~200,000 insertions.

Steps To Reproduce:

I've attached a PoC program that interfaces with the RSKj library for the sake of simplicity. Due to the PoC program being somewhat inefficient and unreliable, I ended up accelerating the testing process by modifying my testing node's NodeChallengeManager to make 10 insertions per valid startChallenge call. If you're interested in running the PoC despite those issues, follow these steps:

  1. Download a copy of the RSKj code
  2. Move the PoC files into the co.rsk.net.discovery package (overwrite PeerExplorer.java with my modified version)
  3. Launch a node for testing - ensure peer discovery is enabled
  4. Compile and run the PoC from PeerFlood - arguments format: <local_address> <target_address> <target_port> <num_threads>
  5. Monitor testing node's logs and stability

If you're developing your own PoC, you need to simply flood a testing node with connections that use random NodeIDs, completing a single ping<->pong handshake then immediately disconnecting.

Mitigation

This could be mitigated by implementing expiring challenges that are cleared by PeerExplorerCleaner.

Impact

An attacker could crash any RSKj node with peer discovery enabled (which it is by default).

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

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

RSKj is the Java implementation of the Rootstock node. Among its features is peer discovery, the mechanism by which a node finds and maintains a set of peers. Two classes carry most of the logic: PeerExplorer.java and NodeChallengeManager.java, both in the co.rsk.net.discovery package.

The discovery flow is a ping/pong handshake. When a node receives an initial ping, it replies with a pong and sends its own ping to continue the handshake. When the other side answers that ping with a pong, the receiving node tries to record the peer as an established connection. The set of known peers is held in a NodeDistanceTable, a structure designed to hold a limited number of nodes, 4096 by default. When a bucket in that table is full, the candidate is not simply dropped: it is passed to NodeChallengeManager, which starts a challenge to decide whether the newcomer should displace an existing entry.

The report describes a way to abuse that challenge path so that a remote party can grow an in-memory structure without limit, eventually exhausting the node's memory.

Setup

No accounts or special roles are involved. The precondition is a running RSKj node with peer discovery enabled, which the report says is the default. The researcher used two theoretical nodes to describe the flow: an attacker, "N1", and a target, "N2".

For reproduction, the researcher wrote a PoC program that interfaces with the RSKj library. Because that PoC was somewhat inefficient and unreliable, testing was accelerated by modifying the testing node's NodeChallengeManager so that each valid startChallenge call performed 10 insertions instead of one.

Finding it

The researcher focused on the interaction between PeerExplorer and NodeChallengeManager. In PeerExplorer, the pong handler looks up the pending request by message ID, validates the response, removes the pending request, and then removes the challenge associated with that message ID. Only if no challenge existed does it call addConnection:

public void handlePong(String ip, PongPeerMessage message) {
	PeerDiscoveryRequest request = this.pendingPingRequests.get(message.getMessageId());

	if (request != null && request.validateMessageResponse(message)) {
		this.pendingPingRequests.remove(message.getMessageId());
		NodeChallenge challenge = this.challengeManager.removeChallenge(message.getMessageId());
		if (challenge == null) {
			this.addConnection(message, ip, message.getPort());
		}
	}
}
...
private void addConnection(PongPeerMessage message, String ip, int port) {
	Node senderNode = new Node(message.getNodeId().getID(), ip, port);
	if (!StringUtils.equals(senderNode.getHexId(), this.localNode.getHexId())) {
		OperationResult result = this.distanceTable.addNode(senderNode);

		if (result.isSuccess()) {
			NodeID senderId = senderNode.getId();
			this.establishedConnections.put(senderId, senderNode);
			logger.debug("New Peer found ip:[{}] port[{}]", ip, port);
		} else {
			this.challengeManager.startChallenge(result.getAffectedEntry().getNode(), senderNode, this);
		}
	}
}

addConnection first tries to insert the sender into the NodeDistanceTable. If the insertion succeeds, the peer goes into establishedConnections. If it fails because the affected bucket is already full, the code calls startChallenge on the node that currently occupies the affected entry, passing the sender as the challenger.

The challenge manager itself is small:

public NodeChallenge startChallenge(Node challengedNode, Node challenger, PeerExplorer explorer) {
	PingPeerMessage pingMessage = explorer.sendPing(challengedNode.getAddress(), 1, challengedNode);
	String messageId = pingMessage.getMessageId();
	NodeChallenge challenge = new NodeChallenge(challengedNode, challenger, messageId);
	activeChallenges.put(messageId, challenge);
	return challenge;
}

public NodeChallenge removeChallenge(String challengeId) {
	return activeChallenges.remove(challengeId);
}

startChallenge sends another ping and stores a NodeChallenge in activeChallenges, keyed by that new ping's messageId. The researcher's observation is that the entry is only ever removed from activeChallenges when the other side replies with a pong carrying the same messageId as the challenge ping, as seen in PeerExplorer.handlePong. A party that never sends that pong can therefore create an arbitrary number of entries in activeChallenges.

Exploitation

Step 1: complete the initial handshake

N1 sends an initial ping to N2. N2 replies with a pong and a subsequent ping to continue the handshake. N1 answers with a pong. N2 then attempts to add N1 to its structure of established connections through handlePong and addConnection.

Step 2: force the challenge path

If the NodeDistanceTable insertion fails because the target bucket is full, addConnection calls startChallenge. N2 sends N1 another ping, and a NodeChallenge is stored in activeChallenges under that ping's messageId.

Step 3: never answer the challenge ping

N1 simply does not send a pong with the challenge ping's messageId. The entry stays in activeChallenges indefinitely. Repeating the handshake with fresh identities grows the map without bound.

The per-host limit

There is a limitation on how far a single host can take this. sendPing checks for an existing pending request to the same address before sending anything new:

public PingPeerMessage sendPing(InetSocketAddress nodeAddress, int attempt, Node node) {
	PingPeerMessage nodeMessage = checkPendingPeerToAddress(nodeAddress);

	if (nodeMessage != null) {
		return nodeMessage;
	}
	....
}
...
private PingPeerMessage checkPendingPeerToAddress(InetSocketAddress address) {
	for (PeerDiscoveryRequest req : this.pendingPingRequests.values()) {
		if (req.getAddress().equals(address)) {
			return (PingPeerMessage) req.getMessage();
		}
	}

	return null;
}

A new ping is only actually sent to N1 if there are no pending pings to its InetSocketAddress, where equality means the host and port both match. Pending pings expire after a set time, 30 seconds by default, and expired ones are cleared by PeerExplorerCleaner at a fixed rate, every 60 seconds by default. With the default configuration, the report concludes that a single host can complete at most 65,535 handshakes (one per port) per minute, which imposes a limit, perhaps unreachable in practice, on how quickly the target's memory can be exhausted. Using multiple hosts circumvents this.

Step 4: flood with unique NodeIDs

Most peer discovery functionality identifies nodes by their NodeID, not by host and port. It is therefore trivial to send a flood of requests with unique NodeIDs, fill NodeDistanceTable, and then make an unrestricted number of in-memory insertions into NodeChallengeManager.activeChallenges. Because NodeChallengeManager is never purged, the flood does not have to happen within a short window. Memory exhaustion follows as NodeChallenge objects accumulate and are not eligible for garbage collection. The report expects node functionality to be disabled as individual threads die on OutOfMemoryError, but in the researcher's testing the whole JVM crashed after roughly 200,000 insertions.

Reproduction steps

The researcher attached a PoC program that interfaces with the RSKj library. The steps given are:

  1. Download a copy of the RSKj code.
  2. Move the PoC files into the co.rsk.net.discovery package, overwriting PeerExplorer.java with the modified version.
  3. Launch a node for testing, ensuring peer discovery is enabled.
  4. Compile and run the PoC from PeerFlood with arguments in the format <local_address> <target_address> <target_port> <num_threads>.
  5. Monitor the testing node's logs and stability.

For anyone writing their own PoC, the recipe is to flood a testing node with connections that use random NodeIDs, complete a single ping/pong handshake, then immediately disconnect.

Root cause

NodeChallengeManager.startChallenge inserts a challenge into activeChallenges keyed by the message ID of a ping it sends, but the only removal path is removeChallenge, called from PeerExplorer.handlePong when a matching pong arrives. A peer that never answers the challenge ping leaves the entry in place forever. There is no expiry and no purge of activeChallenges, so the structure grows with every challenge started. The NodeDistanceTable limit of 4096 nodes does not protect the challenge manager; it is precisely the full table that routes new candidates into the challenge path. The pending-ping expiry and the PeerExplorerCleaner only bound how fast a single host can drive the handshake, not how much memory the challenges consume over time.

Impact

An attacker could crash any RSKj node with peer discovery enabled, which the report says is the default. The failure mode observed was a JVM crash after around 200,000 insertions, with thread death from OutOfMemoryError expected before that. The attack requires the ability to reach the node's peer discovery service and to present many distinct NodeIDs; a single host is rate-limited by the pending-ping logic, which multiple hosts circumvent.

Fix

The report's mitigation is to implement expiring challenges that are cleared by PeerExplorerCleaner, so that unanswered challenges do not accumulate indefinitely.

Variants to test

  • Look for other maps keyed by message or request IDs that are only cleaned up on a successful response. A positive result is a map whose size grows when you complete a handshake but never send the expected follow-up.
  • Check whether a bounded structure (a distance table, a peer cache, a rate limiter) routes overflow into an unbounded secondary structure. A positive result is an overflow path that allocates without a corresponding eviction.
  • Test whether identity is keyed by a value the client controls (here NodeID) rather than by network address. A positive result is being able to create many entries from one host by varying that value.
  • Probe the cleaner: find structures that the periodic cleaner does not touch. A positive result is memory that survives several cleaner cycles.

Hunting notes

This kind of bug tends to hide in handshake and challenge state machines, where an entry is created on an outgoing message and removed only on a matching incoming reply. During recon, look for peer-to-peer or discovery services exposed by default, and for code paths where a full bounded table hands work to a second structure. The signal is a put whose only matching remove sits behind a validation check the remote side controls.

To show impact, the researcher measured growth until failure: roughly 200,000 insertions led to a JVM crash, and the report explains the per-host rate limit and how multiple hosts remove it. That combination, a default-enabled feature, a clear memory growth path, and an observed crash, is what makes the case for a high-severity denial of service.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 19 min read.

What happened, in plain words

RSKj is a piece of software that runs a Rootstock node. A node is a computer that takes part in a blockchain network: it keeps a copy of the shared ledger and talks to other nodes so that everyone stays in sync. To do that, a node needs to know which other nodes exist and which ones it can trust to talk to. The feature that handles this is called peer discovery. A "peer" is simply another node on the network.

Peer discovery works a bit like introducing yourself at a party. One node says hello (a "ping"), the other says hello back (a "pong"), and after a short back and forth they agree to stay in touch. The report found that an attacker can abuse this introduction ritual to make a node keep a growing list of half-finished introductions in its memory. If the list grows long enough, the node runs out of memory and crashes. This kind of attack is called a Denial of Service (DoS): the goal is not to steal data, but to stop a service from working.

Context

Two files carry most of the logic described here, both inside a package called co.rsk.net.discovery:

  • PeerExplorer.java, which runs the ping/pong conversation and keeps track of known peers.
  • NodeChallengeManager.java, which handles a special "challenge" step used when the node's table of known peers is full.

A quick word on Java, since the code is in Java. Java is a programming language. A "class" is a blueprint for a piece of code that bundles data and the actions that can be performed on it. A "method" is one of those actions, a named block of code that does something when called. When you see something.methodName(...) in the code below, it means "run the method called methodName on the object called something".

The discovery flow is a ping/pong handshake. A handshake is a short exchange where two sides confirm they can talk to each other, like two people shaking hands before a conversation. When a node receives an initial ping, it replies with a pong and sends its own ping to continue the handshake. When the other side answers that ping with a pong, the receiving node tries to record the peer as an established connection, meaning a peer it now considers known and usable.

The set of known peers is held in a NodeDistanceTable. Think of it as a shelf with a fixed number of slots: it is designed to hold a limited number of nodes, 4096 by default. When a slot (the report calls it a "bucket") in that table is full, the newcomer is not simply thrown away. Instead it is passed to NodeChallengeManager, which starts a challenge: a small contest to decide whether the newcomer deserves to push out an existing entry. This is a sensible design idea, because it lets fresh, healthy peers replace stale ones.

The report describes a way to abuse that challenge path so that a remote party can grow an in-memory structure without limit, eventually exhausting the node's memory. "In memory" means in the computer's working memory (RAM), as opposed to on disk. Memory is finite, so anything that grows without a limit is a problem.

Setup

No accounts or special roles are involved. The precondition is a running RSKj node with peer discovery enabled, which the report says is the default. "Default" means the setting as shipped, without anyone changing it, so every ordinary node is exposed unless someone deliberately turns the feature off.

The researcher used two theoretical nodes to describe the flow: an attacker, "N1", and a target, "N2". Naming them makes it easier to follow who sends what to whom.

For reproduction, the researcher wrote a PoC program. PoC stands for "proof of concept": a small program that demonstrates the bug really works, rather than just describing it on paper. That PoC interfaces with the RSKj library, meaning it reuses the project's own code instead of reimplementing the protocol from scratch. Because that PoC was somewhat inefficient and unreliable, testing was accelerated by modifying the testing node's NodeChallengeManager so that each valid startChallenge call performed 10 insertions instead of one. In other words, the researcher made the target node's memory grow ten times faster per step, purely to save time while testing.

Finding it

The researcher focused on the interaction between PeerExplorer and NodeChallengeManager. In PeerExplorer, the pong handler looks up the pending request by message ID, validates the response, removes the pending request, and then removes the challenge associated with that message ID. Only if no challenge existed does it call addConnection.

A "message ID" is a unique label attached to each message, so that a reply can be matched to the exact request it answers. Think of a support ticket number: when a reply arrives, the number tells you which ticket it belongs to. "Pending" means waiting for an answer.

Here is the first code block from the report:

public void handlePong(String ip, PongPeerMessage message) {
	PeerDiscoveryRequest request = this.pendingPingRequests.get(message.getMessageId());

	if (request != null && request.validateMessageResponse(message)) {
		this.pendingPingRequests.remove(message.getMessageId());
		NodeChallenge challenge = this.challengeManager.removeChallenge(message.getMessageId());
		if (challenge == null) {
			this.addConnection(message, ip, message.getPort());
		}
	}
}
...
private void addConnection(PongPeerMessage message, String ip, int port) {
	Node senderNode = new Node(message.getNodeId().getID(), ip, port);
	if (!StringUtils.equals(senderNode.getHexId(), this.localNode.getHexId())) {
		OperationResult result = this.distanceTable.addNode(senderNode);

		if (result.isSuccess()) {
			NodeID senderId = senderNode.getId();
			this.establishedConnections.put(senderId, senderNode);
			logger.debug("New Peer found ip:[{}] port[{}]", ip, port);
		} else {
			this.challengeManager.startChallenge(result.getAffectedEntry().getNode(), senderNode, this);
		}
	}
}

Line by line, in plain words:

  1. public void handlePong(String ip, PongPeerMessage message) declares a method that runs when a pong arrives. It receives the sender's IP address and the pong message itself. An IP address is the numeric address of a computer on a network, like a postal address for machines.
  2. PeerDiscoveryRequest request = this.pendingPingRequests.get(message.getMessageId()); looks in the list of pending pings for the one whose ID matches this pong. If nothing matches, request is null, which in Java means "nothing here".
  3. if (request != null && request.validateMessageResponse(message)) continues only if a matching pending request exists and the pong passes validation, meaning it is a plausible answer to that request.
  4. this.pendingPingRequests.remove(message.getMessageId()); removes the pending request, because it has now been answered.
  5. NodeChallenge challenge = this.challengeManager.removeChallenge(message.getMessageId()); asks the challenge manager to remove any challenge stored under this same message ID, and keeps the result.
  6. if (challenge == null) means: only if there was no challenge under that ID.
  7. this.addConnection(message, ip, message.getPort()); then records the peer as a connection. A port is a numbered channel on a computer, so one machine can run several services; host plus port identifies one specific service.
  8. private void addConnection(...) is the method that actually records a peer. private means it can only be called from inside this class.
  9. Node senderNode = new Node(message.getNodeId().getID(), ip, port); builds a node object from the sender's node ID, IP and port. A NodeID is the identifier a node uses for itself on the network, and it is chosen by that node, not assigned by anyone else.
  10. if (!StringUtils.equals(senderNode.getHexId(), this.localNode.getHexId())) skips the case where the sender is this very node, comparing the two IDs as text.
  11. OperationResult result = this.distanceTable.addNode(senderNode); tries to put the sender into the distance table, the shelf with 4096 slots, and stores whether it worked.
  12. if (result.isSuccess()) handles the success case.
  13. NodeID senderId = senderNode.getId(); and this.establishedConnections.put(senderId, senderNode); store the peer in the map of established connections. A map (also called a dictionary) is a structure that stores values under keys, like a phone book storing numbers under names.
  14. logger.debug(...) writes a debug line to the log, a running record of what the program did.
  15. } else { is the failure case: the table was full.
  16. this.challengeManager.startChallenge(result.getAffectedEntry().getNode(), senderNode, this); then starts a challenge between the node currently occupying the affected slot and the newcomer.

addConnection first tries to insert the sender into the NodeDistanceTable. If the insertion succeeds, the peer goes into establishedConnections. If it fails because the affected bucket is already full, the code calls startChallenge on the node that currently occupies the affected entry, passing the sender as the challenger.

The challenge manager itself is small:

public NodeChallenge startChallenge(Node challengedNode, Node challenger, PeerExplorer explorer) {
	PingPeerMessage pingMessage = explorer.sendPing(challengedNode.getAddress(), 1, challengedNode);
	String messageId = pingMessage.getMessageId();
	NodeChallenge challenge = new NodeChallenge(challengedNode, challenger, messageId);
	activeChallenges.put(messageId, challenge);
	return challenge;
}

public NodeChallenge removeChallenge(String challengeId) {
	return activeChallenges.remove(challengeId);
}

Again line by line:

  1. public NodeChallenge startChallenge(Node challengedNode, Node challenger, PeerExplorer explorer) declares the method that begins a challenge. It takes the node being challenged, the newcomer doing the challenging, and the explorer object that can send messages.
  2. PingPeerMessage pingMessage = explorer.sendPing(challengedNode.getAddress(), 1, challengedNode); sends a ping to the challenged node and keeps the ping message. The 1 is an attempt counter passed along.
  3. String messageId = pingMessage.getMessageId(); reads the unique ID of that new ping.
  4. NodeChallenge challenge = new NodeChallenge(challengedNode, challenger, messageId); creates a challenge object holding the two nodes and that message ID.
  5. activeChallenges.put(messageId, challenge); stores the challenge in the map of active challenges, under the ping's message ID. This is the insertion that matters.
  6. return challenge; hands the challenge back to the caller.
  7. public NodeChallenge removeChallenge(String challengeId) declares the only removal method: it takes a challenge ID.
  8. return activeChallenges.remove(challengeId); deletes the entry with that ID from the map and returns it, or returns null if there was none.

startChallenge sends another ping and stores a NodeChallenge in activeChallenges, keyed by that new ping's messageId. The researcher's observation is that the entry is only ever removed from activeChallenges when the other side replies with a pong carrying the same messageId as the challenge ping, as seen in PeerExplorer.handlePong. A party that never sends that pong can therefore create an arbitrary number of entries in activeChallenges.

In everyday terms: imagine a bouncer who, when the guest list is full, hands the newcomer a numbered ticket and says "come back with this ticket and we will sort it out". The bouncer writes the ticket number in a notebook. If the newcomer never comes back, the notebook entry stays forever. Nobody ever crosses it out, and nobody ever throws the notebook away. The attacker is the newcomer who takes the ticket, walks off, and repeats with a new name.

Exploitation

Step 1: complete the initial handshake

N1 sends an initial ping to N2. N2 replies with a pong and a subsequent ping to continue the handshake. N1 answers with a pong. N2 then attempts to add N1 to its structure of established connections through handlePong and addConnection.

This step is needed because the vulnerable code only runs after a normal, successful-looking introduction. The attacker has to behave like a well-behaved peer up to this point; the misbehaviour comes later.

Step 2: force the challenge path

If the NodeDistanceTable insertion fails because the target bucket is full, addConnection calls startChallenge. N2 sends N1 another ping, and a NodeChallenge is stored in activeChallenges under that ping's messageId.

Why force this path? Because the challenge path is the one that writes into the unbounded map. The distance table is capped at 4096 entries, so it cannot grow out of control on its own. The challenge manager has no such cap.

Step 3: never answer the challenge ping

N1 simply does not send a pong with the challenge ping's messageId. The entry stays in activeChallenges indefinitely. Repeating the handshake with fresh identities grows the map without bound.

"Fresh identities" here means new NodeID values. Since the node ID is chosen by the connecting side, the attacker can invent as many as it likes. Each invented identity that reaches the challenge path leaves one more permanent entry behind.

The per-host limit

There is a limitation on how far a single host can take this. sendPing checks for an existing pending request to the same address before sending anything new:

public PingPeerMessage sendPing(InetSocketAddress nodeAddress, int attempt, Node node) {
	PingPeerMessage nodeMessage = checkPendingPeerToAddress(nodeAddress);

	if (nodeMessage != null) {
		return nodeMessage;
	}
	....
}
...
private PingPeerMessage checkPendingPeerToAddress(InetSocketAddress address) {
	for (PeerDiscoveryRequest req : this.pendingPingRequests.values()) {
		if (req.getAddress().equals(address)) {
			return (PingPeerMessage) req.getMessage();
		}
	}

	return null;
}

Line by line:

  1. public PingPeerMessage sendPing(InetSocketAddress nodeAddress, int attempt, Node node) declares the method that sends a ping. InetSocketAddress is a value that combines a host and a port, so it identifies one service on one machine.
  2. PingPeerMessage nodeMessage = checkPendingPeerToAddress(nodeAddress); first asks whether a ping to this address is already waiting for an answer.
  3. if (nodeMessage != null) means: if one was found.
  4. return nodeMessage; then return that existing ping instead of sending a new one. This is a reuse, not a fresh send.
  5. .... marks code omitted from the report.
  6. private PingPeerMessage checkPendingPeerToAddress(InetSocketAddress address) declares the helper that does the lookup.
  7. for (PeerDiscoveryRequest req : this.pendingPingRequests.values()) loops over every pending ping. This is a "for each" loop: do the following once per item.
  8. if (req.getAddress().equals(address)) compares the stored address with the one asked about. Equality here means host and port both match.
  9. return (PingPeerMessage) req.getMessage(); returns the stored ping message if they match. The part in brackets is a cast, telling Java to treat the stored message as a ping message.
  10. return null; after the loop means nothing matched, so there is no pending ping to that address.

A new ping is only actually sent to N1 if there are no pending pings to its InetSocketAddress, where equality means the host and port both match. Pending pings expire after a set time, 30 seconds by default, and expired ones are cleared by PeerExplorerCleaner at a fixed rate, every 60 seconds by default. A cleaner is a background routine that tidies up old data on a schedule, like a cleaner who comes round every hour to empty the bins.

With the default configuration, the report concludes that a single host can complete at most 65,535 handshakes (one per port) per minute, which imposes a limit, perhaps unreachable in practice, on how quickly the target's memory can be exhausted. The number 65,535 is the highest value a port number can take, so one machine has that many ports to play with. Using multiple hosts circumvents this: if one machine is throttled, many machines together are not.

Step 4: flood with unique NodeIDs

Most peer discovery functionality identifies nodes by their NodeID, not by host and port. It is therefore trivial to send a flood of requests with unique NodeIDs, fill NodeDistanceTable, and then make an unrestricted number of in-memory insertions into NodeChallengeManager.activeChallenges. Because NodeChallengeManager is never purged, the flood does not have to happen within a short window. "Purged" means cleaned out; nothing ever cleans this map.

Memory exhaustion follows as NodeChallenge objects accumulate and are not eligible for garbage collection. Garbage collection is the automatic process by which a programming language frees memory that is no longer in use. An object that is still referenced by a map is still "in use" as far as the language is concerned, so it cannot be freed, even though nobody will ever look at it again.

The report expects node functionality to be disabled as individual threads die on OutOfMemoryError, but in the researcher's testing the whole JVM crashed after roughly 200,000 insertions. A thread is one stream of work inside a program; a program can run several at once. The JVM, the Java Virtual Machine, is the runtime that executes Java programs. OutOfMemoryError is the error Java raises when it cannot allocate more memory.

Reproduction steps

The researcher attached a PoC program that interfaces with the RSKj library. The steps given are:

  1. Download a copy of the RSKj code.
  2. Move the PoC files into the co.rsk.net.discovery package, overwriting PeerExplorer.java with the modified version.
  3. Launch a node for testing, ensuring peer discovery is enabled.
  4. Compile and run the PoC from PeerFlood with arguments in the format <local_address> <target_address> <target_port> <num_threads>.
  5. Monitor the testing node's logs and stability.

A package in Java is a folder-like grouping of related classes. "Compile" means turning source code into something the machine can run. The argument format tells you what to type on the command line: the local address to use, the target's address, the target's port, and how many threads to run in parallel. More threads means more simultaneous attempts.

For anyone writing their own PoC, the recipe is to flood a testing node with connections that use random NodeIDs, complete a single ping/pong handshake, then immediately disconnect. The disconnect matters: the attacker does not want to stay around and answer the challenge ping, because answering it would remove the entry.

Root cause

NodeChallengeManager.startChallenge inserts a challenge into activeChallenges keyed by the message ID of a ping it sends, but the only removal path is removeChallenge, called from PeerExplorer.handlePong when a matching pong arrives. A peer that never answers the challenge ping leaves the entry in place forever. There is no expiry and no purge of activeChallenges, so the structure grows with every challenge started.

The NodeDistanceTable limit of 4096 nodes does not protect the challenge manager; it is precisely the full table that routes new candidates into the challenge path. The pending-ping expiry and the PeerExplorerCleaner only bound how fast a single host can drive the handshake, not how much memory the challenges consume over time.

In short, the design has a cap in one place and no cap in the place the overflow is sent to. The safety valve feeds an unsafe container.

Impact

An attacker could crash any RSKj node with peer discovery enabled, which the report says is the default. The failure mode observed was a JVM crash after around 200,000 insertions, with thread death from OutOfMemoryError expected before that. The attack requires the ability to reach the node's peer discovery service and to present many distinct NodeIDs; a single host is rate-limited by the pending-ping logic, so a larger flood is easier with multiple hosts.

A crashed node stops taking part in the network.

Fix

The report's mitigation is to implement expiring challenges that are cleared by PeerExplorerCleaner, so that unanswered challenges do not accumulate indefinitely. In everyday terms: give every ticket an expiry date, and have the cleaner throw away the expired ones. The notebook can then never grow without bound.

Variants to test

These are general patterns worth looking for in other software, based on the shape of this bug:

  • Look for other maps keyed by message or request IDs that are only cleaned up on a successful response. A positive result is a map whose size grows when you complete a handshake but never send the expected follow-up.
  • Check whether a bounded structure (a distance table, a peer cache, a rate limiter) routes overflow into an unbounded secondary structure. A positive result is an overflow path that allocates without a corresponding eviction.
  • Test whether identity is keyed by a value the client controls (here NodeID) rather than by network address. A positive result is being able to create many entries from one host by varying that value.
  • Probe the cleaner: find structures that the periodic cleaner does not touch. A positive result is memory that survives several cleaner cycles.

Hunting notes

This kind of bug tends to hide in handshake and challenge state machines, where an entry is created on an outgoing message and removed only on a matching incoming reply. A state machine is code that moves through a fixed set of stages, like a checkout flow on a shopping site.

During recon, look for peer-to-peer or discovery services exposed by default, and for code paths where a full bounded table hands work to a second structure. Recon means the early exploration phase, before any attack, where you map out what the target exposes. The signal is a put whose only matching remove sits behind a validation check the remote side controls. In other words: something is added to a collection, and the only code that takes it out again depends on the far end behaving properly.

To show impact, the researcher measured growth until failure: roughly 200,000 insertions led to a JVM crash, and the report explains the per-host rate limit and how multiple hosts remove it. That combination, a default-enabled feature, a clear memory growth path, and an observed crash, is what makes the case for a high-severity denial of service.

Glossary

  • API: a defined way for one piece of software to talk to another, like a menu of requests a service accepts.
  • Bounty: a reward paid by a company to someone who reports a security problem in its software.
  • Bucket: one slot in a table that holds a limited number of entries; when the slot is full, new entries cannot simply be added.
  • Challenge: in this report, a contest started when the peer table is full, to decide whether a newcomer replaces an existing peer.
  • Class: a blueprint in object-oriented programming that bundles data and the actions that operate on it.
  • Cleaner: a background routine that periodically removes old or expired data.
  • Compile: turn source code into a form the machine can execute.
  • Connection: an established link between two nodes that they can use to exchange messages.
  • CVSS: a standard scoring system for the severity of a security vulnerability, from 0 to 10.
  • Default: the setting a program uses when nobody has changed it.
  • Denial of Service (DoS): an attack that aims to make a service unavailable rather than to steal data.
  • Distance table: a structure that stores a limited number of known peers, 4096 by default here.
  • Garbage collection: automatic freeing of memory that a program no longer uses.
  • Handshake: a short opening exchange in which two sides confirm they can communicate.
  • HackerOne: a platform where security researchers report vulnerabilities to companies.
  • Host: a computer on a network, identified by an address.
  • In memory: held in the computer's working memory (RAM) rather than on disk.
  • InetSocketAddress: a value combining a host and a port, identifying one service on one machine.
  • IP address: the numeric address of a computer on a network.
  • Java: a widely used programming language.
  • JVM (Java Virtual Machine): the runtime that executes Java programs.
  • Map: a structure that stores values under keys, like a phone book.
  • Message ID: a unique label on a message so a reply can be matched to its request.
  • Method: a named block of code that performs an action when called.
  • Node: a computer running blockchain software that participates in the network.
  • NodeID: the identifier a node uses for itself on the network, chosen by that node.
  • Object: an instance of a class, holding its own data.
  • OutOfMemoryError: the error Java raises when it cannot allocate more memory.
  • Package: a folder-like grouping of related classes in Java.
  • Peer: another node on the network that your node talks to.
  • Peer discovery: the feature by which a node finds and keeps track of other nodes.
  • Pending: waiting for an answer.
  • Ping / pong: a paired request and reply used to check that two sides can talk.
  • PoC (proof of concept): a small program that demonstrates a bug actually works.
  • Port: a numbered channel on a computer, so one machine can run several services.
  • Purge: to clean out unwanted entries from a structure.
  • Recon: the early exploration phase of a security assessment, mapping what a target exposes.
  • Rootstock / RSKj: a blockchain project and its Java node implementation.
  • State machine: code that moves through a fixed set of stages.
  • Thread: one stream of work inside a program; a program can run several at once.
  • Uncontrolled Resource Consumption: the vulnerability class where an attacker makes a system use more of a resource (here memory) than it can afford.
  • Validation: checking that incoming data is plausible and well formed before acting on it.
  • Vulnerability: a weakness in software that an attacker can exploit.

More by z3t

View all

2 more disclosed reports, best first.

More from Rootstock Labs

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.