
Python exploit for CVE-2024-23897: unauthenticated arbitrary file read in Jenkins CLI via args4j @-file expansion, with vulnerability check, OS auto-detection and proxy support.

Fast YAML-based vulnerability scanner with template-driven detection engine for automated security testing across web apps, APIs, networks, DNS, and cloud infrastructure.

Open-source web application security scanner for automated vulnerability detection, manual penetration testing, and API security testing with a proxy-based interception engine.

This repository contains the scanner component for Greenbone Community Edition.
Jenkins reads the first three lines of a local file, unauthenticated.
The CLI expands any argument starting with @ into the contents of that file,
and a few commands parse their arguments before Jenkins checks permissions, so an
anonymous caller can aim that expansion at any file the Jenkins process can read.
Three lines is the ceiling without an account; with one that has Overall/Read the
same bug reads whole files.
This exploit does the unauthenticated three-line read.
Affects Jenkins weekly up to 2.441 and LTS up to 2.426.2. Fixed in 2.442 and
2.426.3 on 24 January 2024, which turned the @ expansion off.
Jenkins ships a command-line interface that speaks to the controller over HTTP at
/cli. It parses commands with args4j, and
args4j has a feature called expandAtFiles: an argument that begins with @ is
replaced by the contents of the named file, one line per argument.
// args4j CmdLineParser, expanding @files before the command runs
if (parserProperties.getAtSyntax() && arg.startsWith("@")) {
args.addAll(Arrays.asList(readAllLines(new File(arg.substring(1)))));
continue;
}
connect-node @/etc/passwd makes Jenkins read
/etc/passwd and feed each line to the command as a separate argument.
What you can reach depends on when the permission check runs, and Jenkins has two command dispatchers with a different order.
CLICommand.main() checks permission before it parses arguments:
if (!(this instanceof HelpCommand || this instanceof WhoAmICommand))
Jenkins.get().checkPermission(Jenkins.READ);
parser.parseArgument(args.toArray(new String[0]));
So connect-node, delete-job, offline-node and the rest throw
AccessDeniedException before args4j ever sees the @-file. That is the path an
authenticated attacker uses to read entire files: each line of the target comes
back as its own No such agent "<line>" exists. error. Unauthenticated, it
returns nothing.
CLIRegisterer.main(), which backs the @CLIMethod commands, checks permission
after it parses:
parser.parseArgument(args); // at-file expansion happens here
Authentication auth = getTransportAuthentication2();
sc.setAuthentication(auth);
jenkins.checkPermission(Jenkins.READ); // too late
The expansion has already read the file by the time the check fails. And two
commands, help and who-am-i, are exempt from the pre-parse check in the other
dispatcher as well. That leaves a handful of commands an anonymous user can drive
into reading a file.
They only leak what args4j quotes back in its parse errors, and that is the line sitting at the argument index the command overflows at. So the number of lines you get is set by how many arguments the command takes:
| Command | Arguments | Error returned | Line |
|---|---|---|---|
who-am-i | 0 | No argument is allowed: X | 1 |
help | 1 | Too many arguments: X | 2 |
keep-build | 2 | Too many arguments: X | 3 |
who-am-i allows no arguments, so the first line of the file is already one too
many and comes back in the error. help takes one, consumes line 1, and trips on
line 2. keep-build takes two (JOB and BUILD#), consumes lines 1 and 2, and
trips on line 3. keep-build is the highest-argument command an anonymous user can
reach in a stock Jenkins, which is why the ceiling is three lines. Jenkins' own
advisory says the same: without Overall/Read you get the first three lines, and no
core command or bundled plugin pushes it further.
A single-line file is therefore recovered in full — who-am-i alone returns the
whole thing. Private keys, API tokens, secret.key
python3 exploit.py -u http://10.10.10.11:8080 --check # is it vulnerable
python3 exploit.py -u http://10.10.10.11:8080 -f /etc/passwd # read one file
python3 exploit.py -u http://10.10.10.11:8080 # read paths interactively
-f reads one file and exits. Without it the exploit prompts for paths:
python3 exploit.py -u http://10.10.10.11:8080
file> C:/Windows/win.ini
file> C:/Users/Administrator/Desktop/flag.txt
The OS is detected on the first read; pass --os to skip detection if you already
know. --check reads nothing - it sends one bogus path and reports whether the
expansion fired.
-u, --url — host, host:port, or full URL. http:// is assumed if no scheme is given.-f, --file — a single file to read, then exit.--check — report whether the target is vulnerable, reading no real file.-p, --port — target port, used only when the target carries none. Defaults to 8080.--os — windows, unix, or auto for path handling. Defaults to auto-detect.-x, --proxy — proxy, for watching the requests in Burp.-k, --insecure — skip TLS verification.--timeout — seconds per request, default 8.Python 3 and requests.
The CLI did not expand the @-file. Target looks patched. means the fix is in:
2.442 or 2.426.3 and later disable expandAtFiles. The endpoint still answers,
it just no longer reads the file.No CLI response. /cli may be disabled or unreachable. means nothing answered at
/cli. Check the host and port, and that the box is up - on a lab that recycles
addresses this is usually a stale IP.Nothing recovered after a read means the Jenkins process cannot read the file.
A file that does not exist reports File not found instead, so this is an OS-level
permission denial or a directory.Stopped after line 1 means line 1 starts with -. args4j reads a - line as an
option, not an argument, so the later commands cannot advance past it. A private
key (-----BEGIN ...) hits this.| Field | Value |
|---|---|
| CVE | CVE-2024-23897 |
| Advisory | Jenkins Security Advisory 2024-01-24, SECURITY-3314 |
| Affected | Jenkins weekly <= 2.441, LTS <= 2.426.2 |
| Fixed in | 2.442 (weekly), 2.426.3 (LTS) |
| CVSS v3.1 | 9.8 Critical, AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H (NVD) |
| CWE | CWE-88 (argument injection), CWE-22 (path traversal) |
| CISA KEV | Added 19 August 2024 |
The 9.8 reflects the whole-file read an authenticated user gets, which decrypts stored credentials and leads to remote code execution. The unauthenticated three-line read this tool performs is the lower-privilege end of the same bug.
| Role | Who |
|---|---|
| Discovered and reported | Yaniv Nizry of SonarSource — Excessive Expansion |
| Vendor advisory | The Jenkins project — 2024-01-24 / SECURITY-3314 |
| Original full-read PoC | Matisse Beckandt (Backendt) — Exploit-DB 51993 |
| No-permission technique | The Jenkins security team, documented in the advisory; command recipe in gquere/pwn_jenkins |
| This implementation | d4ytox |