Skip to content
RCE Write-up Advanced

CVE-2023-34040 Spring Kafka Deserialization Remote Code Execution

Spring Kafka's error-handling deserialiser could be made to deserialise a crafted exception header when the key or value was null, because the class check only restricted the outer exception type and not the nested cause. An attacker able to publish to a topic could therefore trigger deserialisation of a malicious class and achieve remote code execution.

pyn3rd Follow

Published on pyn3rd.github.io

Here is the explicit description about Spring Kafka deserialization vulnerability in Vmware security bulletin.

pyn3rd (@pyn3rd), on pyn3rd.github.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the deserialisation allow-list only validated the outer DeserializationException class while its nested cause field was deserialised without restriction.

Impact

An attacker who can publish to a topic could achieve remote code execution on the consumer, and a CommonsCollections gadget chain could also be used.

What the attacker needed

Consumer uses ErrorHandlingDeserializer; checkDeserExWhenKeyNull/ValueNull set true; attacker can publish to the topic

How it was found

  1. Configure the consumer with ErrorHandlingDeserializer and set checkDeserExWhenKeyNull and checkDeserExWhenValueNull to true.
  2. Publish a record whose key or value is null but which carries the exception header.
  3. Place a serialised malicious class, inheriting Throwable, in the exception header value.
  4. Send the request so the consumer reads the record and deserialises the header, triggering code execution.

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 write-up has not been written yet. The Original tab links to the source.

Kafka is a message queue: programs publish messages to named topics and other programs read them. Spring Kafka can be told to look inside a special header for details of a failed message, and it turns that header back into a Java object. The check only looked at the outer object type, so a hidden inner object of any class slipped through and could run code.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by pyn3rd

View all

2 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.