DOS of RSKJ server
A malformed RLP-encoded UDP packet causes the RSKJ server's decoder to compute a negative length that becomes zero, so the UDP server keeps processing the same packet indefinitely. This blocks other nodes' traffic on the port and eventually crashes the application with an out-of-memory error.
- Disclosed after 22 months
Due of closing of report (ID #2102315) I will summarize total reproducible report here
Summary:
DOS of RSKJ server
Steps To Reproduce:
- download https://github.com/rsksmart/rskj/releases/download/FINGERROOT-5.0.0/rskj-core-5.0.0-FINGERROOT-all.jar
- at server side run
java -classpath rskj-core-5.0.0-FINGERROOT-all.jar -Drpc.providers.web.cors=* -Drpc.providers.web.ws.enabled=true co.rsk.Start
it opens UDPv6 port 5050
- at client side install python3 and library
pip install pysha3, download (Attachment on the original report: poc.py), modifyHOSTinside and run it against server. 4.theUDPServeris going to process only one UDP packet forever and it prevents to process other packages received from different nodes. In a while (some minutes left) the application crashes.
Supporting Material/References:
The root cause: bytesToLength returns -5 and length becomes 0 https://github.com/rsksmart/rskj/blob/master/rskj-core/src/main/java/org/ethereum/util/RLP.java#L432 this is legal https://github.com/rsksmart/rskj/blob/master/rskj-core/src/main/java/org/ethereum/util/RLP.java#L440 and position is unchangeable https://github.com/rsksmart/rskj/blob/master/rskj-core/src/main/java/org/ethereum/util/RLP.java#L405 https://github.com/rsksmart/rskj/blob/master/rskj-core/src/main/java/org/ethereum/util/RLP.java#L403
Impact
Server stops to process the incoming traffic at UDPv6 port 5050. In a while the application crashes as Out of memory.
due of everywhere usage of vulnerable function decode2 there may be affected another entry points of service.
Context
RSKJ is the Java implementation of the Rootstock node, published at https://github.com/rsksmart/rskj. The report concerns the UDP listener that the node opens when started with the WebSocket RPC provider enabled. In the tested build the node opens a UDPv6 port 5050, and that listener is the component that stops working.
The weakness class recorded for the report is uncontrolled resource consumption. The researcher's summary is short: a single crafted UDP packet keeps the UDPServer busy forever, other packets from other nodes are never processed, and after some minutes the application crashes with an out-of-memory condition.
Setup
The setup is minimal and entirely local: one server-side node and one client-side script.
- Server: the released all-in-one jar
rskj-core-5.0.0-FINGERROOT-all.jar, taken from theFINGERROOT-5.0.0release. - Client: Python 3 with the
pysha3library installed viapip install pysha3, plus the proof-of-concept script attached to the report (poc.py), in which theHOSTvalue has to be edited to point at the target. - No accounts, roles or credentials are involved. The only precondition is that the node is reachable on its UDP port.
Finding it
The researcher traced the behaviour to the RLP decoding code in rskj-core/src/main/java/org/ethereum/util/RLP.java. The relevant observation is that bytesToLength can return -5, after which the computed length becomes 0. That outcome is legal for the decoder, but the read position does not advance, so the decoder can be driven into a state where it never makes progress on the input it was given.
Because decode2 is used in many places, the researcher notes that other entry points of the service may be affected as well, not only the UDP listener.
Exploitation
Step 1: obtain the node build
Download the released jar:
https://github.com/rsksmart/rskj/releases/download/FINGERROOT-5.0.0/rskj-core-5.0.0-FINGERROOT-all.jar
Step 2: start the node with the WebSocket provider enabled
On the server side, run:
java -classpath rskj-core-5.0.0-FINGERROOT-all.jar -Drpc.providers.web.cors=* -Drpc.providers.web.ws.enabled=true co.rsk.Start
Starting the node this way opens the UDPv6 port 5050, which is the port the attack targets.
Step 3: prepare the client
On the client side, install Python 3 and the pysha3 library:
pip install pysha3
Then download the attached poc.py, edit the HOST value inside it so that it points at the server, and run it against the server. The script itself is not reproduced in the report text; only its attachment and the HOST edit are described.
Step 4: observe the effect
The UDPServer processes only one UDP packet, forever. Because it is stuck on that single packet, packets received from other nodes are never processed. After a while, described as some minutes, the application crashes.
Root cause
The decoder's length handling is the problem. bytesToLength returns -5, and the length becomes 0. The report points at the following lines as the relevant code:
https://github.com/rsksmart/rskj/blob/master/rskj-core/src/main/java/org/ethereum/util/RLP.java#L432, wherebytesToLengthreturns-5and the length becomes0.https://github.com/rsksmart/rskj/blob/master/rskj-core/src/main/java/org/ethereum/util/RLP.java#L440, where the researcher states that this is legal.https://github.com/rsksmart/rskj/blob/master/rskj-core/src/main/java/org/ethereum/util/RLP.java#L405andhttps://github.com/rsksmart/rskj/blob/master/rskj-core/src/main/java/org/ethereum/util/RLP.java#L403, where the position is unchangeable.
In other words, the decoder accepts a length of zero for the crafted input but does not move its read position, so it keeps decoding the same bytes without consuming them. On the UDP path this manifests as a single packet monopolising the listener indefinitely. The report does not describe any additional defence that was in place or why it failed to stop the input; the implication is that the decoder's own validation accepts the crafted encoding as legal.
Impact
The server stops processing incoming traffic on the UDPv6 port 5050. After some minutes the application crashes with an out-of-memory condition. The researcher also notes that, because the vulnerable function decode2 is used everywhere, other entry points of the service may be affected. That last point is stated as a possibility rather than demonstrated.
Fix
The report does not describe a fix or a code change. The root cause it identifies is the combination of a legal zero length with a read position that does not advance, so the natural place to address it is the RLP decoder's handling of that length and position, but the report itself does not state what was changed.
Variants to test
- Send the same crafted RLP encoding to other interfaces that call
decode2, such as other RPC or peer-facing handlers. A positive result is the same symptom: the handler stops making progress on further input, or memory grows until the process dies. - Try other encodings that produce a zero or negative computed length in
bytesToLengthand check whether the read position advances. A positive result is a decoder loop that consumes no input. - Run the proof-of-concept against a node started without the WebSocket provider enabled, to see whether the UDP listener on
5050is still present and still affected. A positive result is the same stall and crash.
Hunting notes
This kind of bug hides in hand-written binary decoders: RLP, protobuf-style length prefixes, and any parser where a length field is computed from input and then used to advance a cursor. The signal during recon is a service that exposes a UDP or other unauthenticated listener and decodes structured data from it, especially where the decoder is shared across many call sites, as with decode2 here.
What happened, in plain words
Rootstock is a blockchain network, and RSKJ is the program (a "node") that a computer runs to take part in that network. The node listens on a network door called a port, and in this case the door is a UDP port numbered 5050.
The researcher found that a single specially crafted message sent to that door can make the node get stuck. The node keeps working on that one message forever, never gets to the messages from other nodes, and after a few minutes it runs out of memory and crashes. This kind of attack, where you make a system use up its resources until it falls over, is called a denial of service, or DOS.
Some background first
Before the steps make sense, here are a few ideas explained from scratch.
- A node: a computer running software that participates in a blockchain network. Think of it as one member of a large group chat who passes messages along.
- A port: a numbered door on a computer that network traffic arrives at. A computer can have many doors open at once, each for a different service. Port 5050 is the door this report is about.
- UDP: one of the two common ways computers send short messages to each other over a network (the other is TCP). UDP is like posting a letter: you drop it in the postbox and do not wait for a reply. It is fast and simple.
- UDPv6: UDP running over IPv6, the newer version of the internet addressing system. It just means the door is reachable over the newer kind of network address.
- RLP: a way of packing data into a compact stream of bytes so it can be sent over the network. The node has to unpack ("decode") these bytes when a message arrives. The code that does the unpacking is where the bug lives.
- A decoder: the part of a program that turns packed bytes back into meaningful data. Imagine a person reading a parcel label: they look at the length written on the label, then read exactly that many characters. If the length says zero but they never move their finger forward, they keep reading the same spot forever.
- Denial of service (DOS): an attack that stops a service from working for legitimate users, usually by exhausting something (memory, CPU time, network capacity) rather than by stealing data.
- Uncontrolled resource consumption: the formal name for this class of bug. The program uses a resource (here, processing time and memory) without any limit, so an attacker can push it until it breaks.
- Out of memory: what happens when a program asks the computer for more and more memory until there is none left. The program is then killed or crashes.
- A jar file: a single file that bundles a Java program and everything it needs to run. The
-allin the filename means it includes all the libraries too, so you can run it with one command. - A system property: a setting you pass to a Java program on the command line, starting with
-D. It is like a switch you flip before the program starts. - WebSocket RPC provider: a feature that lets other programs talk to the node over a WebSocket connection (a two-way live connection, like a phone call rather than a letter). RPC means "remote procedure call": one program asking another to do something.
- CORS: a browser security rule that controls which websites are allowed to talk to a service. Setting it to
*means "allow any website". - Python: a popular programming language, often used for quick scripts. Python 3 is its current version.
- A library: a bundle of ready-made code you can add to your own program so you do not have to write everything yourself.
pysha3is a library that provides a hashing function. - A proof-of-concept (PoC) script: a small program written to demonstrate that a bug is real. It is not a polished tool; it just proves the point.
HOST: a setting inside the script that says which computer to send the message to. You have to change it to point at the server you are testing.
Setting up the test
The setup is small and entirely local: one computer running the node (the "server") and one computer running a script (the "client").
- Server side: the released all-in-one jar file
rskj-core-5.0.0-FINGERROOT-all.jar, taken from theFINGERROOT-5.0.0release. - Client side: Python 3 with the
pysha3library, plus the proof-of-concept script attached to the report (poc.py). Inside that script you have to edit theHOSTvalue so it points at the server. - No accounts, passwords or special permissions are needed. The only requirement is that the server can be reached on its UDP port.
Step 1: get the node program
Download the released jar file:
https://github.com/rsksmart/rskj/releases/download/FINGERROOT-5.0.0/rskj-core-5.0.0-FINGERROOT-all.jar
This is the download link given in the report.
Step 2: start the node with the WebSocket feature on
On the server side, run this command:
java -classpath rskj-core-5.0.0-FINGERROOT-all.jar -Drpc.providers.web.cors=* -Drpc.providers.web.ws.enabled=true co.rsk.Start
Line by line:
javaruns the Java program.-classpath rskj-core-5.0.0-FINGERROOT-all.jartells Java where to find the program's code: in the jar file you downloaded.co.rsk.Startis the name of the program inside the jar that actually starts the node.
Starting the node this way opens the UDPv6 port 5050. That open door is what the attack targets: it is the entrance the crafted message is sent to.
Step 3: prepare the client script
On the client side, install Python 3 and the pysha3 library:
pip install pysha3
pip is Python's tool for installing libraries. This command downloads and installs pysha3.
Then download the attached poc.py, open it in a text editor, and change the HOST value inside it so that it points at the server you want to test. Run the script against the server. The script's contents are not shown in the report; only the attachment and the HOST edit are described.
Step 4: watch what happens
The UDPServer (the part of the node that listens on the UDP port) processes only one UDP packet, forever. Because it is stuck on that single packet, packets arriving from other nodes are never processed. After a while, described as some minutes, the application crashes.
Think of a shop assistant who picks up one customer's form, reads the same line over and over, and never looks up to serve the queue behind them. Eventually the shop runs out of space and has to close.
Why it happens (the root cause)
The problem is in how the decoder handles the length of a piece of data. A function called bytesToLength can return -5, and after that the computed length becomes 0. The report points at these lines as the relevant code:
https://github.com/rsksmart/rskj/blob/master/rskj-core/src/main/java/org/ethereum/util/RLP.java#L432, wherebytesToLengthreturns-5and the length becomes0.https://github.com/rsksmart/rskj/blob/master/rskj-core/src/main/java/org/ethereum/util/RLP.java#L440, where the researcher states that this outcome is legal.https://github.com/rsksmart/rskj/blob/master/rskj-core/src/main/java/org/ethereum/util/RLP.java#L405andhttps://github.com/rsksmart/rskj/blob/master/rskj-core/src/main/java/org/ethereum/util/RLP.java#L403, where the position is unchangeable.
In plain terms: the decoder accepts a length of zero for the crafted input, but it does not move its read position forward. So it keeps decoding the same bytes without ever consuming them. On the UDP path this shows up as one packet hogging the listener indefinitely.
The report does not describe any other defence that was in place or why it failed to stop the input. The implication is that the decoder's own validation accepts the crafted encoding as legal.
What the impact is
The server stops processing incoming traffic on the UDPv6 port 5050. After some minutes the application crashes with an out-of-memory condition. The researcher also notes that, because the vulnerable function decode2 is used in many places, other entry points of the service may be affected too. That last point is stated as a possibility, not demonstrated.
Was there a fix?
The report does not describe a fix or a code change. The root cause it identifies is the combination of a legal zero length with a read position that does not advance, so the natural place to address it is the RLP decoder's handling of that length and position, but the report itself does not state what was changed.
Other things worth testing
- Send the same crafted RLP encoding to other interfaces that call
decode2, such as other RPC or peer-facing handlers. A positive result is the same symptom: the handler stops making progress on further input, or memory grows until the process dies. - Try other encodings that produce a zero or negative computed length in
bytesToLengthand check whether the read position advances. A positive result is a decoder loop that consumes no input. - Run the proof-of-concept against a node started without the WebSocket feature enabled, to see whether the UDP listener on
5050is still present and still affected. A positive result is the same stall and crash.
How to look for bugs like this
This kind of bug hides in hand-written binary decoders: RLP, protobuf-style length prefixes, and any parser where a length field is computed from input and then used to move a cursor forward. During recon (the early stage of looking for bugs), the signal is a service that exposes a UDP or other unauthenticated listener and decodes structured data from it, especially where the decoder is shared across many call sites, as with decode2 here.
Glossary
- Node: a computer running software that participates in a blockchain network.
- Port: a numbered door on a computer that network traffic arrives at.
- UDP: a fast, connectionless way of sending short messages over a network.
- UDPv6: UDP running over IPv6, the newer internet addressing system.
- RLP: a compact way of packing data into bytes for sending over a network.
- Decoder: the part of a program that turns packed bytes back into meaningful data.
- Denial of service (DOS): an attack that stops a service from working for legitimate users.
- Uncontrolled resource consumption: a bug class where a program uses a resource without limit, letting an attacker exhaust it.
- Out of memory: a crash caused by a program using up all available memory.
- Jar file: a single file bundling a Java program and its libraries.
- System property: a setting passed to a Java program on the command line, starting with
-D. - WebSocket RPC provider: a feature letting other programs talk to the node over a live two-way connection.
- RPC: remote procedure call, one program asking another to do something.
- CORS: a browser rule controlling which websites may talk to a service.
- Library: a bundle of ready-made code you can add to your own program.
- Proof-of-concept (PoC) script: a small program written to demonstrate that a bug is real.
HOST: a setting inside the script saying which computer to send the message to.pip: Python's tool for installing libraries.- Recon: the early stage of looking for bugs, gathering information about a target.
- Cursor / read position: the marker in a decoder showing where in the input it has read up to.
decode2: the function in RSKJ that performs RLP decoding, used in many places.bytesToLength: the function that works out how long a piece of RLP data is.- Bounty: a reward paid by a program for a valid security report.
- Severity: a rating of how serious a bug is, here high.