CVE-2021-32751

7.5 HIGH

📋 TL;DR

CVE-2021-32751 allows arbitrary code execution when attackers can manipulate environment variables for users running vulnerable Gradle start scripts or gradlew scripts. This affects users of Gradle on Unix-like systems who use the application plugin's generated scripts or gradlew. The vulnerability stems from unsafe use of eval in bash scripts.

💻 Affected Systems

Products:
  • Gradle
Versions: All versions prior to 7.2
Operating Systems: Unix-like systems (Linux, macOS, BSD)
Default Config Vulnerable: ⚠️ Yes
Notes: Only affects systems using bash shell and where environment variables can be manipulated. Windows systems are not affected.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Full system compromise with attacker gaining the same privileges as the user running the vulnerable script, potentially leading to data theft, ransomware deployment, or lateral movement.

🟠

Likely Case

Limited code execution within the context of the build process, potentially compromising build artifacts, injecting malicious code into applications, or stealing credentials from build environments.

🟢

If Mitigated

No impact if environment variables are properly secured or scripts are patched/upgraded.

🌐 Internet-Facing: LOW - This requires local access or ability to modify environment variables of the executing user, making direct internet exploitation unlikely.
🏢 Internal Only: MEDIUM - In shared build environments, CI/CD systems, or multi-user systems where users can influence others' environment variables.

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ✅ No
Complexity: LOW

Exploitation requires ability to set environment variables for the target user, which typically requires some level of access or privilege escalation.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: Gradle 7.2

Vendor Advisory: https://github.com/gradle/gradle/security/advisories/GHSA-6j2p-252f-7mw8

Restart Required: No

Instructions:

1. Upgrade Gradle to version 7.2 or later. 2. For existing projects, update gradle-wrapper.properties to use distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip. 3. Run ./gradlew wrapper to update the wrapper script.

🔧 Temporary Workarounds

Generate new gradlew script with Gradle 7.2

linux

Create a new gradlew script using Gradle 7.2 and use it with older Gradle versions

gradle wrapper --gradle-version 7.2
./gradlew wrapper

Secure environment variables

all

Prevent untrusted users from modifying environment variables of users executing gradlew or start scripts

Review and restrict environment variable permissions in CI/CD systems and multi-user environments

🧯 If You Can't Patch

  • Manually patch start scripts to remove eval usage or hardcode values instead of using environment variables
  • Run applications directly with java command instead of using generated start scripts for simple applications

🔍 How to Verify

Check if Vulnerable:

Check Gradle version with: ./gradlew --version | grep Gradle. If version is below 7.2, check if start scripts or gradlew use eval with environment variables.

Check Version:

./gradlew --version | grep Gradle

Verify Fix Applied:

Verify Gradle version is 7.2 or higher: ./gradlew --version | grep 'Gradle 7\.2' or higher. Check that gradlew script doesn't contain unsafe eval usage.

📡 Detection & Monitoring

Log Indicators:

  • Unexpected command execution in build logs
  • Suspicious environment variable modifications in system logs
  • Failed or abnormal gradlew execution attempts

Network Indicators:

  • Unusual outbound connections from build systems during gradle execution

SIEM Query:

process_name:"gradlew" OR process_name:"gradle" AND command_line:"eval" OR command_line:environment variable manipulation patterns

🔗 References

📤 Share & Export