The Wrapper Trap: Silent Persistence in Gradle and Maven
The Gradle and Maven wrapper scripts trust configuration and binaries committed to the repository, so an attacker with write access can redirect downloads or replace the wrapper JAR to execute arbitrary code. This allows compromise of developer machines and CI pipelines, with Maven's binary replacement firing on every invocation.
Published on osec.com
Build tool wrappers are the standard way JVM projects distribute a pinned tool version. Instead of relying on a system-wide installation, the wrapper downloads and caches a specific Gradle or Maven release into the project itself.
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
The wrapper's integrity checks are ineffective because the attacker controls both the download URL and the expected hash, or because no hash check exists for the committed binary.
Impact
An attacker with repository write access could execute arbitrary code on developer machines and CI pipelines, potentially stealing credentials and secrets; Maven's binary replacement attack works on every invocation without network access, while Gradle and Maven URL redirect attacks require a cold cache.
What the attacker needed
Write access to the repository; victim runs ./gradlew or ./mvnw; cold cache for URL redirect attacks
The fix
Pin the expected SHA-256 of maven-wrapper.jar in CI, enforce distributionUrl domain allow-lists, and add distributionSha256Sum to Maven wrapper properties.
How it was found
- Attacker modifies gradle-wrapper.properties to point distributionUrl to their server and sets distributionSha256Sum to the hash of their malicious ZIP.
- CI or developer runs ./gradlew on a cold cache, downloading and executing the malicious Gradle distribution.
- For Maven URL redirect, attacker changes distributionUrl in maven-wrapper.properties to an attacker-controlled server.
- On next ./mvnw with cold cache, the malicious Maven distribution is downloaded and executed.
- For Maven binary replacement, attacker replaces .mvn/wrapper/maven-wrapper.jar with a malicious JAR.
- Every subsequent ./mvnw invocation executes the malicious JAR.
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.
Build tools like Gradle and Maven help compile and run Java projects. Their 'wrappers' are small scripts and files stored in the project that download and run a specific version of the tool. If an attacker can change those files, they can make the wrapper run their own malicious code whenever someone builds the project.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.