Boost _ Shardeum_ Ancillaries 33571 - [Websites and Applications - Medium] Taking down the websocket server via malicious methods object override
Submitted on Tue Jul 23 2024 16:25:12 GMT-0400 (Atlantic Standard Time) by @anton_quantish for Boost | Shardeum: Ancillaries
Report ID: #33571
Report type: Websites and Applications
Report severity: Medium
Target: https://github.com/shardeum/json-rpc-server/tree/dev
Impacts:
Taking down the application/website
Description
Hey team,
Brief/Intro
It's possible to completely take down the websocket JSON-RPC server by a few specifically crafted requests. It will then be able to still accept new connections but won't answer to any request at all.
Vulnerability Details
When the request is received by the Websocket JSON-RPC server, first its method
field checked to be present in the methods
object which contains the mapping from the method names to their functions to be called:
https://github.com/shardeum/json-rpc-server/blob/5dc56e5f4312529d4262cab618ec618d288de5dd/src/websocket/index.ts#L77-L90
Then, after some extra checks, the function from the methods
mapping is called actually with the request.params
and some callback
passed into :
https://github.com/shardeum/json-rpc-server/blob/5dc56e5f4312529d4262cab618ec618d288de5dd/src/websocket/index.ts#L162
The vulnerability is that such a code allows to call not only the methods
own functions, but the ones from its prototype also.
I didn't manage to achieve something like RCE this way but I was able to override all the functions in this methods
mapping to become uncallable using the __defineGetter__
prototype function.
I can send the following JSON request to the JSON-RPC server:
In this case, the __defineGetter__
method will be first checked to be present in the methods
mapping, and the check will pass successfully. Then, this method will be called the following way:
This call defines a getter function (the callback) which will be called for every further accessing the eth_blockNumber
field of methods
mapping.
Thus, when someone then tries to call the eth_blockNumber
method, the callback function will be called as the getter function, it will return null and the method will not do anything (will fail with null
is not a function exception actually).
The same could be done for all the methods available and all of them will not be callable for anyone anymore.
Impact Details
Complete take down of the websocket JSON-RPC server.
Proof of concept
Proof of Concept
Install the python dependencies with
pip3 install websockets
Run the following exploit with
python3 takedown_ws.py
(replace the endpoint with your own one):
Connect to websocket server with
wscat -c ws://172.16.205.128:8080
for instance and try to execute any method. Make sure there's no response and there is an error in server log:
Last updated