Return of the Rhino: An old gadget revisited
A deserialisation gadget in the Rhino JavaScript engine bundled with some Java runtimes allows an attacker who can supply a serialised object to trigger arbitrary method calls via reflection, leading to remote code execution. The gadget works because certain Rhino classes remain serialisable and can be manipulated to invoke static methods like Context.enter() and then arbitrary methods on controlled objects.
Published on codewhitesec.blogspot.com
The original lives on codewhitesec.blogspot.com
We do not hold its text, 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 Rhino Script Engine classes (such as NativeError, NativeJavaMethod, and NativeJavaObject) remain serialisable and allow manipulation of internal fields to perform arbitrary reflection calls during deserialisation, without proper validation or restrictions.
Impact
An attacker who can supply a malicious serialised object could achieve remote code execution on the affected Java runtime, but the gadget only works on certain distributions (e.g., OpenJDK bundled with Ubuntu or Debian) because Oracle JRE7u13+ hardened the classes.
What the attacker needed
Ability to supply serialised data; Vulnerable Java runtime (e.g., OpenJDK on Ubuntu/Debian)
The fix
The gadget should be fixed by making the relevant Rhino classes non-serialisable or by adding validation during deserialisation, as was done in Oracle JRE7u13.
How it was found
- Create a NativeError instance and set its prototype to a NativeJavaObject that wraps the target instance.
- Create a NativeJavaMethod and specify the method to be invoked on the target instance.
- Serialize the crafted object graph and then deserialize it to trigger the gadget.
- Use a trampoline class like BadAttributeValueExpException to trigger toString() on the NativeError during deserialisation.
- Leverage the reflection primitive to call Context.enter() first (via a MemberBox) and then invoke arbitrary methods (e.g., on TemplatesImpl or JdbcRowSetImpl) to achieve 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.
When Java saves an object to a file or sends it over the network, it uses serialisation. If an attacker can control the data being deserialised, they might trick the program into running harmful code. This report shows how a specific set of classes in an old JavaScript engine can be abused to make the program call any method the attacker chooses, which can lead to full control of the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.