monerod can be disabled by a well-timed TCP reset packet
The handle_accept function in monerod's epee networking library does not re-register the accept handler when it receives an error, so a TCP RST sent immediately after the handshake can cause the daemon to stop accepting new connections. An attacker could remotely disable monero nodes, especially idle or syncing ones.
- Triaged in 3 days
- Fixed in 48 days
- Disclosed after 54 days
Summary: A well-timed TCP reset (RST) can cause monerod (or any service relying on epee) to stop accepting new connections.
Description: When a new connection is attempted, the handle_accept function is called. This does some error checking and finishes setting up the connection. Once the connection is set up, it calls acceptor_.async_accept() in order to continue listening for new connections.
However, if the handle_accept function is called with an error code, it bypasses the main block of code and simply logs a message. It does not add the accept handler back to the acceptor. The result is that the daemon will stop accepting new connections if an error is hit.
It is possible for an attacker to remotely trigger such an error. If a TCP RST packet is sent immediately after a successful TCP handshake, the connection/socket will be torn down. If it happens fast enough (specifically in the window between the server receiving the ACK and the handle_accept function being called), this will cause an error.
Releases Affected:
All releases using epee.
Steps To Reproduce:
I've included a python script below which demonstrates a normal TCP connection that ends gracefully, and a malicious connection which causes an RST to be sent at close as opposed to FIN.
If this is run on a relatively idle node (e.g. if it's still synchronizing its blockchain), it will disable the node after just a couple tries. If a node is fully active, it becomes harder to get the RST processed within the critical window. I have yet to disable a fully active node, but it should be possible. A more efficient/faster attack going over raw sockets might make it easier.
Supporting Material/References:
$ ./rst-attack.py <ip> <port>
#!/usr/bin/env python3
import socket, struct, sys
tgt_host = sys.argv[1]
tgt_port = int(sys.argv[2])
# Normal connection, send some data, end with graceful FIN.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
s.connect((tgt_host, tgt_port))
s.send(b"hello")
s.close()
# Abnormal connection, force close by RST instead of FIN.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
l_onoff = 1
l_linger = 0
p=struct.pack('ii', l_onoff, l_linger)
s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, p)
s.connect((tgt_host, tgt_port))
s.close()
Impact
An attacker can remotely disable monero nodes. I marked this as medium since my proof-of-concept script fails to disable most active nodes. However, it is theoretically possible to take down the whole network if a clever variation or different means of causing an accept error is discovered.
An attacker could also monitor the network and snipe any nodes that have lagged behind or are in the middle of syncing the chain.
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 error path in handle_accept fails to call acceptor_.async_accept() again, leaving the acceptor without a pending accept operation.
Impact
An attacker could remotely disable monero nodes, though the proof-of-concept fails to disable most active nodes; idle or syncing nodes are easier targets.
What the attacker needed
Network access to the node's TCP port; node is relatively idle or syncing
How it was found
- Open a normal TCP connection to the target port, send some data, and close gracefully with FIN.
- Open another TCP connection with SO_LINGER set to zero so that close sends an RST instead of FIN.
- On an idle or syncing node, a couple of malicious connection attempts may stop it accepting connections.
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.
When a server accepts a new connection, it must set up a handler to accept the next one. If an error occurs during that setup, the code here just logs it and forgets to re-arm the listener, so the server stops accepting connections. An attacker can force such an error by sending a TCP reset packet at just the right moment.
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.