Skip to content
RCE Write-up Advanced

How I Hacked Google App Engine: Anatomy of a Java Bytecode Exploit

The ASM bytecode rewriting library used by Google App Engine did not check for overflow when writing string length fields, and its parser accepted literal null bytes in strings. An attacker could craft a classfile that, after rewriting, produced an oversized string that overflowed to zero length, causing the JVM to parse the following bytes as code, bypassing security wrappers and leading to arbitrary code execution.

Robert Grosse Follow

Published on blog.polybdenum.com

Back in college, I was very interested in Java bytecode. When I got an internship at Google in 2013, I was skeptical of the security of the Java version of Google App Engine and got permission to spend the last week of my internship doing a mini red team exercise, trying to break into App Engine.

Robert Grosse, on blog.polybdenum.com

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 ASM library lacked overflow checking when serialising string length fields and accepted non-standard null byte encodings during parsing, allowing a crafted classfile to produce a string longer than 65535 bytes that overflowed the length field.

Impact

An attacker could bypass App Engine's bytecode rewriting and permission system to achieve arbitrary code execution on Google's servers.

What the attacker needed

Ability to upload Java classfiles to App Engine; knowledge of Java bytecode and classfile format

How it was found

  1. Upload a specially crafted classfile to App Engine that contains a string of 32768 null bytes.
  2. ASM parses the classfile, converting the null bytes to null characters in memory.
  3. ASM writes the classfile back out, encoding the null characters as two-byte sequences, resulting in a 65536-byte string.
  4. The length field overflows to zero, and the JVM parses the following bytes as code.
  5. The malicious code defines a custom classloader with AllPermission and loads a payload class.
  6. The payload executes arbitrary code on the server.

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.

Google App Engine runs Java code from users on its servers. To keep things safe, it rewrites the code before running it, using a tool called ASM. The author found a bug in ASM that let him sneak malicious code past the rewriting step, so the server would run his code with full permissions.

What is RCE?

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

More from Google

View all

The newest disclosed reports for this program.

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.