mojira.dev
MC-87863

RCON uses TCP as though it's datagram-based

The bug

The RCON protocol is based on TCP, which is designed to transmit a stream of individual bytes. If you send 100 bytes at once, they won't necessarily be received as a unit of exactly those 100 bytes. You might get 80 bytes first and then the remaining 20 bytes. Or get more than 100 bytes, if more data has already arrived. Yet Minecraft's RCON implementation assumes the chunks of the TCP stream it receives correspond exactly to RCON packets and if that is not the case closes the socket, see net.minecraft.server.rcon.thread.RconClient.run() (Mojang name).

In practice, it mostly works if you send commands slowly, like a human entering them in real time. But if you want to send (automated) commands in bulk the server soon reads less or more than the expected amount of data and closes the socket. The only way to get any kind of reliability is to wait for the response to arrive before sending the next command, forcing a round trip for every command.

How to reproduce

  1. Start a local server with the following server.properties settings:

    enable-rcon=true
    rcon.port=25575
    rcon.password=test
  2. Run the attached Java code

[media]
  1. Java 11(\\+)

    java .\RconTest.java localhost 25575 test

    Pre Java 11

    javac .\RconTest.java
    java RconTest localhost 25575 test

    ❌ It will throw an exception pretty soon after executing the first commands

Linked issues

Attachments

Comments 6

proof of concept that breaks it?

@@unknown: Under MC-72390, I have a PoC script that is tested and, via Rcon, will crash a server with a ConcurrentModificationException; though I'm not sure if that bug is caused by this one. They're almost certainly related, however.

@@unknown: do you have further details about how this issue relates to MC-72390?

@@unknown: I managed to make a quick hack in Java (which I don't normally use a lot, so I'm not going to make a full-fledged client). I'm attaching it. Be sure to set the static variables in the source.

@@unknown: This is unrelated to MC-72390. They're just both more problematic the more you send.

Is this still a issue in the latest version of the game(currently 1.13.1)?

If so, please add it to the affected versions, thanks!

Is this considered fixed? It seems that I'm having a similar issue while trying to send two packets directly one after another (in one binary blob) - my connection is instantly dropped. The issue does not happen if the packets are separated by some physical time. (Happening on 1.13.2)

I can confirm this in 1.21 and attached an image demonstrating the bug.

[media]

jonathan2520

(Unassigned)

Confirmed

Platform

Low

Crash, Networking

Minecraft 1.8.8, Minecraft 15w35e, Minecraft 15w36a, Minecraft 15w36c, Minecraft 1.9.4, ..., Minecraft 16w41a, Minecraft 16w43a, Minecraft 16w44a, 1.15.1, 1.21

Retrieved