JSON-RPC DoS through Websockets
The WebSocket JSON-RPC service accepted messages up to 32MB and had no rate limiting, so an attacker could send many large messages in parallel to exhaust server resources and crash it. The report demonstrates a denial of service against the node's RPC server.
Submitted by MevSec
The Websocket service accepts messages for 32MB size.
File: repos\node\rpc\websockets.go
const (
messageSizeLimit = 32 * 1024 * 1024 // 32MB
)
(...)
conn.SetReadLimit(messageSizeLimit)
This size is 3 times bigger than what Golang accepts by default (10MB) on the HTTP service, while there is no reason that websocket payloads are bigger than HTTP payloads. In addition, there is no rate limiting within the code for the websockets.
As a consequence, an external attacker can take down the JSON RPC server by :
- Opening a websocket RPC Connection to Zetachain through Websockets.
- Sending in loop, with parallel workers, malicious Websockets messages (with an unknown method) and a total message size of 32MB.
Details
When the WebSocket server runs, it listens to the messages with readLoop() (L211).
When a message is received, the message body is put in mb variable. (L222)
This content will then be used to instance a msg variable.
File: repos\node\rpc\websockets.go
_, mb, err := wsConn.ReadMessage()
(...)
var msg map[string]interface{}
if err = json.Unmarshal(mb, &msg); err != nil {
s.sendErrResponse(wsConn, err.Error())
continue
}
Afterwards, some other variables are defined:
- method - msg[“method”]
- id - msg[“id”]
Depending on the “method”, a switch case will determine the execution path. If the method is unknown, a call is done to tcpGetAndSendResponse():
File: repos\node\rpc\websockets.go
default:
// otherwise, call the usual rpc server to respond
if err := s.tcpGetAndSendResponse(wsConn, mb); err != nil {
s.sendErrResponse(wsConn, err.Error())
}
}
This tcpGetAndSendResponse function will call the RPC, locally with HTTP:
File: repos\node\rpc\websockets.go
func (s *websocketsServer) tcpGetAndSendResponse(wsConn *wsConn, mb []byte) error {
req, err := http.NewRequestWithContext(context.Background(), "POST", "http://"+s.rpcAddr, bytes.NewBuffer(mb))
if err != nil {
return errors.Wrap(err, "Could not build request")
}
However, this function does not perform any sanitation check. If an attacker sends a 32Mb message on Websockets, it will internally forward the call to the HTTP server with 32Mb payload.
Proof of Concept
A PoC was developed to exploit the vulnerability with :
-
14MB incorrect method name eth_XYZ where XYZ is a random 14MB string,
The interest in using this function is that the server will attempt to send back the name of the method that was not found, sending therefore an extra 14MB back to the client.
-
14MB payload (random string)
-
Only non-ASCII characters in the payload since it seems to cause more problems on the server upon decoding.
-
30 workers from a single machine
The PoC can be found here : https://gist.github.com/0xfadam/2846ee14d67ea95741f27e50570ac77a
The PoC can be launch with the following commands:
go mod init poc
go mod tidy
go run poc.go -ip 127.0.0.1 -ws-port 9546 -secure=false -workers 30
A video showing the crash of the server after exploitation can be found below :
https://drive.google.com/open?id=130MD8xBhNPNawRYksuETfP1P0Kr9Zxom&usp=drive_fs
Recommended Mitigation Steps
The Zetachain server needs to:
- Limit the size of each message. It should be the same what is configured for HTTP (10 MB)
- Enforce an applicative rate-limit mechanism so a single client cannot send thousands of messages within a short timeframe.
0xean (Judge) decreased severity to Medium and commented:
Warden fails to show how this leads to a direct loss of funds. DOS is considered Medium severity.
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 WebSocket handler set a 32MB read limit and lacked rate limiting, then forwarded each large message to the internal HTTP RPC server without size checks.
Impact
An attacker could cause a denial of service, taking down the JSON-RPC server; the judge rated this as Medium severity because no direct loss of funds was shown.
What the attacker needed
Network access to the WebSocket RPC endpoint; ability to open a WebSocket connection
The fix
The server should limit WebSocket message size to match the HTTP limit (10MB) and enforce an application-level rate limit so a single client cannot send many messages quickly.
How it was found
- Open a WebSocket RPC connection to the Zetachain node.
- Send large WebSocket messages with an unknown method name in a loop using parallel workers.
- The server forwards each large message to the internal HTTP RPC server, consuming resources.
- The server crashes under the load.
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 WebSocket is a two-way connection between a browser and a server. This server allowed very large messages (32 megabytes) and did not limit how many a client could send, so someone could flood it with huge requests until it stopped working for everyone.
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.